Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 46f6e2f1 authored by Cole Faust's avatar Cole Faust
Browse files

Allow soong config variables to be boolean-typed

So that you can use `true` instead of `"true"` in select expressions.

Bug: 323382414
Test: m nothing --no-skip-soong-tests
Change-Id: I950bd8e04f8fab5187ea5075514d476227943f33
parent 26faf1b3
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -2253,7 +2253,20 @@ func (e configurationEvalutor) EvaluateConfiguration(condition proptools.Configu
		variable := condition.Arg(1)
		if n, ok := ctx.Config().productVariables.VendorVars[namespace]; ok {
			if v, ok := n[variable]; ok {
				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()
+33 −6
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ func TestSelects(t *testing.T) {
		provider       selectsTestProvider
		providers      map[string]selectsTestProvider
		vendorVars     map[string]map[string]string
		vendorVarTypes map[string]map[string]string
		expectedError  string
	}{
		{
@@ -583,6 +584,31 @@ func TestSelects(t *testing.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",
			bp: `
@@ -813,6 +839,7 @@ func TestSelects(t *testing.T) {
				}),
				FixtureModifyProductVariables(func(variables FixtureProductVariables) {
					variables.VendorVars = tc.vendorVars
					variables.VendorVarTypes = tc.vendorVarTypes
				}),
			)
			if tc.expectedError != "" {
+2 −1
Original line number Diff line number Diff line
@@ -400,6 +400,7 @@ type ProductVariables struct {
	PlatformSepolicyCompatVersions []string `json:",omitempty"`

	VendorVars     map[string]map[string]string `json:",omitempty"`
	VendorVarTypes map[string]map[string]string `json:",omitempty"`

	Ndk_abis *bool `json:",omitempty"`