From 9e2a5a7d6d311902803997582b67b8dc1495b865 Mon Sep 17 00:00:00 2001 From: Liz Kammer Date: Tue, 19 Sep 2023 08:41:14 -0400 Subject: Don't panic for unhandled product vars Instead, we return an error. This allows us to access some product variable information earlier when it will not be used as an attribute without panicing Test: m nothing Change-Id: Id094b2b9e1364a8d174d99b3824fa149fb235b3e --- android/variable.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'android/variable.go') diff --git a/android/variable.go b/android/variable.go index 6d9cc4b8d..e521ca21c 100644 --- a/android/variable.go +++ b/android/variable.go @@ -669,7 +669,8 @@ type ProductConfigProperties map[string]map[ProductConfigOrSoongConfigProperty]i // ProductVariableProperties returns a ProductConfigProperties containing only the properties which // have been set for the given module. -func ProductVariableProperties(ctx ArchVariantContext, module Module) ProductConfigProperties { +func ProductVariableProperties(ctx ArchVariantContext, module Module) (ProductConfigProperties, []error) { + var errs []error moduleBase := module.base() productConfigProperties := ProductConfigProperties{} @@ -693,12 +694,15 @@ func ProductVariableProperties(ctx ArchVariantContext, module Module) ProductCon for namespace, namespacedVariableProps := range m.namespacedVariableProps() { for _, namespacedVariableProp := range namespacedVariableProps { variableValues := reflect.ValueOf(namespacedVariableProp).Elem().FieldByName(soongconfig.SoongConfigProperty) - productConfigProperties.AddSoongConfigProperties(namespace, variableValues) + err := productConfigProperties.AddSoongConfigProperties(namespace, variableValues) + if err != nil { + errs = append(errs, err) + } } } } - return productConfigProperties + return productConfigProperties, errs } func (p *ProductConfigProperties) AddProductConfigProperty( @@ -820,7 +824,7 @@ func (productConfigProperties *ProductConfigProperties) AddProductConfigProperti } -func (productConfigProperties *ProductConfigProperties) AddSoongConfigProperties(namespace string, soongConfigVariablesStruct reflect.Value) { +func (productConfigProperties *ProductConfigProperties) AddSoongConfigProperties(namespace string, soongConfigVariablesStruct reflect.Value) error { // // Example of soong_config_variables: // @@ -917,7 +921,7 @@ func (productConfigProperties *ProductConfigProperties) AddSoongConfigProperties if propertyName == "Target" { productConfigProperties.AddSoongConfigPropertiesFromTargetStruct(namespace, variableName, proptools.PropertyNameForField(propertyOrValueName), field.Field(k)) } else if propertyName == "Arch" || propertyName == "Multilib" { - panic("Arch/Multilib are not currently supported in soong config variable structs") + return fmt.Errorf("Arch/Multilib are not currently supported in soong config variable structs") } else { productConfigProperties.AddSoongConfigProperty(propertyName, namespace, variableName, proptools.PropertyNameForField(propertyOrValueName), "", field.Field(k).Interface()) } @@ -928,13 +932,14 @@ func (productConfigProperties *ProductConfigProperties) AddSoongConfigProperties if propertyOrValueName == "Target" { productConfigProperties.AddSoongConfigPropertiesFromTargetStruct(namespace, variableName, "", propertyOrStruct) } else if propertyOrValueName == "Arch" || propertyOrValueName == "Multilib" { - panic("Arch/Multilib are not currently supported in soong config variable structs") + return fmt.Errorf("Arch/Multilib are not currently supported in soong config variable structs") } else { productConfigProperties.AddSoongConfigProperty(propertyOrValueName, namespace, variableName, "", "", propertyOrStruct.Interface()) } } } } + return nil } func (productConfigProperties *ProductConfigProperties) AddSoongConfigPropertiesFromTargetStruct(namespace, soongConfigVariableName string, soongConfigVariableValue string, targetStruct reflect.Value) { -- cgit v1.2.3-59-g8ed1b