2020-11-19 11:38:02 +01:00
|
|
|
// Copyright 2020 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package bazel
|
|
|
|
|
2021-03-12 12:04:21 +01:00
|
|
|
import (
|
|
|
|
"fmt"
|
2021-03-24 15:04:33 +01:00
|
|
|
"path/filepath"
|
2021-03-24 15:14:47 +01:00
|
|
|
"regexp"
|
2021-03-12 12:04:21 +01:00
|
|
|
"sort"
|
2021-06-17 07:43:19 +02:00
|
|
|
"strings"
|
2021-03-12 12:04:21 +01:00
|
|
|
)
|
2021-02-24 13:20:12 +01:00
|
|
|
|
2020-12-14 14:25:34 +01:00
|
|
|
// BazelTargetModuleProperties contain properties and metadata used for
|
|
|
|
// Blueprint to BUILD file conversion.
|
|
|
|
type BazelTargetModuleProperties struct {
|
|
|
|
// The Bazel rule class for this target.
|
2021-02-19 17:06:17 +01:00
|
|
|
Rule_class string `blueprint:"mutated"`
|
2021-01-27 03:58:43 +01:00
|
|
|
|
|
|
|
// The target label for the bzl file containing the definition of the rule class.
|
2021-02-19 17:06:17 +01:00
|
|
|
Bzl_load_location string `blueprint:"mutated"`
|
2020-12-14 14:25:34 +01:00
|
|
|
}
|
2021-01-26 15:18:53 +01:00
|
|
|
|
2021-02-07 16:05:16 +01:00
|
|
|
const BazelTargetModuleNamePrefix = "__bp2build__"
|
|
|
|
|
2021-06-17 07:43:19 +02:00
|
|
|
func StripNamePrefix(moduleName string) string {
|
|
|
|
return strings.TrimPrefix(moduleName, BazelTargetModuleNamePrefix)
|
|
|
|
}
|
|
|
|
|
2021-03-24 15:14:47 +01:00
|
|
|
var productVariableSubstitutionPattern = regexp.MustCompile("%(d|s)")
|
|
|
|
|
2021-04-19 07:00:15 +02:00
|
|
|
// Label is used to represent a Bazel compatible Label. Also stores the original
|
|
|
|
// bp text to support string replacement.
|
2021-01-26 15:18:53 +01:00
|
|
|
type Label struct {
|
2021-04-19 07:00:15 +02:00
|
|
|
// The string representation of a Bazel target label. This can be a relative
|
|
|
|
// or fully qualified label. These labels are used for generating BUILD
|
|
|
|
// files with bp2build.
|
|
|
|
Label string
|
|
|
|
|
|
|
|
// The original Soong/Blueprint module name that the label was derived from.
|
|
|
|
// This is used for replacing references to the original name with the new
|
|
|
|
// label, for example in genrule cmds.
|
|
|
|
//
|
|
|
|
// While there is a reversible 1:1 mapping from the module name to Bazel
|
|
|
|
// label with bp2build that could make computing the original module name
|
|
|
|
// from the label automatic, it is not the case for handcrafted targets,
|
|
|
|
// where modules can have a custom label mapping through the { bazel_module:
|
|
|
|
// { label: <label> } } property.
|
|
|
|
//
|
|
|
|
// With handcrafted labels, those modules don't go through bp2build
|
|
|
|
// conversion, but relies on handcrafted targets in the source tree.
|
|
|
|
OriginalModuleName string
|
2021-01-26 15:18:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// LabelList is used to represent a list of Bazel labels.
|
|
|
|
type LabelList struct {
|
|
|
|
Includes []Label
|
|
|
|
Excludes []Label
|
|
|
|
}
|
|
|
|
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
func (ll *LabelList) Equals(other LabelList) bool {
|
|
|
|
if len(ll.Includes) != len(other.Includes) || len(ll.Excludes) != len(other.Excludes) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
for i, _ := range ll.Includes {
|
|
|
|
if ll.Includes[i] != other.Includes[i] {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for i, _ := range ll.Excludes {
|
|
|
|
if ll.Excludes[i] != other.Excludes[i] {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
func (ll *LabelList) IsNil() bool {
|
|
|
|
return ll.Includes == nil && ll.Excludes == nil
|
|
|
|
}
|
|
|
|
|
2021-06-02 19:02:03 +02:00
|
|
|
func (ll *LabelList) deepCopy() LabelList {
|
|
|
|
return LabelList{
|
|
|
|
Includes: ll.Includes[:],
|
|
|
|
Excludes: ll.Excludes[:],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-24 15:04:33 +01:00
|
|
|
// uniqueParentDirectories returns a list of the unique parent directories for
|
|
|
|
// all files in ll.Includes.
|
|
|
|
func (ll *LabelList) uniqueParentDirectories() []string {
|
|
|
|
dirMap := map[string]bool{}
|
|
|
|
for _, label := range ll.Includes {
|
|
|
|
dirMap[filepath.Dir(label.Label)] = true
|
|
|
|
}
|
|
|
|
dirs := []string{}
|
|
|
|
for dir := range dirMap {
|
|
|
|
dirs = append(dirs, dir)
|
|
|
|
}
|
|
|
|
return dirs
|
|
|
|
}
|
|
|
|
|
2021-01-26 15:18:53 +01:00
|
|
|
// Append appends the fields of other labelList to the corresponding fields of ll.
|
|
|
|
func (ll *LabelList) Append(other LabelList) {
|
|
|
|
if len(ll.Includes) > 0 || len(other.Includes) > 0 {
|
|
|
|
ll.Includes = append(ll.Includes, other.Includes...)
|
|
|
|
}
|
|
|
|
if len(ll.Excludes) > 0 || len(other.Excludes) > 0 {
|
|
|
|
ll.Excludes = append(other.Excludes, other.Excludes...)
|
|
|
|
}
|
|
|
|
}
|
2021-02-24 13:20:12 +01:00
|
|
|
|
2021-04-13 09:14:55 +02:00
|
|
|
// UniqueSortedBazelLabels takes a []Label and deduplicates the labels, and returns
|
|
|
|
// the slice in a sorted order.
|
|
|
|
func UniqueSortedBazelLabels(originalLabels []Label) []Label {
|
2021-03-12 12:04:21 +01:00
|
|
|
uniqueLabelsSet := make(map[Label]bool)
|
|
|
|
for _, l := range originalLabels {
|
|
|
|
uniqueLabelsSet[l] = true
|
|
|
|
}
|
|
|
|
var uniqueLabels []Label
|
|
|
|
for l, _ := range uniqueLabelsSet {
|
|
|
|
uniqueLabels = append(uniqueLabels, l)
|
|
|
|
}
|
|
|
|
sort.SliceStable(uniqueLabels, func(i, j int) bool {
|
|
|
|
return uniqueLabels[i].Label < uniqueLabels[j].Label
|
|
|
|
})
|
|
|
|
return uniqueLabels
|
|
|
|
}
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
func FirstUniqueBazelLabels(originalLabels []Label) []Label {
|
|
|
|
var labels []Label
|
|
|
|
found := make(map[Label]bool, len(originalLabels))
|
|
|
|
for _, l := range originalLabels {
|
|
|
|
if _, ok := found[l]; ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
labels = append(labels, l)
|
|
|
|
found[l] = true
|
|
|
|
}
|
|
|
|
return labels
|
|
|
|
}
|
|
|
|
|
|
|
|
func FirstUniqueBazelLabelList(originalLabelList LabelList) LabelList {
|
|
|
|
var uniqueLabelList LabelList
|
|
|
|
uniqueLabelList.Includes = FirstUniqueBazelLabels(originalLabelList.Includes)
|
|
|
|
uniqueLabelList.Excludes = FirstUniqueBazelLabels(originalLabelList.Excludes)
|
|
|
|
return uniqueLabelList
|
|
|
|
}
|
|
|
|
|
|
|
|
func UniqueSortedBazelLabelList(originalLabelList LabelList) LabelList {
|
2021-03-12 12:04:21 +01:00
|
|
|
var uniqueLabelList LabelList
|
2021-04-13 09:14:55 +02:00
|
|
|
uniqueLabelList.Includes = UniqueSortedBazelLabels(originalLabelList.Includes)
|
|
|
|
uniqueLabelList.Excludes = UniqueSortedBazelLabels(originalLabelList.Excludes)
|
2021-03-12 12:04:21 +01:00
|
|
|
return uniqueLabelList
|
|
|
|
}
|
|
|
|
|
2021-04-06 22:06:21 +02:00
|
|
|
// Subtract needle from haystack
|
|
|
|
func SubtractStrings(haystack []string, needle []string) []string {
|
|
|
|
// This is really a set
|
|
|
|
remainder := make(map[string]bool)
|
|
|
|
|
|
|
|
for _, s := range haystack {
|
|
|
|
remainder[s] = true
|
|
|
|
}
|
|
|
|
for _, s := range needle {
|
|
|
|
delete(remainder, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
var strings []string
|
|
|
|
for s, _ := range remainder {
|
|
|
|
strings = append(strings, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.SliceStable(strings, func(i, j int) bool {
|
|
|
|
return strings[i] < strings[j]
|
|
|
|
})
|
|
|
|
|
|
|
|
return strings
|
|
|
|
}
|
|
|
|
|
2021-06-02 13:10:02 +02:00
|
|
|
// Map a function over all labels in a LabelList.
|
|
|
|
func MapLabelList(mapOver LabelList, mapFn func(string) string) LabelList {
|
|
|
|
var includes []Label
|
|
|
|
for _, inc := range mapOver.Includes {
|
|
|
|
mappedLabel := Label{Label: mapFn(inc.Label), OriginalModuleName: inc.OriginalModuleName}
|
|
|
|
includes = append(includes, mappedLabel)
|
|
|
|
}
|
|
|
|
// mapFn is not applied over excludes, but they are propagated as-is.
|
|
|
|
return LabelList{Includes: includes, Excludes: mapOver.Excludes}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Map a function over all Labels in a LabelListAttribute
|
|
|
|
func MapLabelListAttribute(mapOver LabelListAttribute, mapFn func(string) string) LabelListAttribute {
|
|
|
|
var result LabelListAttribute
|
|
|
|
|
|
|
|
result.Value = MapLabelList(mapOver.Value, mapFn)
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
for axis, configToLabels := range mapOver.ConfigurableValues {
|
|
|
|
for config, value := range configToLabels {
|
|
|
|
result.SetSelectValue(axis, config, MapLabelList(value, mapFn))
|
2021-06-02 13:10:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2021-05-25 18:10:58 +02:00
|
|
|
// Return all needles in a given haystack, where needleFn is true for needles.
|
|
|
|
func FilterLabelList(haystack LabelList, needleFn func(string) bool) LabelList {
|
|
|
|
var includes []Label
|
|
|
|
for _, inc := range haystack.Includes {
|
|
|
|
if needleFn(inc.Label) {
|
|
|
|
includes = append(includes, inc)
|
|
|
|
}
|
|
|
|
}
|
2021-06-02 13:10:02 +02:00
|
|
|
// needleFn is not applied over excludes, but they are propagated as-is.
|
2021-05-25 18:10:58 +02:00
|
|
|
return LabelList{Includes: includes, Excludes: haystack.Excludes}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return all needles in a given haystack, where needleFn is true for needles.
|
|
|
|
func FilterLabelListAttribute(haystack LabelListAttribute, needleFn func(string) bool) LabelListAttribute {
|
2021-05-21 14:37:59 +02:00
|
|
|
result := MakeLabelListAttribute(FilterLabelList(haystack.Value, needleFn))
|
2021-05-25 18:10:58 +02:00
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
for config, selects := range haystack.ConfigurableValues {
|
|
|
|
newSelects := make(labelListSelectValues, len(selects))
|
|
|
|
for k, v := range selects {
|
|
|
|
newSelects[k] = FilterLabelList(v, needleFn)
|
2021-05-19 12:49:02 +02:00
|
|
|
}
|
2021-05-21 14:37:59 +02:00
|
|
|
result.ConfigurableValues[config] = newSelects
|
2021-05-25 18:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
// Subtract needle from haystack
|
|
|
|
func SubtractBazelLabelListAttribute(haystack LabelListAttribute, needle LabelListAttribute) LabelListAttribute {
|
2021-05-21 14:37:59 +02:00
|
|
|
result := MakeLabelListAttribute(SubtractBazelLabelList(haystack.Value, needle.Value))
|
2021-05-25 18:10:58 +02:00
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
for config, selects := range haystack.ConfigurableValues {
|
|
|
|
newSelects := make(labelListSelectValues, len(selects))
|
|
|
|
needleSelects := needle.ConfigurableValues[config]
|
2021-05-25 18:10:58 +02:00
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
for k, v := range selects {
|
|
|
|
newSelects[k] = SubtractBazelLabelList(v, needleSelects[k])
|
2021-05-19 12:49:02 +02:00
|
|
|
}
|
2021-05-21 14:37:59 +02:00
|
|
|
result.ConfigurableValues[config] = newSelects
|
2021-05-25 18:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2021-04-06 22:06:21 +02:00
|
|
|
// Subtract needle from haystack
|
|
|
|
func SubtractBazelLabels(haystack []Label, needle []Label) []Label {
|
|
|
|
// This is really a set
|
|
|
|
remainder := make(map[Label]bool)
|
|
|
|
|
|
|
|
for _, label := range haystack {
|
|
|
|
remainder[label] = true
|
|
|
|
}
|
|
|
|
for _, label := range needle {
|
|
|
|
delete(remainder, label)
|
|
|
|
}
|
|
|
|
|
|
|
|
var labels []Label
|
|
|
|
for label, _ := range remainder {
|
|
|
|
labels = append(labels, label)
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.SliceStable(labels, func(i, j int) bool {
|
|
|
|
return labels[i].Label < labels[j].Label
|
|
|
|
})
|
|
|
|
|
|
|
|
return labels
|
|
|
|
}
|
|
|
|
|
2021-05-13 21:13:04 +02:00
|
|
|
// Appends two LabelLists, returning the combined list.
|
|
|
|
func AppendBazelLabelLists(a LabelList, b LabelList) LabelList {
|
|
|
|
var result LabelList
|
|
|
|
result.Includes = append(a.Includes, b.Includes...)
|
|
|
|
result.Excludes = append(a.Excludes, b.Excludes...)
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2021-04-06 22:06:21 +02:00
|
|
|
// Subtract needle from haystack
|
|
|
|
func SubtractBazelLabelList(haystack LabelList, needle LabelList) LabelList {
|
|
|
|
var result LabelList
|
|
|
|
result.Includes = SubtractBazelLabels(haystack.Includes, needle.Includes)
|
|
|
|
// NOTE: Excludes are intentionally not subtracted
|
|
|
|
result.Excludes = haystack.Excludes
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2021-04-05 12:35:13 +02:00
|
|
|
type Attribute interface {
|
|
|
|
HasConfigurableValues() bool
|
|
|
|
}
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
type labelSelectValues map[string]*Label
|
2021-05-27 08:15:54 +02:00
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
type configurableLabels map[ConfigurationAxis]labelSelectValues
|
2021-05-27 08:15:54 +02:00
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
func (cl configurableLabels) setValueForAxis(axis ConfigurationAxis, config string, value *Label) {
|
|
|
|
if cl[axis] == nil {
|
|
|
|
cl[axis] = make(labelSelectValues)
|
|
|
|
}
|
|
|
|
cl[axis][config] = value
|
2021-05-27 08:15:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Represents an attribute whose value is a single label
|
|
|
|
type LabelAttribute struct {
|
2021-05-21 14:37:59 +02:00
|
|
|
Value *Label
|
2021-05-27 08:15:54 +02:00
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
ConfigurableValues configurableLabels
|
2021-04-30 15:35:09 +02:00
|
|
|
}
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
// HasConfigurableValues returns whether there are configurable values set for this label.
|
|
|
|
func (la LabelAttribute) HasConfigurableValues() bool {
|
|
|
|
return len(la.ConfigurableValues) > 0
|
2021-05-27 08:15:54 +02:00
|
|
|
}
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
// SetValue sets the base, non-configured value for the Label
|
|
|
|
func (la *LabelAttribute) SetValue(value Label) {
|
|
|
|
la.SetSelectValue(NoConfigAxis, "", value)
|
2021-05-27 08:15:54 +02:00
|
|
|
}
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
// SetSelectValue set a value for a bazel select for the given axis, config and value.
|
|
|
|
func (la *LabelAttribute) SetSelectValue(axis ConfigurationAxis, config string, value Label) {
|
|
|
|
axis.validateConfig(config)
|
|
|
|
switch axis.configurationType {
|
|
|
|
case noConfig:
|
|
|
|
la.Value = &value
|
2021-07-16 22:33:47 +02:00
|
|
|
case arch, os, osArch, bionic, productVariables:
|
2021-05-21 14:37:59 +02:00
|
|
|
if la.ConfigurableValues == nil {
|
|
|
|
la.ConfigurableValues = make(configurableLabels)
|
2021-05-27 08:15:54 +02:00
|
|
|
}
|
2021-05-21 14:37:59 +02:00
|
|
|
la.ConfigurableValues.setValueForAxis(axis, config, &value)
|
2021-05-05 09:00:01 +02:00
|
|
|
default:
|
2021-05-21 14:37:59 +02:00
|
|
|
panic(fmt.Errorf("Unrecognized ConfigurationAxis %s", axis))
|
2021-05-05 09:00:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
// SelectValue gets a value for a bazel select for the given axis and config.
|
|
|
|
func (la *LabelAttribute) SelectValue(axis ConfigurationAxis, config string) Label {
|
|
|
|
axis.validateConfig(config)
|
|
|
|
switch axis.configurationType {
|
|
|
|
case noConfig:
|
|
|
|
return *la.Value
|
2021-07-16 22:33:47 +02:00
|
|
|
case arch, os, osArch, bionic, productVariables:
|
2021-05-21 14:37:59 +02:00
|
|
|
return *la.ConfigurableValues[axis][config]
|
2021-05-05 09:00:01 +02:00
|
|
|
default:
|
2021-05-21 14:37:59 +02:00
|
|
|
panic(fmt.Errorf("Unrecognized ConfigurationAxis %s", axis))
|
2021-05-05 09:00:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
// SortedConfigurationAxes returns all the used ConfigurationAxis in sorted order.
|
|
|
|
func (la *LabelAttribute) SortedConfigurationAxes() []ConfigurationAxis {
|
|
|
|
keys := make([]ConfigurationAxis, 0, len(la.ConfigurableValues))
|
|
|
|
for k := range la.ConfigurableValues {
|
|
|
|
keys = append(keys, k)
|
2021-05-27 08:15:54 +02:00
|
|
|
}
|
2021-04-23 11:17:24 +02:00
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
sort.Slice(keys, func(i, j int) bool { return keys[i].less(keys[j]) })
|
|
|
|
return keys
|
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
|
|
|
type configToBools map[string]bool
|
|
|
|
|
|
|
|
func (ctb configToBools) setValue(config string, value *bool) {
|
|
|
|
if value == nil {
|
|
|
|
if _, ok := ctb[config]; ok {
|
|
|
|
delete(ctb, config)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ctb[config] = *value
|
|
|
|
}
|
|
|
|
|
|
|
|
type configurableBools map[ConfigurationAxis]configToBools
|
|
|
|
|
|
|
|
func (cb configurableBools) setValueForAxis(axis ConfigurationAxis, config string, value *bool) {
|
|
|
|
if cb[axis] == nil {
|
|
|
|
cb[axis] = make(configToBools)
|
|
|
|
}
|
|
|
|
cb[axis].setValue(config, value)
|
|
|
|
}
|
|
|
|
|
|
|
|
// BoolAttribute represents an attribute whose value is a single bool but may be configurable..
|
|
|
|
type BoolAttribute struct {
|
|
|
|
Value *bool
|
|
|
|
|
|
|
|
ConfigurableValues configurableBools
|
|
|
|
}
|
|
|
|
|
|
|
|
// HasConfigurableValues returns whether there are configurable values for this attribute.
|
|
|
|
func (ba BoolAttribute) HasConfigurableValues() bool {
|
|
|
|
return len(ba.ConfigurableValues) > 0
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetSelectValue sets value for the given axis/config.
|
|
|
|
func (ba *BoolAttribute) SetSelectValue(axis ConfigurationAxis, config string, value *bool) {
|
|
|
|
axis.validateConfig(config)
|
|
|
|
switch axis.configurationType {
|
|
|
|
case noConfig:
|
|
|
|
ba.Value = value
|
2021-07-16 22:33:47 +02:00
|
|
|
case arch, os, osArch, bionic, productVariables:
|
2021-06-03 19:43:01 +02:00
|
|
|
if ba.ConfigurableValues == nil {
|
|
|
|
ba.ConfigurableValues = make(configurableBools)
|
|
|
|
}
|
|
|
|
ba.ConfigurableValues.setValueForAxis(axis, config, value)
|
|
|
|
default:
|
|
|
|
panic(fmt.Errorf("Unrecognized ConfigurationAxis %s", axis))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SelectValue gets the value for the given axis/config.
|
|
|
|
func (ba BoolAttribute) SelectValue(axis ConfigurationAxis, config string) *bool {
|
|
|
|
axis.validateConfig(config)
|
|
|
|
switch axis.configurationType {
|
|
|
|
case noConfig:
|
|
|
|
return ba.Value
|
2021-07-16 22:33:47 +02:00
|
|
|
case arch, os, osArch, bionic, productVariables:
|
2021-06-03 19:43:01 +02:00
|
|
|
if v, ok := ba.ConfigurableValues[axis][config]; ok {
|
|
|
|
return &v
|
|
|
|
} else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
panic(fmt.Errorf("Unrecognized ConfigurationAxis %s", axis))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SortedConfigurationAxes returns all the used ConfigurationAxis in sorted order.
|
|
|
|
func (ba *BoolAttribute) SortedConfigurationAxes() []ConfigurationAxis {
|
|
|
|
keys := make([]ConfigurationAxis, 0, len(ba.ConfigurableValues))
|
|
|
|
for k := range ba.ConfigurableValues {
|
|
|
|
keys = append(keys, k)
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Slice(keys, func(i, j int) bool { return keys[i].less(keys[j]) })
|
|
|
|
return keys
|
|
|
|
}
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
// labelListSelectValues supports config-specific label_list typed Bazel attribute values.
|
|
|
|
type labelListSelectValues map[string]LabelList
|
2021-04-23 11:17:24 +02:00
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
func (ll labelListSelectValues) appendSelects(other labelListSelectValues) {
|
|
|
|
for k, v := range other {
|
|
|
|
l := ll[k]
|
|
|
|
(&l).Append(v)
|
|
|
|
ll[k] = l
|
|
|
|
}
|
2021-05-19 12:49:02 +02:00
|
|
|
}
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
// HasConfigurableValues returns whether there are configurable values within this set of selects.
|
|
|
|
func (ll labelListSelectValues) HasConfigurableValues() bool {
|
|
|
|
for _, v := range ll {
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
if v.Includes != nil {
|
2021-05-21 14:37:59 +02:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
2021-03-15 11:02:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// LabelListAttribute is used to represent a list of Bazel labels as an
|
|
|
|
// attribute.
|
|
|
|
type LabelListAttribute struct {
|
2021-05-21 14:37:59 +02:00
|
|
|
// The non-configured attribute label list Value. Required.
|
2021-03-15 11:02:43 +01:00
|
|
|
Value LabelList
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
// The configured attribute label list Values. Optional
|
|
|
|
// a map of independent configurability axes
|
|
|
|
ConfigurableValues configurableLabelLists
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
|
|
|
|
// If true, differentiate between "nil" and "empty" list. nil means that
|
|
|
|
// this attribute should not be specified at all, and "empty" means that
|
|
|
|
// the attribute should be explicitly specified as an empty list.
|
|
|
|
// This mode facilitates use of attribute defaults: an empty list should
|
|
|
|
// override the default.
|
|
|
|
ForceSpecifyEmptyList bool
|
2021-03-24 15:04:33 +01:00
|
|
|
}
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
type configurableLabelLists map[ConfigurationAxis]labelListSelectValues
|
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
|
|
|
func (cll configurableLabelLists) setValueForAxis(axis ConfigurationAxis, config string, list LabelList) {
|
|
|
|
if list.IsNil() {
|
|
|
|
if _, ok := cll[axis][config]; ok {
|
|
|
|
delete(cll[axis], config)
|
2021-05-19 12:49:02 +02:00
|
|
|
}
|
2021-05-21 14:37:59 +02:00
|
|
|
return
|
2021-03-15 11:02:43 +01:00
|
|
|
}
|
2021-05-21 14:37:59 +02:00
|
|
|
if cll[axis] == nil {
|
|
|
|
cll[axis] = make(labelListSelectValues)
|
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
|
|
|
cll[axis][config] = list
|
2021-03-15 11:02:43 +01:00
|
|
|
}
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
func (cll configurableLabelLists) Append(other configurableLabelLists) {
|
|
|
|
for axis, otherSelects := range other {
|
|
|
|
selects := cll[axis]
|
|
|
|
if selects == nil {
|
|
|
|
selects = make(labelListSelectValues, len(otherSelects))
|
|
|
|
}
|
|
|
|
selects.appendSelects(otherSelects)
|
|
|
|
cll[axis] = selects
|
2021-03-15 11:02:43 +01: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
|
|
|
// MakeLabelListAttribute initializes a LabelListAttribute with the non-arch specific value.
|
|
|
|
func MakeLabelListAttribute(value LabelList) LabelListAttribute {
|
|
|
|
return LabelListAttribute{
|
|
|
|
Value: value,
|
|
|
|
ConfigurableValues: make(configurableLabelLists),
|
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
|
|
|
func (lla *LabelListAttribute) SetValue(list LabelList) {
|
|
|
|
lla.SetSelectValue(NoConfigAxis, "", list)
|
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
|
|
|
// SetSelectValue set a value for a bazel select for the given axis, config and value.
|
|
|
|
func (lla *LabelListAttribute) SetSelectValue(axis ConfigurationAxis, config string, list LabelList) {
|
|
|
|
axis.validateConfig(config)
|
|
|
|
switch axis.configurationType {
|
|
|
|
case noConfig:
|
|
|
|
lla.Value = list
|
2021-07-16 22:33:47 +02:00
|
|
|
case arch, os, osArch, bionic, productVariables:
|
2021-05-21 14:37:59 +02:00
|
|
|
if lla.ConfigurableValues == nil {
|
|
|
|
lla.ConfigurableValues = make(configurableLabelLists)
|
|
|
|
}
|
|
|
|
lla.ConfigurableValues.setValueForAxis(axis, config, list)
|
|
|
|
default:
|
|
|
|
panic(fmt.Errorf("Unrecognized ConfigurationAxis %s", axis))
|
2021-05-19 12:49:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
// SelectValue gets a value for a bazel select for the given axis and config.
|
|
|
|
func (lla *LabelListAttribute) SelectValue(axis ConfigurationAxis, config string) LabelList {
|
|
|
|
axis.validateConfig(config)
|
|
|
|
switch axis.configurationType {
|
|
|
|
case noConfig:
|
|
|
|
return lla.Value
|
2021-07-16 22:33:47 +02:00
|
|
|
case arch, os, osArch, bionic, productVariables:
|
2021-05-21 14:37:59 +02:00
|
|
|
return lla.ConfigurableValues[axis][config]
|
2021-05-19 12:49:02 +02:00
|
|
|
default:
|
2021-05-21 14:37:59 +02:00
|
|
|
panic(fmt.Errorf("Unrecognized ConfigurationAxis %s", axis))
|
2021-05-19 12:49:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
// SortedConfigurationAxes returns all the used ConfigurationAxis in sorted order.
|
|
|
|
func (lla *LabelListAttribute) SortedConfigurationAxes() []ConfigurationAxis {
|
|
|
|
keys := make([]ConfigurationAxis, 0, len(lla.ConfigurableValues))
|
|
|
|
for k := range lla.ConfigurableValues {
|
|
|
|
keys = append(keys, k)
|
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
|
|
|
|
|
|
|
sort.Slice(keys, func(i, j int) bool { return keys[i].less(keys[j]) })
|
|
|
|
return keys
|
2021-03-15 11:02:43 +01:00
|
|
|
}
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
// Append all values, including os and arch specific ones, from another
|
|
|
|
// LabelListAttribute to this LabelListAttribute.
|
|
|
|
func (lla *LabelListAttribute) Append(other LabelListAttribute) {
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
if lla.ForceSpecifyEmptyList && !other.Value.IsNil() {
|
|
|
|
lla.Value.Includes = []Label{}
|
|
|
|
}
|
2021-05-21 14:37:59 +02:00
|
|
|
lla.Value.Append(other.Value)
|
|
|
|
if lla.ConfigurableValues == nil {
|
|
|
|
lla.ConfigurableValues = make(configurableLabelLists)
|
2021-05-19 12:49:02 +02:00
|
|
|
}
|
2021-05-21 14:37:59 +02:00
|
|
|
lla.ConfigurableValues.Append(other.ConfigurableValues)
|
2021-05-19 12:49:02 +02:00
|
|
|
}
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
// HasConfigurableValues returns true if the attribute contains axis-specific label list values.
|
|
|
|
func (lla LabelListAttribute) HasConfigurableValues() bool {
|
|
|
|
return len(lla.ConfigurableValues) > 0
|
2021-05-19 12:49:02 +02:00
|
|
|
}
|
|
|
|
|
2021-07-13 17:47:44 +02:00
|
|
|
// IsEmpty returns true if the attribute has no values under any configuration.
|
|
|
|
func (lla LabelListAttribute) IsEmpty() bool {
|
|
|
|
if len(lla.Value.Includes) > 0 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
for axis, _ := range lla.ConfigurableValues {
|
|
|
|
if lla.ConfigurableValues[axis].HasConfigurableValues() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-06-02 19:02:03 +02:00
|
|
|
// ResolveExcludes handles excludes across the various axes, ensuring that items are removed from
|
|
|
|
// the base value and included in default values as appropriate.
|
|
|
|
func (lla *LabelListAttribute) ResolveExcludes() {
|
|
|
|
for axis, configToLabels := range lla.ConfigurableValues {
|
|
|
|
baseLabels := lla.Value.deepCopy()
|
|
|
|
for config, val := range configToLabels {
|
|
|
|
// Exclude config-specific excludes from base value
|
|
|
|
lla.Value = SubtractBazelLabelList(lla.Value, LabelList{Includes: val.Excludes})
|
|
|
|
|
|
|
|
// add base values to config specific to add labels excluded by others in this axis
|
|
|
|
// then remove all config-specific excludes
|
|
|
|
allLabels := baseLabels.deepCopy()
|
|
|
|
allLabels.Append(val)
|
|
|
|
lla.ConfigurableValues[axis][config] = SubtractBazelLabelList(allLabels, LabelList{Includes: val.Excludes})
|
|
|
|
}
|
|
|
|
|
|
|
|
// After going through all configs, delete the duplicates in the config
|
|
|
|
// values that are already in the base Value.
|
|
|
|
for config, val := range configToLabels {
|
|
|
|
lla.ConfigurableValues[axis][config] = SubtractBazelLabelList(val, lla.Value)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now that the Value list is finalized for this axis, compare it with the original
|
|
|
|
// list, and put the difference into the default condition for the axis.
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
lla.ConfigurableValues[axis][ConditionsDefaultConfigKey] = SubtractBazelLabelList(baseLabels, lla.Value)
|
2021-06-02 19:02:03 +02:00
|
|
|
|
|
|
|
// if everything ends up without includes, just delete the axis
|
|
|
|
if !lla.ConfigurableValues[axis].HasConfigurableValues() {
|
|
|
|
delete(lla.ConfigurableValues, axis)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-24 13:20:12 +01:00
|
|
|
// StringListAttribute corresponds to the string_list Bazel attribute type with
|
|
|
|
// support for additional metadata, like configurations.
|
|
|
|
type StringListAttribute struct {
|
|
|
|
// The base value of the string list attribute.
|
|
|
|
Value []string
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
// The configured attribute label list Values. Optional
|
|
|
|
// a map of independent configurability axes
|
|
|
|
ConfigurableValues configurableStringLists
|
2021-05-19 12:49:02 +02:00
|
|
|
}
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
type configurableStringLists map[ConfigurationAxis]stringListSelectValues
|
2021-05-19 12:49:02 +02:00
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
func (csl configurableStringLists) Append(other configurableStringLists) {
|
|
|
|
for axis, otherSelects := range other {
|
|
|
|
selects := csl[axis]
|
|
|
|
if selects == nil {
|
|
|
|
selects = make(stringListSelectValues, len(otherSelects))
|
2021-02-24 13:20:12 +01:00
|
|
|
}
|
2021-05-21 14:37:59 +02:00
|
|
|
selects.appendSelects(otherSelects)
|
|
|
|
csl[axis] = selects
|
2021-02-24 13:20:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
func (csl configurableStringLists) setValueForAxis(axis ConfigurationAxis, config string, list []string) {
|
|
|
|
if csl[axis] == nil {
|
|
|
|
csl[axis] = make(stringListSelectValues)
|
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
|
|
|
csl[axis][config] = list
|
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
|
|
|
type stringListSelectValues map[string][]string
|
2021-02-24 13:20:12 +01:00
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
func (sl stringListSelectValues) appendSelects(other stringListSelectValues) {
|
|
|
|
for k, v := range other {
|
|
|
|
sl[k] = append(sl[k], v...)
|
2021-02-24 13:20:12 +01:00
|
|
|
}
|
|
|
|
}
|
2021-03-24 15:14:47 +01:00
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
func (sl stringListSelectValues) hasConfigurableValues(other stringListSelectValues) bool {
|
|
|
|
for _, val := range sl {
|
|
|
|
if len(val) > 0 {
|
|
|
|
return true
|
|
|
|
}
|
2021-04-05 12:35:13 +02:00
|
|
|
}
|
2021-05-21 14:37:59 +02:00
|
|
|
return false
|
2021-04-05 12:35:13 +02:00
|
|
|
}
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
// MakeStringListAttribute initializes a StringListAttribute with the non-arch specific value.
|
|
|
|
func MakeStringListAttribute(value []string) StringListAttribute {
|
|
|
|
// NOTE: These strings are not necessarily unique or sorted.
|
|
|
|
return StringListAttribute{
|
|
|
|
Value: value,
|
|
|
|
ConfigurableValues: make(configurableStringLists),
|
2021-04-05 12:35:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
// HasConfigurableValues returns true if the attribute contains axis-specific string_list values.
|
|
|
|
func (sla StringListAttribute) HasConfigurableValues() bool {
|
|
|
|
return len(sla.ConfigurableValues) > 0
|
2021-05-19 12:49:02 +02:00
|
|
|
}
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
// Append appends all values, including os and arch specific ones, from another
|
|
|
|
// StringListAttribute to this StringListAttribute
|
|
|
|
func (sla *StringListAttribute) Append(other StringListAttribute) {
|
|
|
|
sla.Value = append(sla.Value, other.Value...)
|
|
|
|
if sla.ConfigurableValues == nil {
|
|
|
|
sla.ConfigurableValues = make(configurableStringLists)
|
|
|
|
}
|
|
|
|
sla.ConfigurableValues.Append(other.ConfigurableValues)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetSelectValue set a value for a bazel select for the given axis, config and value.
|
|
|
|
func (sla *StringListAttribute) SetSelectValue(axis ConfigurationAxis, config string, list []string) {
|
|
|
|
axis.validateConfig(config)
|
|
|
|
switch axis.configurationType {
|
|
|
|
case noConfig:
|
|
|
|
sla.Value = list
|
2021-07-16 22:33:47 +02:00
|
|
|
case arch, os, osArch, bionic, productVariables:
|
2021-05-21 14:37:59 +02:00
|
|
|
if sla.ConfigurableValues == nil {
|
|
|
|
sla.ConfigurableValues = make(configurableStringLists)
|
|
|
|
}
|
|
|
|
sla.ConfigurableValues.setValueForAxis(axis, config, list)
|
2021-05-19 12:49:02 +02:00
|
|
|
default:
|
2021-05-21 14:37:59 +02:00
|
|
|
panic(fmt.Errorf("Unrecognized ConfigurationAxis %s", axis))
|
2021-05-19 12:49:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
// SelectValue gets a value for a bazel select for the given axis and config.
|
|
|
|
func (sla *StringListAttribute) SelectValue(axis ConfigurationAxis, config string) []string {
|
|
|
|
axis.validateConfig(config)
|
|
|
|
switch axis.configurationType {
|
|
|
|
case noConfig:
|
|
|
|
return sla.Value
|
2021-07-16 22:33:47 +02:00
|
|
|
case arch, os, osArch, bionic, productVariables:
|
2021-05-21 14:37:59 +02:00
|
|
|
return sla.ConfigurableValues[axis][config]
|
2021-05-19 12:49:02 +02:00
|
|
|
default:
|
2021-05-21 14:37:59 +02:00
|
|
|
panic(fmt.Errorf("Unrecognized ConfigurationAxis %s", axis))
|
2021-05-19 12:49:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
// SortedConfigurationAxes returns all the used ConfigurationAxis in sorted order.
|
|
|
|
func (sla *StringListAttribute) SortedConfigurationAxes() []ConfigurationAxis {
|
|
|
|
keys := make([]ConfigurationAxis, 0, len(sla.ConfigurableValues))
|
|
|
|
for k := range sla.ConfigurableValues {
|
|
|
|
keys = append(keys, k)
|
2021-05-06 19:54:29 +02:00
|
|
|
}
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
sort.Slice(keys, func(i, j int) bool { return keys[i].less(keys[j]) })
|
|
|
|
return keys
|
2021-04-13 09:14:55 +02:00
|
|
|
}
|
|
|
|
|
2021-03-24 15:14:47 +01:00
|
|
|
// TryVariableSubstitution, replace string substitution formatting within each string in slice with
|
|
|
|
// Starlark string.format compatible tag for productVariable.
|
|
|
|
func TryVariableSubstitutions(slice []string, productVariable string) ([]string, bool) {
|
|
|
|
ret := make([]string, 0, len(slice))
|
|
|
|
changesMade := false
|
|
|
|
for _, s := range slice {
|
|
|
|
newS, changed := TryVariableSubstitution(s, productVariable)
|
|
|
|
ret = append(ret, newS)
|
|
|
|
changesMade = changesMade || changed
|
|
|
|
}
|
|
|
|
return ret, changesMade
|
|
|
|
}
|
|
|
|
|
|
|
|
// TryVariableSubstitution, replace string substitution formatting within s with Starlark
|
|
|
|
// string.format compatible tag for productVariable.
|
|
|
|
func TryVariableSubstitution(s string, productVariable string) (string, bool) {
|
2021-05-26 14:45:30 +02:00
|
|
|
sub := productVariableSubstitutionPattern.ReplaceAllString(s, "$("+productVariable+")")
|
2021-03-24 15:14:47 +01:00
|
|
|
return sub, s != sub
|
|
|
|
}
|