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

Commit 91743e86 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Handle arch/os-specific product variables" am: c1ae9243

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1700827

Change-Id: I7ec018044a260cc0ecddf02470b451a474aab92e
parents 31353efe c1ae9243
Loading
Loading
Loading
Loading
+25 −6
Original line number Diff line number Diff line
@@ -467,7 +467,7 @@ type ProductConfigProperties map[string][]ProductConfigProperty

// ProductVariableProperties returns a ProductConfigProperties containing only the properties which
// have been set for the module in the given context.
func ProductVariableProperties(ctx ProductConfigContext) ProductConfigProperties {
func ProductVariableProperties(ctx BaseMutatorContext) ProductConfigProperties {
	module := ctx.Module()
	moduleBase := module.base()

@@ -477,7 +477,28 @@ func ProductVariableProperties(ctx ProductConfigContext) ProductConfigProperties
		return productConfigProperties
	}

	variableValues := reflect.ValueOf(moduleBase.variableProperties).Elem().FieldByName("Product_variables")
	productVariableValues(moduleBase.variableProperties, "", &productConfigProperties)

	for arch, targetProps := range moduleBase.GetArchProperties(ctx, moduleBase.variableProperties) {
		// GetArchProperties is creating an instance of the requested type
		// and productVariablesValues expects an interface, so no need to cast
		productVariableValues(targetProps, arch.Name, &productConfigProperties)
	}

	for os, targetProps := range moduleBase.GetTargetProperties(ctx, moduleBase.variableProperties) {
		// GetTargetProperties is creating an instance of the requested type
		// and productVariablesValues expects an interface, so no need to cast
		productVariableValues(targetProps, os.Name, &productConfigProperties)
	}

	return productConfigProperties
}

func productVariableValues(variableProps interface{}, suffix string, productConfigProperties *ProductConfigProperties) {
	if suffix != "" {
		suffix = "-" + suffix
	}
	variableValues := reflect.ValueOf(variableProps).Elem().FieldByName("Product_variables")
	for i := 0; i < variableValues.NumField(); i++ {
		variableValue := variableValues.Field(i)
		// Check if any properties were set for the module
@@ -495,15 +516,13 @@ func ProductVariableProperties(ctx ProductConfigContext) ProductConfigProperties

			// e.g. Asflags, Cflags, Enabled, etc.
			propertyName := variableValue.Type().Field(j).Name
			productConfigProperties[propertyName] = append(productConfigProperties[propertyName],
			(*productConfigProperties)[propertyName] = append((*productConfigProperties)[propertyName],
				ProductConfigProperty{
					ProductConfigVariable: productVariableName,
					ProductConfigVariable: productVariableName + suffix,
					Property:              property.Interface(),
				})
		}
	}

	return productConfigProperties
}

func VariableMutator(mctx BottomUpMutatorContext) {
+6 −0
Original line number Diff line number Diff line
@@ -563,6 +563,12 @@ func (attrs *StringListAttribute) SetValueForOS(os string, value []string) {
	*v = value
}

func (attrs *StringListAttribute) SortedProductVariables() []ProductVariableValues {
	vals := attrs.ProductValues[:]
	sort.Slice(vals, func(i, j int) bool { return vals[i].ProductVariable < vals[j].ProductVariable })
	return vals
}

// Append appends all values, including os and arch specific ones, from another
// StringListAttribute to this StringListAttribute
func (attrs *StringListAttribute) Append(other StringListAttribute) {
+73 −1
Original line number Diff line number Diff line
@@ -1187,13 +1187,85 @@ cc_library_static {
        "-I.",
        "-I$(BINDIR)/.",
    ] + select({
        "//build/bazel/product_variables:binder32bit": ["-Wbinder32bit"],
        "//conditions:default": [],
    }) + select({
        "//build/bazel/product_variables:malloc_not_svelte": ["-Wmalloc_not_svelte"],
        "//conditions:default": [],
    }) + select({
        "//build/bazel/product_variables:malloc_zero_contents": ["-Wmalloc_zero_contents"],
        "//conditions:default": [],
    }),
    linkstatic = True,
    srcs = ["common.c"],
)`},
	})
}

func TestCcLibraryStaticProductVariableArchSpecificSelects(t *testing.T) {
	runCcLibraryStaticTestCase(t, bp2buildTestCase{
		description:                        "cc_library_static arch-specific product variable selects",
		moduleTypeUnderTest:                "cc_library_static",
		moduleTypeUnderTestFactory:         cc.LibraryStaticFactory,
		moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
		depsMutators:                       []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
		filesystem:                         map[string]string{},
		blueprint: soongCcLibraryStaticPreamble + `
cc_library_static {
    name: "foo_static",
    srcs: ["common.c"],
    product_variables: {
      malloc_not_svelte: {
        cflags: ["-Wmalloc_not_svelte"],
      },
    },
		arch: {
				arm64: {
						product_variables: {
								malloc_not_svelte: {
										cflags: ["-Warm64_malloc_not_svelte"],
								},
						},
				},
		},
		multilib: {
				lib32: {
						product_variables: {
								malloc_not_svelte: {
										cflags: ["-Wlib32_malloc_not_svelte"],
								},
						},
				},
		},
		target: {
				android: {
						product_variables: {
								malloc_not_svelte: {
										cflags: ["-Wandroid_malloc_not_svelte"],
								},
						},
				}
		},
} `,
		expectedBazelTargets: []string{`cc_library_static(
    name = "foo_static",
    copts = [
        "-I.",
        "-I$(BINDIR)/.",
    ] + select({
        "//build/bazel/product_variables:malloc_not_svelte": ["-Wmalloc_not_svelte"],
        "//conditions:default": [],
    }) + select({
        "//build/bazel/product_variables:binder32bit": ["-Wbinder32bit"],
        "//build/bazel/product_variables:malloc_not_svelte-android": ["-Wandroid_malloc_not_svelte"],
        "//conditions:default": [],
    }) + select({
        "//build/bazel/product_variables:malloc_not_svelte-arm": ["-Wlib32_malloc_not_svelte"],
        "//conditions:default": [],
    }) + select({
        "//build/bazel/product_variables:malloc_not_svelte-arm64": ["-Warm64_malloc_not_svelte"],
        "//conditions:default": [],
    }) + select({
        "//build/bazel/product_variables:malloc_not_svelte-x86": ["-Wlib32_malloc_not_svelte"],
        "//conditions:default": [],
    }),
    linkstatic = True,
+1 −1
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ func getStringListValues(list bazel.StringListAttribute) (reflect.Value, []selec
		selectValues = append(selectValues, osSelects)
	}

	for _, pv := range list.ProductValues {
	for _, pv := range list.SortedProductVariables() {
		s := make(selects)
		if len(pv.Values) > 0 {
			s[pv.SelectKey()] = reflect.ValueOf(pv.Values)