Check that a product variable is set
Store product variables in pointers so that we can only apply the properties if the product variable was set to a value. Also only apply bool properties if they are true, adn rearrange the code to do the cheapest checks first. Remove device_uses_logd, it doesn't exist any more. Change-Id: Icf42408f57bd611746f8d985bfceb50c7f95ea59
This commit is contained in:
@@ -31,10 +31,6 @@ func init() {
|
|||||||
|
|
||||||
type variableProperties struct {
|
type variableProperties struct {
|
||||||
Product_variables struct {
|
Product_variables struct {
|
||||||
Device_uses_logd struct {
|
|
||||||
Cflags []string
|
|
||||||
Srcs []string
|
|
||||||
}
|
|
||||||
Device_uses_dlmalloc struct {
|
Device_uses_dlmalloc struct {
|
||||||
Cflags []string
|
Cflags []string
|
||||||
Srcs []string
|
Srcs []string
|
||||||
@@ -54,16 +50,18 @@ type variableProperties struct {
|
|||||||
var zeroProductVariables variableProperties
|
var zeroProductVariables variableProperties
|
||||||
|
|
||||||
type productVariables struct {
|
type productVariables struct {
|
||||||
Device_uses_logd bool
|
Device_uses_jemalloc *bool `json:",omitempty"`
|
||||||
Device_uses_jemalloc bool
|
Device_uses_dlmalloc *bool `json:",omitempty"`
|
||||||
Device_uses_dlmalloc bool
|
Dlmalloc_alignment *int `json:",omitempty"`
|
||||||
Dlmalloc_alignment int
|
}
|
||||||
|
|
||||||
|
func boolPtr(v bool) *bool {
|
||||||
|
return &v
|
||||||
}
|
}
|
||||||
|
|
||||||
func (productVariables) DefaultConfig() jsonConfigurable {
|
func (productVariables) DefaultConfig() jsonConfigurable {
|
||||||
v := productVariables{
|
v := productVariables{
|
||||||
Device_uses_logd: true,
|
Device_uses_jemalloc: boolPtr(true),
|
||||||
Device_uses_jemalloc: true,
|
|
||||||
}
|
}
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
@@ -83,18 +81,28 @@ func VariableMutator(mctx blueprint.EarlyMutatorContext) {
|
|||||||
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)
|
zeroValue := zeroValues.Field(i)
|
||||||
if reflect.DeepEqual(variableValue, zeroValue) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
name := variableValues.Type().Field(i).Name
|
name := variableValues.Type().Field(i).Name
|
||||||
property := "product_variables." + proptools.PropertyNameForField(name)
|
property := "product_variables." + proptools.PropertyNameForField(name)
|
||||||
|
|
||||||
|
// Check that the variable was set for the product
|
||||||
val := reflect.ValueOf(mctx.Config().(Config).ProductVariables).FieldByName(name)
|
val := reflect.ValueOf(mctx.Config().(Config).ProductVariables).FieldByName(name)
|
||||||
|
if !val.IsValid() || val.Kind() != reflect.Ptr || val.IsNil() {
|
||||||
if mctx.ContainsProperty(property) && val.IsValid() {
|
continue
|
||||||
a.setVariableProperties(mctx, property, variableValue, val.Interface())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val = val.Elem()
|
||||||
|
|
||||||
|
// For bools, check that the value is true
|
||||||
|
if val.Kind() == reflect.Bool && val.Bool() == false {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if any properties were set for the module
|
||||||
|
if reflect.DeepEqual(variableValue.Interface(), zeroValue.Interface()) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
a.setVariableProperties(mctx, property, variableValue, val.Interface())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user