From 28357db9d0c33ce1c749371eeeff16e0d658a252 Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Fri, 12 Apr 2024 14:43:10 -0700 Subject: [PATCH] Support unpacking a variable to a configurable property Bug: 323382414 Test: m nothing --no-skip-soong-tests Change-Id: I504e53c34305f5de0af8629bf21ac1ce94704732 --- proptools/unpack.go | 3 +++ proptools/unpack_test.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/proptools/unpack.go b/proptools/unpack.go index 53b2b2f..5886cb1 100644 --- a/proptools/unpack.go +++ b/proptools/unpack.go @@ -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() diff --git a/proptools/unpack_test.go b/proptools/unpack_test.go index 3182c8b..fee7c9c 100644 --- a/proptools/unpack_test.go +++ b/proptools/unpack_test.go @@ -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) {