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

Commit 479e39f8 authored by Spandan Das's avatar Spandan Das
Browse files

Handle nil enabled values

If enabled does not appear inside `soong_config_vars`, we can ignore it.

Bug: 210546943
Test: go test ./bp2build

Change-Id: I9e4d51c3b683f262921449634f827915ce87dc8d
parent 09f6b139
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -1434,7 +1434,10 @@ func productVariableConfigEnableAttribute(ctx *topDownMutatorContext) bazel.Labe
				ctx.ModuleErrorf("Could not convert product variable enabled property")
			}

			if *flag {
			if flag == nil {
				// soong config var is not used to set `enabled`. nothing to do.
				continue
			} else if *flag {
				axis := productConfigProp.ConfigurationAxis()
				result.SetSelectValue(axis, bazel.ConditionsDefaultConfigKey, bazel.MakeLabelList([]bazel.Label{{Label: "@platforms//:incompatible"}}))
				result.SetSelectValue(axis, productConfigProp.SelectKey(), bazel.LabelList{Includes: []bazel.Label{}})
+55 −0
Original line number Diff line number Diff line
@@ -1520,3 +1520,58 @@ special_cc_defaults {
		runSoongConfigModuleTypeTest(t, bp2buildTestCase)
	}
}

func TestNoPanicIfEnabledIsNotUsed(t *testing.T) {
	bp := `
soong_config_string_variable {
	name: "my_string_variable",
	values: ["val1", "val2"],
}
soong_config_module_type {
	name: "special_cc_defaults",
	module_type: "cc_defaults",
	config_namespace: "my_namespace",
	variables: ["my_string_variable"],
	properties: [
		"cflags",
		"enabled",
	],
}
special_cc_defaults {
	name: "my_special_cc_defaults",
	soong_config_variables: {
		my_string_variable: {
			val1: {
				cflags: ["-DFOO"],
			},
			val2: {
				cflags: ["-DBAR"],
			},
		},
	},
}
cc_binary {
	name: "my_binary",
	enabled: false,
	defaults: ["my_special_cc_defaults"],
}
`
	tc := Bp2buildTestCase{
		Description:                "Soong config vars is not used to set `enabled` property",
		ModuleTypeUnderTest:        "cc_binary",
		ModuleTypeUnderTestFactory: cc.BinaryFactory,
		Blueprint:                  bp,
		ExpectedBazelTargets: []string{
			MakeBazelTarget("cc_binary", "my_binary", AttrNameToString{
				"copts": `select({
        "//build/bazel/product_config/config_settings:my_namespace__my_string_variable__val1": ["-DFOO"],
        "//build/bazel/product_config/config_settings:my_namespace__my_string_variable__val2": ["-DBAR"],
        "//conditions:default": [],
    })`,
				"local_includes":         `["."]`,
				"target_compatible_with": `["@platforms//:incompatible"]`,
			}),
		},
	}
	runSoongConfigModuleTypeTest(t, tc)
}