Handle the 'enabled' property in bp2build
Also fix some bugs pertaining to configurable attribute handling of bool
attributes and label sttributes, so that they may support values across
multiple different axes at the same time.
Test: unit tests for bp2build
Test: mixed_droid
Change-Id: I411efcfddf02d55dbc0775962068a11348a8bb2c
diff --git a/bp2build/configurability.go b/bp2build/configurability.go
index c953259..dfbb265 100644
--- a/bp2build/configurability.go
+++ b/bp2build/configurability.go
@@ -1,10 +1,11 @@
package bp2build
import (
- "android/soong/android"
- "android/soong/bazel"
"fmt"
"reflect"
+
+ "android/soong/android"
+ "android/soong/bazel"
)
// Configurability support for bp2build.
@@ -89,13 +90,15 @@
}
archSelects := map[string]reflect.Value{}
defaultVal := configToLabels[bazel.ConditionsDefaultConfigKey]
+ // Skip empty list values unless ether EmitEmptyList is true, or these values differ from the default.
+ emitEmptyList := list.EmitEmptyList || len(defaultVal.Includes) > 0
for config, labels := range configToLabels {
// Omit any entries in the map which match the default value, for brevity.
if config != bazel.ConditionsDefaultConfigKey && labels.Equals(defaultVal) {
continue
}
selectKey := axis.SelectKey(config)
- if use, value := labelListSelectValue(selectKey, labels, list.EmitEmptyList); use {
+ if use, value := labelListSelectValue(selectKey, labels, emitEmptyList); use {
archSelects[selectKey] = value
}
}
@@ -144,9 +147,15 @@
shouldPrintDefault = true
}
case bazel.LabelAttribute:
+ if err := list.Collapse(); err != nil {
+ return "", err
+ }
value, configurableAttrs = getLabelValue(list)
defaultSelectValue = &bazelNone
case bazel.BoolAttribute:
+ if err := list.Collapse(); err != nil {
+ return "", err
+ }
value, configurableAttrs = getBoolValue(list)
defaultSelectValue = &bazelNone
default:
@@ -204,11 +213,12 @@
continue
}
value := selectMap[selectKey]
- if isZero(value) && !emitZeroValues {
- // Ignore zero values to not generate empty lists.
+ if isZero(value) && !emitZeroValues && isZero(selectMap[bazel.ConditionsDefaultSelectKey]) {
+ // Ignore zero values to not generate empty lists. However, always note zero values if
+ // the default value is non-zero.
continue
}
- s, err := prettyPrintSelectEntry(value, selectKey, indent, emitZeroValues)
+ s, err := prettyPrintSelectEntry(value, selectKey, indent, true)
if err != nil {
return "", err
}