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
This commit is contained in:
Spandan Das
2023-08-08 02:00:22 +00:00
parent 479e39f8fb
commit 846ce68a2f
2 changed files with 29 additions and 1 deletions

View File

@@ -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")