Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1353e596 authored by Lukacs T. Berki's avatar Lukacs T. Berki
Browse files

Handle the version_script property.

Doesn't work when depends on arch/target/etc., but good enough for
libdl_android.

Bug: 186650430
Test: Presubmits.
Change-Id: Ib0facb41a89454717c74663e5e078aedd33d1b9c
parent f794e826
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -100,6 +100,10 @@ func BazelLabelForModuleDeps(ctx BazelConversionPathContext, modules []string) b
	return labels
}

func BazelLabelForModuleSrcSingle(ctx BazelConversionPathContext, path string) bazel.Label {
	return BazelLabelForModuleSrcExcludes(ctx, []string{path}, []string(nil)).Includes[0]
}

// BazelLabelForModuleSrc expects a list of path (relative to local module directory) and module
// references (":<module>") and returns a bazel.LabelList{} containing the resolved references in
// paths, relative to the local module, or Bazel-labels (absolute if in a different package or
+9 −0
Original line number Diff line number Diff line
@@ -227,6 +227,15 @@ type Attribute interface {
	HasConfigurableValues() bool
}

// Represents an attribute whose value is a single label
type LabelAttribute struct {
	Value Label
}

func (LabelAttribute) HasConfigurableValues() bool {
	return false
}

// Arch-specific label_list typed Bazel attribute values. This should correspond
// to the types of architectures supported for compilation in arch.go.
type labelListArchValues struct {
+1 −3
Original line number Diff line number Diff line
@@ -519,10 +519,8 @@ func isZero(value reflect.Value) bool {
	case reflect.Struct:
		valueIsZero := true
		for i := 0; i < value.NumField(); i++ {
			if value.Field(i).CanSet() {
			valueIsZero = valueIsZero && isZero(value.Field(i))
		}
		}
		return valueIsZero
	case reflect.Ptr:
		if !value.IsNil() {
+25 −0
Original line number Diff line number Diff line
@@ -275,6 +275,31 @@ cc_library_static { name: "b" }
    copts = ["-Ifoo/bar"],
    srcs = ["a.cpp"],
    static_deps_for_shared = [":b"],
)`},
		},
		{
			description:                        "cc_library non-configured version script",
			moduleTypeUnderTest:                "cc_library",
			moduleTypeUnderTestFactory:         cc.LibraryFactory,
			moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
			depsMutators:                       []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
			dir:                                "foo/bar",
			filesystem: map[string]string{
				"foo/bar/Android.bp": `
cc_library {
    name: "a",
    srcs: ["a.cpp"],
    version_script: "v.map",
    bazel_module: { bp2build_available: true },
}
`,
			},
			bp: soongCcLibraryPreamble,
			expectedBazelTargets: []string{`cc_library(
    name = "a",
    copts = ["-Ifoo/bar"],
    srcs = ["a.cpp"],
    version_script = "v.map",
)`},
		},
	}
+7 −1
Original line number Diff line number Diff line
@@ -30,6 +30,11 @@ func getStringListValues(list bazel.StringListAttribute) (reflect.Value, selects
	return value, archSelects, osSelects
}

func getLabelValue(label bazel.LabelAttribute) (reflect.Value, selects, selects) {
	value := reflect.ValueOf(label.Value)
	return value, nil, nil
}

func getLabelListValues(list bazel.LabelListAttribute) (reflect.Value, selects, selects) {
	value := reflect.ValueOf(list.Value.Includes)
	if !list.HasConfigurableValues() {
@@ -54,12 +59,13 @@ func getLabelListValues(list bazel.LabelListAttribute) (reflect.Value, selects,
func prettyPrintAttribute(v bazel.Attribute, indent int) (string, error) {
	var value reflect.Value
	var archSelects, osSelects selects

	switch list := v.(type) {
	case bazel.StringListAttribute:
		value, archSelects, osSelects = getStringListValues(list)
	case bazel.LabelListAttribute:
		value, archSelects, osSelects = getLabelListValues(list)
	case bazel.LabelAttribute:
		value, archSelects, osSelects = getLabelValue(list)
	default:
		return "", fmt.Errorf("Not a supported Bazel attribute type: %s", v)
	}
Loading