Handle arch/os-specific product variables
Bug: 183595873
Test: go test bp2build tests
Change-Id: I36e93ae1eb2943555dd304d5bdf62d995e77b437
diff --git a/android/variable.go b/android/variable.go
index 672576a..cf74933 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -467,7 +467,7 @@
// 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 @@
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 @@
// 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) {