Handle arch/os-specific product variables
Bug: 183595873 Test: go test bp2build tests Change-Id: I36e93ae1eb2943555dd304d5bdf62d995e77b437
This commit is contained in:
@@ -467,7 +467,7 @@ type ProductConfigProperties map[string][]ProductConfigProperty
|
|||||||
|
|
||||||
// ProductVariableProperties returns a ProductConfigProperties containing only the properties which
|
// ProductVariableProperties returns a ProductConfigProperties containing only the properties which
|
||||||
// have been set for the module in the given context.
|
// have been set for the module in the given context.
|
||||||
func ProductVariableProperties(ctx ProductConfigContext) ProductConfigProperties {
|
func ProductVariableProperties(ctx BaseMutatorContext) ProductConfigProperties {
|
||||||
module := ctx.Module()
|
module := ctx.Module()
|
||||||
moduleBase := module.base()
|
moduleBase := module.base()
|
||||||
|
|
||||||
@@ -477,7 +477,28 @@ func ProductVariableProperties(ctx ProductConfigContext) ProductConfigProperties
|
|||||||
return 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++ {
|
for i := 0; i < variableValues.NumField(); i++ {
|
||||||
variableValue := variableValues.Field(i)
|
variableValue := variableValues.Field(i)
|
||||||
// Check if any properties were set for the module
|
// Check if any properties were set for the module
|
||||||
@@ -495,15 +516,13 @@ func ProductVariableProperties(ctx ProductConfigContext) ProductConfigProperties
|
|||||||
|
|
||||||
// e.g. Asflags, Cflags, Enabled, etc.
|
// e.g. Asflags, Cflags, Enabled, etc.
|
||||||
propertyName := variableValue.Type().Field(j).Name
|
propertyName := variableValue.Type().Field(j).Name
|
||||||
productConfigProperties[propertyName] = append(productConfigProperties[propertyName],
|
(*productConfigProperties)[propertyName] = append((*productConfigProperties)[propertyName],
|
||||||
ProductConfigProperty{
|
ProductConfigProperty{
|
||||||
ProductConfigVariable: productVariableName,
|
ProductConfigVariable: productVariableName + suffix,
|
||||||
Property: property.Interface(),
|
Property: property.Interface(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return productConfigProperties
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func VariableMutator(mctx BottomUpMutatorContext) {
|
func VariableMutator(mctx BottomUpMutatorContext) {
|
||||||
|
@@ -563,6 +563,12 @@ func (attrs *StringListAttribute) SetValueForOS(os string, value []string) {
|
|||||||
*v = value
|
*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
|
// Append appends all values, including os and arch specific ones, from another
|
||||||
// StringListAttribute to this StringListAttribute
|
// StringListAttribute to this StringListAttribute
|
||||||
func (attrs *StringListAttribute) Append(other StringListAttribute) {
|
func (attrs *StringListAttribute) Append(other StringListAttribute) {
|
||||||
|
@@ -1187,14 +1187,86 @@ cc_library_static {
|
|||||||
"-I.",
|
"-I.",
|
||||||
"-I$(BINDIR)/.",
|
"-I$(BINDIR)/.",
|
||||||
] + select({
|
] + select({
|
||||||
|
"//build/bazel/product_variables:binder32bit": ["-Wbinder32bit"],
|
||||||
|
"//conditions:default": [],
|
||||||
|
}) + select({
|
||||||
"//build/bazel/product_variables:malloc_not_svelte": ["-Wmalloc_not_svelte"],
|
"//build/bazel/product_variables:malloc_not_svelte": ["-Wmalloc_not_svelte"],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
}) + select({
|
}) + select({
|
||||||
"//build/bazel/product_variables:malloc_zero_contents": ["-Wmalloc_zero_contents"],
|
"//build/bazel/product_variables:malloc_zero_contents": ["-Wmalloc_zero_contents"],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
}) + select({
|
}),
|
||||||
"//build/bazel/product_variables:binder32bit": ["-Wbinder32bit"],
|
linkstatic = True,
|
||||||
"//conditions:default": [],
|
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: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,
|
linkstatic = True,
|
||||||
srcs = ["common.c"],
|
srcs = ["common.c"],
|
||||||
|
@@ -34,7 +34,7 @@ func getStringListValues(list bazel.StringListAttribute) (reflect.Value, []selec
|
|||||||
selectValues = append(selectValues, osSelects)
|
selectValues = append(selectValues, osSelects)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, pv := range list.ProductValues {
|
for _, pv := range list.SortedProductVariables() {
|
||||||
s := make(selects)
|
s := make(selects)
|
||||||
if len(pv.Values) > 0 {
|
if len(pv.Values) > 0 {
|
||||||
s[pv.SelectKey()] = reflect.ValueOf(pv.Values)
|
s[pv.SelectKey()] = reflect.ValueOf(pv.Values)
|
||||||
|
Reference in New Issue
Block a user