2021-02-24 13:20:12 +01:00
|
|
|
package bp2build
|
|
|
|
|
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
|
|
|
import (
|
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/bazel"
|
|
|
|
"fmt"
|
|
|
|
"reflect"
|
|
|
|
)
|
2021-02-24 13:20:12 +01:00
|
|
|
|
|
|
|
// Configurability support for bp2build.
|
|
|
|
|
2021-04-05 12:35:13 +02:00
|
|
|
type selects map[string]reflect.Value
|
|
|
|
|
2021-05-06 19:54:29 +02:00
|
|
|
func getStringListValues(list bazel.StringListAttribute) (reflect.Value, []selects) {
|
2021-04-05 12:35:13 +02:00
|
|
|
value := reflect.ValueOf(list.Value)
|
|
|
|
if !list.HasConfigurableValues() {
|
2021-05-06 19:54:29 +02:00
|
|
|
return value, []selects{}
|
2021-04-05 12:35:13 +02:00
|
|
|
}
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
var ret []selects
|
|
|
|
for _, axis := range list.SortedConfigurationAxes() {
|
|
|
|
configToLists := list.ConfigurableValues[axis]
|
|
|
|
archSelects := map[string]reflect.Value{}
|
|
|
|
for config, labels := range configToLists {
|
|
|
|
selectKey := axis.SelectKey(config)
|
|
|
|
archSelects[selectKey] = reflect.ValueOf(labels)
|
2021-05-19 12:49:02 +02:00
|
|
|
}
|
2021-05-21 14:37:59 +02:00
|
|
|
if len(archSelects) > 0 {
|
|
|
|
ret = append(ret, archSelects)
|
2021-05-06 19:54:29 +02:00
|
|
|
}
|
|
|
|
}
|
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
return value, ret
|
2021-04-05 12:35:13 +02:00
|
|
|
}
|
|
|
|
|
2021-05-06 19:54:29 +02:00
|
|
|
func getLabelValue(label bazel.LabelAttribute) (reflect.Value, []selects) {
|
2021-05-27 08:15:54 +02:00
|
|
|
value := reflect.ValueOf(label.Value)
|
|
|
|
if !label.HasConfigurableValues() {
|
|
|
|
return value, []selects{}
|
|
|
|
}
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
ret := selects{}
|
|
|
|
for _, axis := range label.SortedConfigurationAxes() {
|
|
|
|
configToLabels := label.ConfigurableValues[axis]
|
|
|
|
for config, labels := range configToLabels {
|
|
|
|
selectKey := axis.SelectKey(config)
|
|
|
|
ret[selectKey] = reflect.ValueOf(labels)
|
2021-05-27 08:15:54 +02:00
|
|
|
}
|
|
|
|
}
|
2021-05-12 12:36:45 +02:00
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
return value, []selects{ret}
|
2021-04-30 15:35:09 +02:00
|
|
|
}
|
|
|
|
|
2021-06-03 19:43:01 +02:00
|
|
|
func getBoolValue(boolAttr bazel.BoolAttribute) (reflect.Value, []selects) {
|
|
|
|
value := reflect.ValueOf(boolAttr.Value)
|
|
|
|
if !boolAttr.HasConfigurableValues() {
|
|
|
|
return value, []selects{}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret := selects{}
|
|
|
|
for _, axis := range boolAttr.SortedConfigurationAxes() {
|
|
|
|
configToBools := boolAttr.ConfigurableValues[axis]
|
|
|
|
for config, bools := range configToBools {
|
|
|
|
selectKey := axis.SelectKey(config)
|
|
|
|
ret[selectKey] = reflect.ValueOf(bools)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// if there is a select, use the base value as the conditions default value
|
|
|
|
if len(ret) > 0 {
|
|
|
|
ret[bazel.ConditionsDefaultSelectKey] = value
|
|
|
|
value = reflect.Zero(value.Type())
|
|
|
|
}
|
|
|
|
|
|
|
|
return value, []selects{ret}
|
|
|
|
}
|
2021-05-06 19:54:29 +02:00
|
|
|
func getLabelListValues(list bazel.LabelListAttribute) (reflect.Value, []selects) {
|
2021-04-05 12:35:13 +02:00
|
|
|
value := reflect.ValueOf(list.Value.Includes)
|
2021-05-26 21:08:27 +02:00
|
|
|
var ret []selects
|
2021-05-21 14:37:59 +02:00
|
|
|
for _, axis := range list.SortedConfigurationAxes() {
|
|
|
|
configToLabels := list.ConfigurableValues[axis]
|
|
|
|
if !configToLabels.HasConfigurableValues() {
|
|
|
|
continue
|
2021-05-26 21:08:27 +02:00
|
|
|
}
|
2021-05-21 14:37:59 +02:00
|
|
|
archSelects := map[string]reflect.Value{}
|
|
|
|
for config, labels := range configToLabels {
|
|
|
|
selectKey := axis.SelectKey(config)
|
|
|
|
if use, value := labelListSelectValue(selectKey, labels); use {
|
|
|
|
archSelects[selectKey] = value
|
2021-05-26 21:08:27 +02:00
|
|
|
}
|
2021-05-19 12:49:02 +02:00
|
|
|
}
|
2021-05-21 14:37:59 +02:00
|
|
|
if len(archSelects) > 0 {
|
|
|
|
ret = append(ret, archSelects)
|
2021-05-26 21:08:27 +02:00
|
|
|
}
|
|
|
|
}
|
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
|
|
|
|
2021-05-26 21:08:27 +02:00
|
|
|
return value, ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func labelListSelectValue(selectKey string, list bazel.LabelList) (bool, reflect.Value) {
|
|
|
|
if selectKey == bazel.ConditionsDefaultSelectKey || len(list.Includes) > 0 {
|
|
|
|
return true, reflect.ValueOf(list.Includes)
|
|
|
|
} else if len(list.Excludes) > 0 {
|
|
|
|
// if there is still an excludes -- we need to have an empty list for this select & use the
|
|
|
|
// value in conditions default Includes
|
|
|
|
return true, reflect.ValueOf([]string{})
|
|
|
|
}
|
|
|
|
return false, reflect.Zero(reflect.TypeOf([]string{}))
|
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
|
|
|
}
|
|
|
|
|
2021-06-03 19:43:01 +02:00
|
|
|
var (
|
|
|
|
emptyBazelList = "[]"
|
|
|
|
bazelNone = "None"
|
|
|
|
)
|
|
|
|
|
2021-04-05 12:35:13 +02:00
|
|
|
// prettyPrintAttribute converts an Attribute to its Bazel syntax. May contain
|
|
|
|
// select statements.
|
|
|
|
func prettyPrintAttribute(v bazel.Attribute, indent int) (string, error) {
|
|
|
|
var value reflect.Value
|
2021-05-06 19:54:29 +02:00
|
|
|
var configurableAttrs []selects
|
2021-06-03 19:43:01 +02:00
|
|
|
var defaultSelectValue *string
|
2021-04-05 12:35:13 +02:00
|
|
|
switch list := v.(type) {
|
|
|
|
case bazel.StringListAttribute:
|
2021-05-06 19:54:29 +02:00
|
|
|
value, configurableAttrs = getStringListValues(list)
|
2021-06-03 19:43:01 +02:00
|
|
|
defaultSelectValue = &emptyBazelList
|
2021-04-05 12:35:13 +02:00
|
|
|
case bazel.LabelListAttribute:
|
2021-05-06 19:54:29 +02:00
|
|
|
value, configurableAttrs = getLabelListValues(list)
|
2021-06-03 19:43:01 +02:00
|
|
|
defaultSelectValue = &emptyBazelList
|
2021-04-30 15:35:09 +02:00
|
|
|
case bazel.LabelAttribute:
|
2021-05-06 19:54:29 +02:00
|
|
|
value, configurableAttrs = getLabelValue(list)
|
2021-06-03 19:43:01 +02:00
|
|
|
defaultSelectValue = &bazelNone
|
|
|
|
case bazel.BoolAttribute:
|
|
|
|
value, configurableAttrs = getBoolValue(list)
|
|
|
|
defaultSelectValue = &bazelNone
|
2021-04-05 12:35:13 +02:00
|
|
|
default:
|
|
|
|
return "", fmt.Errorf("Not a supported Bazel attribute type: %s", v)
|
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
|
|
|
}
|
|
|
|
|
2021-05-06 19:54:29 +02:00
|
|
|
var err error
|
2021-05-05 09:00:01 +02:00
|
|
|
ret := ""
|
|
|
|
if value.Kind() != reflect.Invalid {
|
|
|
|
s, err := prettyPrint(value, indent)
|
|
|
|
if err != nil {
|
|
|
|
return ret, err
|
|
|
|
}
|
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
|
|
|
|
2021-05-05 09:00:01 +02:00
|
|
|
ret += s
|
|
|
|
}
|
2021-03-24 15:04:33 +01:00
|
|
|
// Convenience function to append selects components to an attribute value.
|
2021-06-03 19:43:01 +02:00
|
|
|
appendSelects := func(selectsData selects, defaultValue *string, s string) (string, error) {
|
2021-03-24 15:04:33 +01:00
|
|
|
selectMap, err := prettyPrintSelectMap(selectsData, defaultValue, indent)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
if s != "" && selectMap != "" {
|
|
|
|
s += " + "
|
|
|
|
}
|
|
|
|
s += selectMap
|
|
|
|
|
|
|
|
return s, nil
|
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
|
|
|
}
|
|
|
|
|
2021-05-06 19:54:29 +02:00
|
|
|
for _, configurableAttr := range configurableAttrs {
|
|
|
|
ret, err = appendSelects(configurableAttr, defaultSelectValue, ret)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2021-04-05 12:35:13 +02:00
|
|
|
}
|
|
|
|
|
2021-05-06 19:54:29 +02:00
|
|
|
return ret, nil
|
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// prettyPrintSelectMap converts a map of select keys to reflected Values as a generic way
|
|
|
|
// to construct a select map for any kind of attribute type.
|
2021-06-03 19:43:01 +02:00
|
|
|
func prettyPrintSelectMap(selectMap map[string]reflect.Value, defaultValue *string, indent int) (string, error) {
|
2021-04-05 12:35:13 +02:00
|
|
|
if selectMap == nil {
|
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
|
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
|
|
|
var selects string
|
|
|
|
for _, selectKey := range android.SortedStringKeys(selectMap) {
|
2021-05-06 19:54:29 +02:00
|
|
|
if selectKey == bazel.ConditionsDefaultSelectKey {
|
2021-04-23 11:17:24 +02:00
|
|
|
// Handle default condition later.
|
|
|
|
continue
|
|
|
|
}
|
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
|
|
|
value := selectMap[selectKey]
|
|
|
|
if isZero(value) {
|
|
|
|
// Ignore zero values to not generate empty lists.
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
s, err := prettyPrintSelectEntry(value, selectKey, indent)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2021-04-13 09:14:55 +02:00
|
|
|
// s could still be an empty string, e.g. unset slices of structs with
|
|
|
|
// length of 0.
|
|
|
|
if s != "" {
|
|
|
|
selects += s + ",\n"
|
|
|
|
}
|
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(selects) == 0 {
|
|
|
|
// No conditions (or all values are empty lists), so no need for a map.
|
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the map.
|
2021-03-24 15:04:33 +01:00
|
|
|
ret := "select({\n"
|
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
|
|
|
ret += selects
|
2021-04-23 11:17:24 +02:00
|
|
|
|
|
|
|
// Handle the default condition
|
2021-05-06 19:54:29 +02:00
|
|
|
s, err := prettyPrintSelectEntry(selectMap[bazel.ConditionsDefaultSelectKey], bazel.ConditionsDefaultSelectKey, indent)
|
2021-04-23 11:17:24 +02:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2021-06-03 19:43:01 +02:00
|
|
|
if s != "" {
|
2021-04-23 11:17:24 +02:00
|
|
|
// Print the custom default value.
|
|
|
|
ret += s
|
|
|
|
ret += ",\n"
|
2021-06-03 19:43:01 +02:00
|
|
|
} else if defaultValue != nil {
|
|
|
|
// Print an explicit empty list (the default value) even if the value is
|
|
|
|
// empty, to avoid errors about not finding a configuration that matches.
|
|
|
|
ret += fmt.Sprintf("%s\"%s\": %s,\n", makeIndent(indent+1), bazel.ConditionsDefaultSelectKey, *defaultValue)
|
2021-04-23 11:17:24 +02:00
|
|
|
}
|
|
|
|
|
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
|
|
|
ret += makeIndent(indent)
|
|
|
|
ret += "})"
|
|
|
|
|
|
|
|
return ret, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// prettyPrintSelectEntry converts a reflect.Value into an entry in a select map
|
|
|
|
// with a provided key.
|
|
|
|
func prettyPrintSelectEntry(value reflect.Value, key string, indent int) (string, error) {
|
|
|
|
s := makeIndent(indent + 1)
|
|
|
|
v, err := prettyPrint(value, indent+1)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2021-04-13 09:14:55 +02:00
|
|
|
if v == "" {
|
|
|
|
return "", nil
|
|
|
|
}
|
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
|
|
|
s += fmt.Sprintf("\"%s\": %s", key, v)
|
|
|
|
return s, nil
|
|
|
|
}
|