Support empty srcs for configurable attrs
Test: mixed build linkerconfig Change-Id: I1ee56f7fa46ce2971ecae6d2ca9258631a32f46a
This commit is contained in:
@@ -140,7 +140,6 @@ func SubtractStrings(haystack []string, needle []string) []string {
|
|||||||
// Return all needles in a given haystack, where needleFn is true for needles.
|
// Return all needles in a given haystack, where needleFn is true for needles.
|
||||||
func FilterLabelList(haystack LabelList, needleFn func(string) bool) LabelList {
|
func FilterLabelList(haystack LabelList, needleFn func(string) bool) LabelList {
|
||||||
var includes []Label
|
var includes []Label
|
||||||
|
|
||||||
for _, inc := range haystack.Includes {
|
for _, inc := range haystack.Includes {
|
||||||
if needleFn(inc.Label) {
|
if needleFn(inc.Label) {
|
||||||
includes = append(includes, inc)
|
includes = append(includes, inc)
|
||||||
|
@@ -445,7 +445,7 @@ func prettyPrint(propertyValue reflect.Value, indent int) (string, error) {
|
|||||||
return prettyPrint(propertyValue.Elem(), indent)
|
return prettyPrint(propertyValue.Elem(), indent)
|
||||||
case reflect.Slice:
|
case reflect.Slice:
|
||||||
if propertyValue.Len() == 0 {
|
if propertyValue.Len() == 0 {
|
||||||
return "", nil
|
return "[]", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if propertyValue.Len() == 1 {
|
if propertyValue.Len() == 1 {
|
||||||
|
@@ -850,6 +850,84 @@ cc_library_static {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCcLibraryStaticOneArchEmpty(t *testing.T) {
|
||||||
|
runCcLibraryStaticTestCase(t, bp2buildTestCase{
|
||||||
|
description: "cc_library_static one arch empty",
|
||||||
|
moduleTypeUnderTest: "cc_library_static",
|
||||||
|
moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
|
||||||
|
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
|
||||||
|
depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
|
||||||
|
filesystem: map[string]string{
|
||||||
|
"common.cc": "",
|
||||||
|
"foo-no-arm.cc": "",
|
||||||
|
"foo-excluded.cc": "",
|
||||||
|
},
|
||||||
|
blueprint: soongCcLibraryStaticPreamble + `
|
||||||
|
cc_library_static {
|
||||||
|
name: "foo_static",
|
||||||
|
srcs: ["common.cc", "foo-*.cc"],
|
||||||
|
exclude_srcs: ["foo-excluded.cc"],
|
||||||
|
arch: {
|
||||||
|
arm: { exclude_srcs: ["foo-no-arm.cc"] },
|
||||||
|
},
|
||||||
|
}`,
|
||||||
|
expectedBazelTargets: []string{`cc_library_static(
|
||||||
|
name = "foo_static",
|
||||||
|
copts = [
|
||||||
|
"-I.",
|
||||||
|
"-I$(BINDIR)/.",
|
||||||
|
],
|
||||||
|
linkstatic = True,
|
||||||
|
srcs = ["common.cc"] + select({
|
||||||
|
"//build/bazel/platforms/arch:arm": [],
|
||||||
|
"//conditions:default": ["foo-no-arm.cc"],
|
||||||
|
}),
|
||||||
|
)`},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCcLibraryStaticOneArchEmptyOtherSet(t *testing.T) {
|
||||||
|
runCcLibraryStaticTestCase(t, bp2buildTestCase{
|
||||||
|
description: "cc_library_static one arch empty other set",
|
||||||
|
moduleTypeUnderTest: "cc_library_static",
|
||||||
|
moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
|
||||||
|
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
|
||||||
|
depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
|
||||||
|
filesystem: map[string]string{
|
||||||
|
"common.cc": "",
|
||||||
|
"foo-no-arm.cc": "",
|
||||||
|
"x86-only.cc": "",
|
||||||
|
"foo-excluded.cc": "",
|
||||||
|
},
|
||||||
|
blueprint: soongCcLibraryStaticPreamble + `
|
||||||
|
cc_library_static {
|
||||||
|
name: "foo_static",
|
||||||
|
srcs: ["common.cc", "foo-*.cc"],
|
||||||
|
exclude_srcs: ["foo-excluded.cc"],
|
||||||
|
arch: {
|
||||||
|
arm: { exclude_srcs: ["foo-no-arm.cc"] },
|
||||||
|
x86: { srcs: ["x86-only.cc"] },
|
||||||
|
},
|
||||||
|
}`,
|
||||||
|
expectedBazelTargets: []string{`cc_library_static(
|
||||||
|
name = "foo_static",
|
||||||
|
copts = [
|
||||||
|
"-I.",
|
||||||
|
"-I$(BINDIR)/.",
|
||||||
|
],
|
||||||
|
linkstatic = True,
|
||||||
|
srcs = ["common.cc"] + select({
|
||||||
|
"//build/bazel/platforms/arch:arm": [],
|
||||||
|
"//build/bazel/platforms/arch:x86": [
|
||||||
|
"foo-no-arm.cc",
|
||||||
|
"x86-only.cc",
|
||||||
|
],
|
||||||
|
"//conditions:default": ["foo-no-arm.cc"],
|
||||||
|
}),
|
||||||
|
)`},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestCcLibraryStaticMultipleDepSameName(t *testing.T) {
|
func TestCcLibraryStaticMultipleDepSameName(t *testing.T) {
|
||||||
runCcLibraryStaticTestCase(t, bp2buildTestCase{
|
runCcLibraryStaticTestCase(t, bp2buildTestCase{
|
||||||
description: "cc_library_static multiple dep same name panic",
|
description: "cc_library_static multiple dep same name panic",
|
||||||
|
@@ -80,32 +80,55 @@ func getLabelListValues(list bazel.LabelListAttribute) (reflect.Value, []selects
|
|||||||
if !list.HasConfigurableValues() {
|
if !list.HasConfigurableValues() {
|
||||||
return value, []selects{}
|
return value, []selects{}
|
||||||
}
|
}
|
||||||
|
var ret []selects
|
||||||
|
|
||||||
archSelects := map[string]reflect.Value{}
|
archSelects := map[string]reflect.Value{}
|
||||||
for arch, selectKey := range bazel.PlatformArchMap {
|
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{}
|
osSelects := map[string]reflect.Value{}
|
||||||
osArchSelects := make([]selects, 0)
|
osArchSelects := []selects{}
|
||||||
for _, os := range android.SortedStringKeys(bazel.PlatformOsMap) {
|
for _, os := range android.SortedStringKeys(bazel.PlatformOsMap) {
|
||||||
selectKey := bazel.PlatformOsMap[os]
|
selectKey := bazel.PlatformOsMap[os]
|
||||||
osSelects[selectKey] = reflect.ValueOf(list.GetOsValueForTarget(os).Includes)
|
if use, value := labelListSelectValue(selectKey, list.GetOsValueForTarget(os)); use {
|
||||||
archSelects := make(map[string]reflect.Value)
|
osSelects[selectKey] = value
|
||||||
|
}
|
||||||
|
selects := make(map[string]reflect.Value)
|
||||||
// TODO(b/187530594): Should we also check arch=CONDITIOSN_DEFAULT? (not in AllArches)
|
// TODO(b/187530594): Should we also check arch=CONDITIOSN_DEFAULT? (not in AllArches)
|
||||||
for _, arch := range bazel.AllArches {
|
for _, arch := range bazel.AllArches {
|
||||||
target := os + "_" + arch
|
target := os + "_" + arch
|
||||||
selectKey := bazel.PlatformTargetMap[target]
|
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
|
return value, ret
|
||||||
selects = append(selects, archSelects)
|
}
|
||||||
selects = append(selects, osSelects)
|
|
||||||
selects = append(selects, osArchSelects...)
|
func labelListSelectValue(selectKey string, list bazel.LabelList) (bool, reflect.Value) {
|
||||||
return value, selects
|
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
|
// prettyPrintAttribute converts an Attribute to its Bazel syntax. May contain
|
||||||
|
@@ -421,7 +421,9 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul
|
|||||||
if baseCompilerProps, ok := osProps.Properties.(*BaseCompilerProperties); ok {
|
if baseCompilerProps, ok := osProps.Properties.(*BaseCompilerProperties); ok {
|
||||||
srcsList := parseSrcs(baseCompilerProps)
|
srcsList := parseSrcs(baseCompilerProps)
|
||||||
// TODO(b/186153868): add support for os-specific srcs and exclude_srcs
|
// TODO(b/186153868): add support for os-specific srcs and exclude_srcs
|
||||||
srcs.SetOsValueForTarget(os.Name, bazel.SubtractBazelLabelList(srcsList, baseSrcsLabelList))
|
if len(baseCompilerProps.Srcs) > 0 || len(baseCompilerProps.Exclude_srcs) > 0 {
|
||||||
|
srcs.SetOsValueForTarget(os.Name, bazel.SubtractBazelLabelList(srcsList, baseSrcsLabelList))
|
||||||
|
}
|
||||||
copts.SetOsValueForTarget(os.Name, parseCopts(baseCompilerProps))
|
copts.SetOsValueForTarget(os.Name, parseCopts(baseCompilerProps))
|
||||||
asFlags.SetOsValueForTarget(os.Name, parseCommandLineFlags(baseCompilerProps.Asflags))
|
asFlags.SetOsValueForTarget(os.Name, parseCommandLineFlags(baseCompilerProps.Asflags))
|
||||||
conlyFlags.SetOsValueForTarget(os.Name, parseCommandLineFlags(baseCompilerProps.Conlyflags))
|
conlyFlags.SetOsValueForTarget(os.Name, parseCommandLineFlags(baseCompilerProps.Conlyflags))
|
||||||
@@ -431,7 +433,9 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul
|
|||||||
if baseCompilerProps, ok := archProps.(*BaseCompilerProperties); ok {
|
if baseCompilerProps, ok := archProps.(*BaseCompilerProperties); ok {
|
||||||
srcsList := parseSrcs(baseCompilerProps)
|
srcsList := parseSrcs(baseCompilerProps)
|
||||||
// TODO(b/186153868): add support for os-specific srcs and exclude_srcs
|
// TODO(b/186153868): add support for os-specific srcs and exclude_srcs
|
||||||
srcs.SetOsArchValueForTarget(os.Name, arch.Name, bazel.SubtractBazelLabelList(srcsList, baseSrcsLabelList))
|
if len(baseCompilerProps.Srcs) > 0 || len(baseCompilerProps.Exclude_srcs) > 0 {
|
||||||
|
srcs.SetOsArchValueForTarget(os.Name, arch.Name, bazel.SubtractBazelLabelList(srcsList, baseSrcsLabelList))
|
||||||
|
}
|
||||||
copts.SetOsArchValueForTarget(os.Name, arch.Name, parseCopts(baseCompilerProps))
|
copts.SetOsArchValueForTarget(os.Name, arch.Name, parseCopts(baseCompilerProps))
|
||||||
asFlags.SetOsArchValueForTarget(os.Name, arch.Name, parseCommandLineFlags(baseCompilerProps.Asflags))
|
asFlags.SetOsArchValueForTarget(os.Name, arch.Name, parseCommandLineFlags(baseCompilerProps.Asflags))
|
||||||
conlyFlags.SetOsArchValueForTarget(os.Name, arch.Name, parseCommandLineFlags(baseCompilerProps.Conlyflags))
|
conlyFlags.SetOsArchValueForTarget(os.Name, arch.Name, parseCommandLineFlags(baseCompilerProps.Conlyflags))
|
||||||
|
Reference in New Issue
Block a user