LTO Bp2build

Bug: 261733821
Test: Unit Tests
Change-Id: I8c3721d35c464e296012145b2e95a7f0866aac37
This commit is contained in:
Trevor Radcliffe
2023-02-06 21:58:30 +00:00
parent 7720f5704c
commit 56b1a2b575
6 changed files with 636 additions and 0 deletions

View File

@@ -17,6 +17,7 @@ package bazel
import (
"fmt"
"path/filepath"
"reflect"
"regexp"
"sort"
"strings"
@@ -533,6 +534,37 @@ func (ba *BoolAttribute) ToLabelListAttribute(falseVal LabelList, trueVal LabelL
return result, nil
}
// ToStringListAttribute creates a StringListAttribute from this BoolAttribute,
// where each bool corresponds to a string list value generated by the provided
// function.
// TODO(b/271425661): Generalize this
func (ba *BoolAttribute) ToStringListAttribute(valueFunc func(boolPtr *bool, axis ConfigurationAxis, config string) []string) (StringListAttribute, error) {
mainVal := valueFunc(ba.Value, NoConfigAxis, "")
if !ba.HasConfigurableValues() {
return MakeStringListAttribute(mainVal), nil
}
result := StringListAttribute{}
if err := ba.Collapse(); err != nil {
return result, err
}
for axis, configToBools := range ba.ConfigurableValues {
if len(configToBools) < 1 {
continue
}
for config, boolPtr := range configToBools {
val := valueFunc(&boolPtr, axis, config)
if !reflect.DeepEqual(val, mainVal) {
result.SetSelectValue(axis, config, val)
}
}
result.SetSelectValue(axis, ConditionsDefaultConfigKey, mainVal)
}
return result, nil
}
// Collapse reduces the configurable axes of the boolean attribute to a single axis.
// This is necessary for final writing to bp2build, as a configurable boolean
// attribute can only be comprised by a single select.