Merge "Add test & documentation for PropertiesToApply"
This commit is contained in:
@@ -158,11 +158,7 @@ func processModuleTypeDef(v *SoongConfigDefinition, def *parser.Module) (errs []
|
|||||||
return []error{fmt.Errorf("bool_variable name must not be blank")}
|
return []error{fmt.Errorf("bool_variable name must not be blank")}
|
||||||
}
|
}
|
||||||
|
|
||||||
mt.Variables = append(mt.Variables, &boolVariable{
|
mt.Variables = append(mt.Variables, newBoolVariable(name))
|
||||||
baseVariable: baseVariable{
|
|
||||||
variable: name,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, name := range props.Value_variables {
|
for _, name := range props.Value_variables {
|
||||||
@@ -420,6 +416,9 @@ func typeForPropertyFromPropertyStruct(ps interface{}, property string) reflect.
|
|||||||
|
|
||||||
// PropertiesToApply returns the applicable properties from a ModuleType that should be applied
|
// PropertiesToApply returns the applicable properties from a ModuleType that should be applied
|
||||||
// based on SoongConfig values.
|
// based on SoongConfig values.
|
||||||
|
// Expects that props contains a struct field with name soong_config_variables. The fields within
|
||||||
|
// soong_config_variables are expected to be in the same order as moduleType.Variables. In general,
|
||||||
|
// props should be generated via CreateProperties.
|
||||||
func PropertiesToApply(moduleType *ModuleType, props reflect.Value, config SoongConfig) ([]interface{}, error) {
|
func PropertiesToApply(moduleType *ModuleType, props reflect.Value, config SoongConfig) ([]interface{}, error) {
|
||||||
var ret []interface{}
|
var ret []interface{}
|
||||||
props = props.Elem().FieldByName(soongConfigProperty)
|
props = props.Elem().FieldByName(soongConfigProperty)
|
||||||
@@ -505,6 +504,14 @@ type boolVariable struct {
|
|||||||
baseVariable
|
baseVariable
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newBoolVariable(name string) *boolVariable {
|
||||||
|
return &boolVariable{
|
||||||
|
baseVariable{
|
||||||
|
variable: name,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (b boolVariable) variableValuesType() reflect.Type {
|
func (b boolVariable) variableValuesType() reflect.Type {
|
||||||
return emptyInterfaceType
|
return emptyInterfaceType
|
||||||
}
|
}
|
||||||
|
@@ -17,6 +17,8 @@ package soongconfig
|
|||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/blueprint/proptools"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_CanonicalizeToProperty(t *testing.T) {
|
func Test_CanonicalizeToProperty(t *testing.T) {
|
||||||
@@ -247,3 +249,72 @@ func Test_createAffectablePropertiesType(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type properties struct {
|
||||||
|
A *string
|
||||||
|
B bool
|
||||||
|
}
|
||||||
|
type soongConfigVariables struct {
|
||||||
|
Bool_var properties
|
||||||
|
Other_bool_var properties
|
||||||
|
}
|
||||||
|
|
||||||
|
type soongConfigProps struct {
|
||||||
|
Soong_config_variables soongConfigVariables
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_PropertiesToApply(t *testing.T) {
|
||||||
|
|
||||||
|
mt := &ModuleType{
|
||||||
|
BaseModuleType: "foo",
|
||||||
|
ConfigNamespace: "bar",
|
||||||
|
Variables: []soongConfigVariable{
|
||||||
|
newBoolVariable("bool_var"),
|
||||||
|
newBoolVariable("other_bool_var"),
|
||||||
|
},
|
||||||
|
affectableProperties: []string{
|
||||||
|
"a",
|
||||||
|
"b",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
props := soongConfigProps{
|
||||||
|
Soong_config_variables: soongConfigVariables{
|
||||||
|
Bool_var: properties{
|
||||||
|
A: proptools.StringPtr("a"),
|
||||||
|
B: true,
|
||||||
|
},
|
||||||
|
Other_bool_var: properties{
|
||||||
|
A: proptools.StringPtr("other"),
|
||||||
|
B: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
testCases := []struct {
|
||||||
|
config SoongConfig
|
||||||
|
wantProps []interface{}
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
config: Config(map[string]string{}),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
config: Config(map[string]string{"bool_var": "y"}),
|
||||||
|
wantProps: []interface{}{props.Soong_config_variables.Bool_var},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
config: Config(map[string]string{"other_bool_var": "y"}),
|
||||||
|
wantProps: []interface{}{props.Soong_config_variables.Other_bool_var},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range testCases {
|
||||||
|
gotProps, err := PropertiesToApply(mt, reflect.ValueOf(&props), tc.config)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error in PropertiesToApply: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(gotProps, tc.wantProps) {
|
||||||
|
t.Errorf("Expected %s, got %s", tc.wantProps, gotProps)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user