Support unpacking a variable to a configurable property

Bug: 323382414
Test: m nothing --no-skip-soong-tests
Change-Id: I504e53c34305f5de0af8629bf21ac1ce94704732
This commit is contained in:
Cole Faust 2024-04-12 14:43:10 -07:00
parent 3311debbb3
commit 28357db9d0
2 changed files with 39 additions and 0 deletions

View file

@ -419,6 +419,9 @@ func (ctx *unpackContext) unpackToConfigurable(propertyName string, property *pa
case *parser.Operator:
property.Value = v.Value.Eval()
return ctx.unpackToConfigurable(propertyName, property, configurableType, configuredType)
case *parser.Variable:
property.Value = v.Value.Eval()
return ctx.unpackToConfigurable(propertyName, property, configurableType, configuredType)
case *parser.Select:
resultPtr := reflect.New(configurableType)
result := resultPtr.Elem()

View file

@ -924,6 +924,42 @@ var validUnpackTestCases = []struct {
},
},
},
{
name: "Unpack variable to configurable property",
input: `
my_string_variable = "asdf"
my_bool_variable = true
m {
foo: my_string_variable,
bar: my_bool_variable,
}
`,
output: []interface{}{
&struct {
Foo Configurable[string]
Bar Configurable[bool]
}{
Foo: Configurable[string]{
propertyName: "foo",
cases: []configurableCase[string]{
{
value: StringPtr("asdf"),
},
},
appendWrapper: &appendWrapper[string]{},
},
Bar: Configurable[bool]{
propertyName: "bar",
cases: []configurableCase[bool]{
{
value: BoolPtr(true),
},
},
appendWrapper: &appendWrapper[bool]{},
},
},
},
},
}
func TestUnpackProperties(t *testing.T) {