Merge "Allow soong config variables to be boolean-typed" into main am: 1c74ac54a8
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/3141002 Change-Id: I0473826c4a9c9f9c3b0cea8dbad8aa59f09f03d2 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -2253,7 +2253,20 @@ func (e configurationEvalutor) EvaluateConfiguration(condition proptools.Configu
|
|||||||
variable := condition.Arg(1)
|
variable := condition.Arg(1)
|
||||||
if n, ok := ctx.Config().productVariables.VendorVars[namespace]; ok {
|
if n, ok := ctx.Config().productVariables.VendorVars[namespace]; ok {
|
||||||
if v, ok := n[variable]; ok {
|
if v, ok := n[variable]; ok {
|
||||||
return proptools.ConfigurableValueString(v)
|
ty := ""
|
||||||
|
if namespaces, ok := ctx.Config().productVariables.VendorVarTypes[namespace]; ok {
|
||||||
|
ty = namespaces[variable]
|
||||||
|
}
|
||||||
|
switch ty {
|
||||||
|
case "":
|
||||||
|
// strings are the default, we don't bother writing them to the soong variables json file
|
||||||
|
return proptools.ConfigurableValueString(v)
|
||||||
|
case "bool":
|
||||||
|
return proptools.ConfigurableValueBool(v == "true")
|
||||||
|
default:
|
||||||
|
panic("unhandled soong config variable type: " + ty)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return proptools.ConfigurableValueUndefined()
|
return proptools.ConfigurableValueUndefined()
|
||||||
|
@@ -25,12 +25,13 @@ import (
|
|||||||
|
|
||||||
func TestSelects(t *testing.T) {
|
func TestSelects(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
bp string
|
bp string
|
||||||
provider selectsTestProvider
|
provider selectsTestProvider
|
||||||
providers map[string]selectsTestProvider
|
providers map[string]selectsTestProvider
|
||||||
vendorVars map[string]map[string]string
|
vendorVars map[string]map[string]string
|
||||||
expectedError string
|
vendorVarTypes map[string]map[string]string
|
||||||
|
expectedError string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "basic string list",
|
name: "basic string list",
|
||||||
@@ -583,6 +584,31 @@ func TestSelects(t *testing.T) {
|
|||||||
my_string: proptools.StringPtr("t"),
|
my_string: proptools.StringPtr("t"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Select on boolean soong config variable",
|
||||||
|
bp: `
|
||||||
|
my_module_type {
|
||||||
|
name: "foo",
|
||||||
|
my_string: select(soong_config_variable("my_namespace", "my_variable"), {
|
||||||
|
true: "t",
|
||||||
|
false: "f",
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
vendorVars: map[string]map[string]string{
|
||||||
|
"my_namespace": {
|
||||||
|
"my_variable": "true",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
vendorVarTypes: map[string]map[string]string{
|
||||||
|
"my_namespace": {
|
||||||
|
"my_variable": "bool",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
provider: selectsTestProvider{
|
||||||
|
my_string: proptools.StringPtr("t"),
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "Select on boolean false",
|
name: "Select on boolean false",
|
||||||
bp: `
|
bp: `
|
||||||
@@ -813,6 +839,7 @@ func TestSelects(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
FixtureModifyProductVariables(func(variables FixtureProductVariables) {
|
FixtureModifyProductVariables(func(variables FixtureProductVariables) {
|
||||||
variables.VendorVars = tc.vendorVars
|
variables.VendorVars = tc.vendorVars
|
||||||
|
variables.VendorVarTypes = tc.vendorVarTypes
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
if tc.expectedError != "" {
|
if tc.expectedError != "" {
|
||||||
|
@@ -399,7 +399,8 @@ type ProductVariables struct {
|
|||||||
|
|
||||||
PlatformSepolicyCompatVersions []string `json:",omitempty"`
|
PlatformSepolicyCompatVersions []string `json:",omitempty"`
|
||||||
|
|
||||||
VendorVars map[string]map[string]string `json:",omitempty"`
|
VendorVars map[string]map[string]string `json:",omitempty"`
|
||||||
|
VendorVarTypes map[string]map[string]string `json:",omitempty"`
|
||||||
|
|
||||||
Ndk_abis *bool `json:",omitempty"`
|
Ndk_abis *bool `json:",omitempty"`
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user