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

Commit 69bda98f authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes I816f209e,I9e4d51c3 into main

* changes:
  Handle enabled: false via conditions_default
  Handle nil enabled values
parents 002764c8 846ce68a
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -1434,10 +1434,17 @@ 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{}})
			} else if scp, isSoongConfigProperty := productConfigProp.(SoongConfigProperty); isSoongConfigProperty && scp.value == bazel.ConditionsDefaultConfigKey {
				// productVariableConfigEnableAttribute runs only if `enabled: false` is set at the top-level outside soong_config_variables
				// conditions_default { enabled: false} is a no-op in this case
				continue
			} else {
				// TODO(b/210546943): handle negative case where `enabled: false`
				ctx.ModuleErrorf("`enabled: false` is not currently supported for configuration variables. See b/210546943")
+80 −1
Original line number Diff line number Diff line
@@ -1243,6 +1243,24 @@ cc_binary {
    srcs: ["main.cc"],
    defaults: ["alphabet_sample_cc_defaults"],
    enabled: false,
}

alphabet_cc_defaults {
    name: "alphabet_sample_cc_defaults_conditions_default",
    soong_config_variables: {
        special_build: {
		conditions_default: {
			enabled: false,
		},
	},
    },
}

cc_binary {
    name: "alphabet_binary_conditions_default",
    srcs: ["main.cc"],
    defaults: ["alphabet_sample_cc_defaults_conditions_default"],
    enabled: false,
}`

	runSoongConfigModuleTypeTest(t, Bp2buildTestCase{
@@ -1259,7 +1277,13 @@ cc_binary {
        "//build/bazel/product_config/config_settings:alphabet_module__special_build": [],
        "//conditions:default": ["@platforms//:incompatible"],
    }),
)`}})
)`,
			MakeBazelTarget("cc_binary", "alphabet_binary_conditions_default", AttrNameToString{
				"local_includes":         `["."]`,
				"srcs":                   `["main.cc"]`,
				"target_compatible_with": `["@platforms//:incompatible"]`,
			}),
		}})
}

func TestSoongConfigModuleType_ProductVariableIgnoredIfEnabledByDefault(t *testing.T) {
@@ -1520,3 +1544,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)
}