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

Commit 846ce68a authored by Spandan Das's avatar Spandan Das
Browse files

Handle enabled: false via conditions_default

In this Android.bp file
```
my_cc_defaults {
  enabled: false,
  soong_config_variables: {
    my_bool_variable: {
       conditions_default: {enabled: false},
    }
  }
}
```
The inner enabled: false is a no-op because the top-level enabled is
false. Currently, bp2build will raise an exception for this Android.bp
file.

However, it does not need to. `productVariableConfigEnableLabels` runs
only if the top-level enabled is false. If it sees enabled: false via
conditions_default, it should just ignore it since it is a no-op.

Test: go test ./bp2build
Bug: 210546943
Change-Id: I816f209eaf21de65ddfbc2893e5255be94bcaa11
parent 479e39f8
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -1441,6 +1441,10 @@ func productVariableConfigEnableAttribute(ctx *topDownMutatorContext) bazel.Labe
				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")
+25 −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) {