diff --git a/android/soongconfig/modules.go b/android/soongconfig/modules.go index f6b49382c..d525bdcfe 100644 --- a/android/soongconfig/modules.go +++ b/android/soongconfig/modules.go @@ -16,12 +16,13 @@ package soongconfig import ( "fmt" - "github.com/google/blueprint/parser" - "github.com/google/blueprint/proptools" "io" "reflect" "sort" "strings" + + "github.com/google/blueprint/parser" + "github.com/google/blueprint/proptools" ) const conditionsDefault = "conditions_default" @@ -688,6 +689,7 @@ func (s *valueVariable) PropertiesToApply(config SoongConfig, values reflect.Val continue } field = field.Elem() + kind = field.Kind() } switch kind { case reflect.String: diff --git a/android/soongconfig/modules_test.go b/android/soongconfig/modules_test.go index 00e8b785a..db2c83ccb 100644 --- a/android/soongconfig/modules_test.go +++ b/android/soongconfig/modules_test.go @@ -299,7 +299,7 @@ type boolVarProps struct { Conditions_default *properties } -type soongConfigVars struct { +type boolSoongConfigVars struct { Bool_var interface{} } @@ -307,7 +307,11 @@ type stringSoongConfigVars struct { String_var interface{} } -func Test_PropertiesToApply(t *testing.T) { +type valueSoongConfigVars struct { + My_value_var interface{} +} + +func Test_PropertiesToApply_Bool(t *testing.T) { mt, _ := newModuleType(&ModuleTypeProperties{ Module_type: "foo", Config_namespace: "bar", @@ -323,9 +327,9 @@ func Test_PropertiesToApply(t *testing.T) { B: false, } actualProps := &struct { - Soong_config_variables soongConfigVars + Soong_config_variables boolSoongConfigVars }{ - Soong_config_variables: soongConfigVars{ + Soong_config_variables: boolSoongConfigVars{ Bool_var: &boolVarProps{ A: boolVarPositive.A, B: boolVarPositive.B, @@ -369,6 +373,62 @@ func Test_PropertiesToApply(t *testing.T) { } } +func Test_PropertiesToApply_Value(t *testing.T) { + mt, _ := newModuleType(&ModuleTypeProperties{ + Module_type: "foo", + Config_namespace: "bar", + Value_variables: []string{"my_value_var"}, + Properties: []string{"a", "b"}, + }) + conditionsDefault := &properties{ + A: proptools.StringPtr("default"), + B: false, + } + actualProps := &struct { + Soong_config_variables valueSoongConfigVars + }{ + Soong_config_variables: valueSoongConfigVars{ + My_value_var: &boolVarProps{ + A: proptools.StringPtr("A=%s"), + B: true, + Conditions_default: conditionsDefault, + }, + }, + } + props := reflect.ValueOf(actualProps) + + testCases := []struct { + name string + config SoongConfig + wantProps []interface{} + }{ + { + name: "no_vendor_config", + config: Config(map[string]string{}), + wantProps: []interface{}{conditionsDefault}, + }, + { + name: "value_var_set", + config: Config(map[string]string{"my_value_var": "Hello"}), + wantProps: []interface{}{&properties{ + A: proptools.StringPtr("A=Hello"), + B: true, + }}, + }, + } + + for _, tc := range testCases { + gotProps, err := PropertiesToApply(mt, props, tc.config) + if err != nil { + t.Errorf("%s: Unexpected error in PropertiesToApply: %s", tc.name, err) + } + + if !reflect.DeepEqual(gotProps, tc.wantProps) { + t.Errorf("%s: Expected %s, got %s", tc.name, tc.wantProps, gotProps) + } + } +} + func Test_PropertiesToApply_String_Error(t *testing.T) { mt, _ := newModuleType(&ModuleTypeProperties{ Module_type: "foo",