Fix product variable zero value check
The zero value check was being done by using reflect.DeepEqual on a field from the default product variables, but this results in comparison against a random type when the product variables struct for the module has been filtered down. Luckily this will always fail false, which just removed and optimization but left the behavior correct. Use reflect.IsZero instead, which is both faster and correct. Test: variable_test.go Change-Id: Ieaaa590c2788ca39230e6695397e8ba8d1c6c103
This commit is contained in:
parent
387ad5c576
commit
6961a491a5
|
@ -539,7 +539,7 @@ func InitAndroidModule(m Module) {
|
||||||
|
|
||||||
// Allow tests to override the default product variables
|
// Allow tests to override the default product variables
|
||||||
if base.variableProperties == nil {
|
if base.variableProperties == nil {
|
||||||
base.variableProperties = zeroProductVariables
|
base.variableProperties = defaultProductVariables
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter the product variables properties to the ones that exist on this module
|
// Filter the product variables properties to the ones that exist on this module
|
||||||
|
|
|
@ -133,7 +133,7 @@ type variableProperties struct {
|
||||||
} `android:"arch_variant"`
|
} `android:"arch_variant"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var zeroProductVariables interface{} = variableProperties{}
|
var defaultProductVariables interface{} = variableProperties{}
|
||||||
|
|
||||||
type productVariables struct {
|
type productVariables struct {
|
||||||
// Suffix to add to generated Makefiles
|
// Suffix to add to generated Makefiles
|
||||||
|
@ -399,11 +399,9 @@ func variableMutator(mctx BottomUpMutatorContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
variableValues := reflect.ValueOf(a.variableProperties).Elem().FieldByName("Product_variables")
|
variableValues := reflect.ValueOf(a.variableProperties).Elem().FieldByName("Product_variables")
|
||||||
zeroValues := reflect.ValueOf(zeroProductVariables).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)
|
||||||
zeroValue := zeroValues.Field(i)
|
|
||||||
name := variableValues.Type().Field(i).Name
|
name := variableValues.Type().Field(i).Name
|
||||||
property := "product_variables." + proptools.PropertyNameForField(name)
|
property := "product_variables." + proptools.PropertyNameForField(name)
|
||||||
|
|
||||||
|
@ -421,10 +419,9 @@ func variableMutator(mctx BottomUpMutatorContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if any properties were set for the module
|
// Check if any properties were set for the module
|
||||||
if reflect.DeepEqual(variableValue.Interface(), zeroValue.Interface()) {
|
if variableValue.IsZero() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
a.setVariableProperties(mctx, property, variableValue, val.Interface())
|
a.setVariableProperties(mctx, property, variableValue, val.Interface())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue