Handle arch/os-specific product variables

Bug: 183595873
Test: go test bp2build tests
Change-Id: I36e93ae1eb2943555dd304d5bdf62d995e77b437
This commit is contained in:
Liz Kammer
2021-05-10 11:39:53 -04:00
parent 6fd7b3fee9
commit e3e4a5f2d8
4 changed files with 107 additions and 10 deletions

View File

@@ -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) {