Support empty srcs for configurable attrs

Test: mixed build linkerconfig
Change-Id: I1ee56f7fa46ce2971ecae6d2ca9258631a32f46a
This commit is contained in:
Liz Kammer
2021-05-26 15:08:27 -04:00
parent bcf5304eab
commit 2b07ec7b3b
5 changed files with 119 additions and 15 deletions

View File

@@ -80,32 +80,55 @@ func getLabelListValues(list bazel.LabelListAttribute) (reflect.Value, []selects
if !list.HasConfigurableValues() {
return value, []selects{}
}
var ret []selects
archSelects := map[string]reflect.Value{}
for arch, selectKey := range bazel.PlatformArchMap {
archSelects[selectKey] = reflect.ValueOf(list.GetValueForArch(arch).Includes)
if use, value := labelListSelectValue(selectKey, list.GetValueForArch(arch)); use {
archSelects[selectKey] = value
}
}
if len(archSelects) > 0 {
ret = append(ret, archSelects)
}
osSelects := map[string]reflect.Value{}
osArchSelects := make([]selects, 0)
osArchSelects := []selects{}
for _, os := range android.SortedStringKeys(bazel.PlatformOsMap) {
selectKey := bazel.PlatformOsMap[os]
osSelects[selectKey] = reflect.ValueOf(list.GetOsValueForTarget(os).Includes)
archSelects := make(map[string]reflect.Value)
if use, value := labelListSelectValue(selectKey, list.GetOsValueForTarget(os)); use {
osSelects[selectKey] = value
}
selects := make(map[string]reflect.Value)
// TODO(b/187530594): Should we also check arch=CONDITIOSN_DEFAULT? (not in AllArches)
for _, arch := range bazel.AllArches {
target := os + "_" + arch
selectKey := bazel.PlatformTargetMap[target]
archSelects[selectKey] = reflect.ValueOf(list.GetOsArchValueForTarget(os, arch).Includes)
if use, value := labelListSelectValue(selectKey, list.GetOsArchValueForTarget(os, arch)); use {
selects[selectKey] = value
}
}
if len(selects) > 0 {
osArchSelects = append(osArchSelects, selects)
}
osArchSelects = append(osArchSelects, archSelects)
}
if len(osSelects) > 0 {
ret = append(ret, osSelects)
}
ret = append(ret, osArchSelects...)
var selects []selects
selects = append(selects, archSelects)
selects = append(selects, osSelects)
selects = append(selects, osArchSelects...)
return value, selects
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{}))
}
// prettyPrintAttribute converts an Attribute to its Bazel syntax. May contain