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
This commit is contained in:
Cole Faust 2024-01-12 12:12:26 -08:00
parent 744a2a6b7d
commit a03ac3a75a
2 changed files with 68 additions and 6 deletions

View file

@ -16,12 +16,13 @@ package soongconfig
import ( import (
"fmt" "fmt"
"github.com/google/blueprint/parser"
"github.com/google/blueprint/proptools"
"io" "io"
"reflect" "reflect"
"sort" "sort"
"strings" "strings"
"github.com/google/blueprint/parser"
"github.com/google/blueprint/proptools"
) )
const conditionsDefault = "conditions_default" const conditionsDefault = "conditions_default"
@ -688,6 +689,7 @@ func (s *valueVariable) PropertiesToApply(config SoongConfig, values reflect.Val
continue continue
} }
field = field.Elem() field = field.Elem()
kind = field.Kind()
} }
switch kind { switch kind {
case reflect.String: case reflect.String:

View file

@ -299,7 +299,7 @@ type boolVarProps struct {
Conditions_default *properties Conditions_default *properties
} }
type soongConfigVars struct { type boolSoongConfigVars struct {
Bool_var interface{} Bool_var interface{}
} }
@ -307,7 +307,11 @@ type stringSoongConfigVars struct {
String_var interface{} 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{ mt, _ := newModuleType(&ModuleTypeProperties{
Module_type: "foo", Module_type: "foo",
Config_namespace: "bar", Config_namespace: "bar",
@ -323,9 +327,9 @@ func Test_PropertiesToApply(t *testing.T) {
B: false, B: false,
} }
actualProps := &struct { actualProps := &struct {
Soong_config_variables soongConfigVars Soong_config_variables boolSoongConfigVars
}{ }{
Soong_config_variables: soongConfigVars{ Soong_config_variables: boolSoongConfigVars{
Bool_var: &boolVarProps{ Bool_var: &boolVarProps{
A: boolVarPositive.A, A: boolVarPositive.A,
B: boolVarPositive.B, 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) { func Test_PropertiesToApply_String_Error(t *testing.T) {
mt, _ := newModuleType(&ModuleTypeProperties{ mt, _ := newModuleType(&ModuleTypeProperties{
Module_type: "foo", Module_type: "foo",