Refactor how bp2build gets arch-specific props.
Then plumb them to LabelAttribute.
This refactoring is required because the previous implementation did not
handle properties in shards other than the first one (e.g.
version_script) well. In addition, it also makes the code paths between
bp2build and analysis more similar.
Bug: 186650430
Test: Presubmits.
Change-Id: Ic4393e8ae47f4e88816bf45c89399efd61494d22
diff --git a/bp2build/configurability.go b/bp2build/configurability.go
index 050679b..95a2747 100644
--- a/bp2build/configurability.go
+++ b/bp2build/configurability.go
@@ -59,22 +59,30 @@
func prettyPrintAttribute(v bazel.Attribute, indent int) (string, error) {
var value reflect.Value
var archSelects, osSelects selects
+ var defaultSelectValue string
switch list := v.(type) {
case bazel.StringListAttribute:
value, archSelects, osSelects = getStringListValues(list)
+ defaultSelectValue = "[]"
case bazel.LabelListAttribute:
value, archSelects, osSelects = getLabelListValues(list)
+ defaultSelectValue = "[]"
case bazel.LabelAttribute:
value, archSelects, osSelects = getLabelValue(list)
+ defaultSelectValue = "None"
default:
return "", fmt.Errorf("Not a supported Bazel attribute type: %s", v)
}
- ret, err := prettyPrint(value, indent)
- if err != nil {
- return ret, err
- }
+ ret := ""
+ if value.Kind() != reflect.Invalid {
+ s, err := prettyPrint(value, indent)
+ if err != nil {
+ return ret, err
+ }
+ ret += s
+ }
// Convenience function to append selects components to an attribute value.
appendSelects := func(selectsData selects, defaultValue, s string) (string, error) {
selectMap, err := prettyPrintSelectMap(selectsData, defaultValue, indent)
@@ -89,12 +97,12 @@
return s, nil
}
- ret, err = appendSelects(archSelects, "[]", ret)
+ ret, err := appendSelects(archSelects, defaultSelectValue, ret)
if err != nil {
return "", err
}
- ret, err = appendSelects(osSelects, "[]", ret)
+ ret, err = appendSelects(osSelects, defaultSelectValue, ret)
return ret, err
}