Make bp2build-generated selects() based on product config build settings
...instead of based on constraint settings. Bug: 269577299 Test: m nothing and ./build/bazel/ci/bp2build.sh Change-Id: Ib9caec79c92b8fd304e46be841de5612bd1637e3
This commit is contained in:
@@ -16,6 +16,7 @@ package starlark_fmt
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -33,6 +34,72 @@ func Indention(level int) string {
|
||||
return strings.Repeat(" ", level*indent)
|
||||
}
|
||||
|
||||
func PrintAny(value any, indentLevel int) string {
|
||||
return printAnyRecursive(reflect.ValueOf(value), indentLevel)
|
||||
}
|
||||
|
||||
func printAnyRecursive(value reflect.Value, indentLevel int) string {
|
||||
switch value.Type().Kind() {
|
||||
case reflect.String:
|
||||
val := value.String()
|
||||
if strings.Contains(val, "\"") || strings.Contains(val, "\n") {
|
||||
return `'''` + val + `'''`
|
||||
}
|
||||
return `"` + val + `"`
|
||||
case reflect.Bool:
|
||||
if value.Bool() {
|
||||
return "True"
|
||||
} else {
|
||||
return "False"
|
||||
}
|
||||
case reflect.Int:
|
||||
return fmt.Sprintf("%d", value.Int())
|
||||
case reflect.Slice:
|
||||
if value.Len() == 0 {
|
||||
return "[]"
|
||||
} else if value.Len() == 1 {
|
||||
return "[" + printAnyRecursive(value.Index(0), indentLevel) + "]"
|
||||
}
|
||||
list := make([]string, 0, value.Len()+2)
|
||||
list = append(list, "[")
|
||||
innerIndent := Indention(indentLevel + 1)
|
||||
for i := 0; i < value.Len(); i++ {
|
||||
list = append(list, innerIndent+printAnyRecursive(value.Index(i), indentLevel+1)+`,`)
|
||||
}
|
||||
list = append(list, Indention(indentLevel)+"]")
|
||||
return strings.Join(list, "\n")
|
||||
case reflect.Map:
|
||||
if value.Len() == 0 {
|
||||
return "{}"
|
||||
}
|
||||
items := make([]string, 0, value.Len())
|
||||
for _, key := range value.MapKeys() {
|
||||
items = append(items, fmt.Sprintf(`%s%s: %s,`, Indention(indentLevel+1), printAnyRecursive(key, indentLevel+1), printAnyRecursive(value.MapIndex(key), indentLevel+1)))
|
||||
}
|
||||
sort.Strings(items)
|
||||
return fmt.Sprintf(`{
|
||||
%s
|
||||
%s}`, strings.Join(items, "\n"), Indention(indentLevel))
|
||||
case reflect.Struct:
|
||||
if value.NumField() == 0 {
|
||||
return "struct()"
|
||||
}
|
||||
items := make([]string, 0, value.NumField()+2)
|
||||
items = append(items, "struct(")
|
||||
for i := 0; i < value.NumField(); i++ {
|
||||
if value.Type().Field(i).Anonymous {
|
||||
panic("anonymous fields aren't supported")
|
||||
}
|
||||
name := value.Type().Field(i).Name
|
||||
items = append(items, fmt.Sprintf(`%s%s = %s,`, Indention(indentLevel+1), name, printAnyRecursive(value.Field(i), indentLevel+1)))
|
||||
}
|
||||
items = append(items, Indention(indentLevel)+")")
|
||||
return strings.Join(items, "\n")
|
||||
default:
|
||||
panic("Unhandled kind: " + value.Kind().String())
|
||||
}
|
||||
}
|
||||
|
||||
// PrintBool returns a Starlark compatible bool string.
|
||||
func PrintBool(item bool) string {
|
||||
if item {
|
||||
|
Reference in New Issue
Block a user