Allow value variables to set pointer properties
Non-null pointers were always leading to an "unsupported property type"
error due to not updating the kind field.
Bug: 319897584
Test: Presubmits
Change-Id: I058ab8d153d9507f9037d699acf6e1fe4f08f538
diff --git a/android/soongconfig/modules.go b/android/soongconfig/modules.go
index f6b4938..d525bdc 100644
--- a/android/soongconfig/modules.go
+++ b/android/soongconfig/modules.go
@@ -16,12 +16,13 @@
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 @@
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 00e8b78..db2c83c 100644
--- a/android/soongconfig/modules_test.go
+++ b/android/soongconfig/modules_test.go
@@ -299,7 +299,7 @@
Conditions_default *properties
}
-type soongConfigVars struct {
+type boolSoongConfigVars struct {
Bool_var interface{}
}
@@ -307,7 +307,11 @@
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 @@
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_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",