bp2build: Handle target.linux

Also refactor target.bionic to be handled not as its own configuration
axis, but instead to be grouped into os selects handling.

This allows us to remove libbase and its dependencies from the bp2build
denylist.

Test: mixed_droid.sh CI
Change-Id: I92f30074d286306207653fe37589835ae3db16c4
This commit is contained in:
Chris Parsons 2021-10-01 14:45:30 -04:00
parent 2df9ebf9ca
commit 2dde0cb3de
6 changed files with 104 additions and 58 deletions

View file

@ -2005,16 +2005,37 @@ func (m *ModuleBase) GetArchVariantProperties(ctx ArchVariantContext, propertySe
osToProp := ArchVariantProperties{}
archOsToProp := ArchVariantProperties{}
var linuxStructs, bionicStructs []reflect.Value
var ok bool
linuxStructs, ok = getTargetStructs(ctx, archProperties, "Linux")
if !ok {
linuxStructs = make([]reflect.Value, 0)
}
bionicStructs, ok = getTargetStructs(ctx, archProperties, "Bionic")
if !ok {
bionicStructs = make([]reflect.Value, 0)
}
// For android, linux, ...
for _, os := range osTypeList {
if os == CommonOS {
// It looks like this OS value is not used in Blueprint files
continue
}
osStructs, ok := getTargetStructs(ctx, archProperties, os.Field)
osStructs := make([]reflect.Value, 0)
osSpecificStructs, ok := getTargetStructs(ctx, archProperties, os.Field)
if ok {
osToProp[os.Name] = mergeStructs(ctx, osStructs, propertySet)
osStructs = append(osStructs, osSpecificStructs...)
}
if os.Linux() {
osStructs = append(osStructs, linuxStructs...)
}
if os.Bionic() {
osStructs = append(osStructs, bionicStructs...)
}
osToProp[os.Name] = mergeStructs(ctx, osStructs, propertySet)
// For arm, x86, ...
for _, arch := range osArchTypeMap[os] {
@ -2048,15 +2069,9 @@ func (m *ModuleBase) GetArchVariantProperties(ctx ArchVariantContext, propertySe
archOsToProp[targetName] = mergeStructs(ctx, osArchStructs, propertySet)
}
}
axisToProps[bazel.OsConfigurationAxis] = osToProp
axisToProps[bazel.OsArchConfigurationAxis] = archOsToProp
bionicStructs, ok := getTargetStructs(ctx, archProperties, "Bionic")
if ok {
axisToProps[bazel.BionicConfigurationAxis] = map[string]interface{}{
"bionic": mergeStructs(ctx, bionicStructs, propertySet)}
}
return axisToProps
}

View file

@ -223,9 +223,6 @@ var (
"libc_malloc_debug", // http://b/186824339, cc_library_static, depends on //system/libbase:libbase (http://b/186823646)
"libc_malloc_debug_backtrace", // http://b/186824112, cc_library_static, depends on //external/libcxxabi:libc++demangle (http://b/186823773)
//"libcutils", // http://b/186827426, cc_library, depends on //system/core/libprocessgroup:libprocessgroup_headers (http://b/186826841)
//"libcutils_sockets", // http://b/186826853, cc_library, depends on //system/libbase:libbase (http://b/186826479)
"liblinker_debuggerd_stub", // http://b/186824327, cc_library_static, depends on //external/zlib:libz (http://b/186823782)
// also depends on //system/libziparchive:libziparchive (http://b/186823656)
// also depends on //system/logging/liblog:liblog (http://b/186822772)
@ -285,24 +282,6 @@ var (
"libadb_protos_static", // b/200601772: Requires cc_library proto support
"libadb_protos", // b/200601772: Requires cc_library proto support
"libapp_processes_protos_lite", // b/200601772: Requires cc_library proto support
"libbase", // TODO(cparsons): Breaks libandroidfw. Investigate.
// The below items depend on libbase.
"libadb_pairing_auth",
"libadb_pairing_auth_static",
"libadb_sysdeps",
"libadb_tls_connection",
"libadb_tls_connection_static",
"libadbconnection_client",
"libadbconnection_server",
"libadbd_auth",
"libadbd_fs",
"libcutils",
"libcutils_sockets",
"libdiagnose_usb",
// ---
}
// Per-module denylist of cc_library modules to only generate the static

View file

@ -91,11 +91,6 @@ var (
ConditionsDefaultConfigKey: ConditionsDefaultSelectKey, // The default condition of an os select map.
}
platformBionicMap = map[string]string{
"bionic": "//build/bazel/platforms/os:bionic",
ConditionsDefaultConfigKey: ConditionsDefaultSelectKey, // The default condition of an os select map.
}
platformOsArchMap = map[string]string{
osArchAndroidArm: "//build/bazel/platforms/os_arch:android_arm",
osArchAndroidArm64: "//build/bazel/platforms/os_arch:android_arm64",
@ -122,7 +117,6 @@ const (
arch
os
osArch
bionic
productVariables
)
@ -132,7 +126,6 @@ func (ct configurationType) String() string {
arch: "arch",
os: "os",
osArch: "arch_os",
bionic: "bionic",
productVariables: "product_variables",
}[ct]
}
@ -155,10 +148,6 @@ func (ct configurationType) validateConfig(config string) {
if _, ok := platformOsArchMap[config]; !ok {
panic(fmt.Errorf("Unknown os+arch: %s", config))
}
case bionic:
if _, ok := platformBionicMap[config]; !ok {
panic(fmt.Errorf("Unknown for %s: %s", ct.String(), config))
}
case productVariables:
// do nothing
default:
@ -178,8 +167,6 @@ func (ct configurationType) SelectKey(config string) string {
return platformOsMap[config]
case osArch:
return platformOsArchMap[config]
case bionic:
return platformBionicMap[config]
case productVariables:
if config == ConditionsDefaultConfigKey {
return ConditionsDefaultSelectKey
@ -199,8 +186,6 @@ var (
OsConfigurationAxis = ConfigurationAxis{configurationType: os}
// An axis for arch+os-specific configurations
OsArchConfigurationAxis = ConfigurationAxis{configurationType: osArch}
// An axis for bionic os-specific configurations
BionicConfigurationAxis = ConfigurationAxis{configurationType: bionic}
)
// ProductVariableConfigurationAxis returns an axis for the given product variable

View file

@ -264,7 +264,7 @@ func (la *LabelAttribute) SetSelectValue(axis ConfigurationAxis, config string,
switch axis.configurationType {
case noConfig:
la.Value = &value
case arch, os, osArch, bionic, productVariables:
case arch, os, osArch, productVariables:
if la.ConfigurableValues == nil {
la.ConfigurableValues = make(configurableLabels)
}
@ -280,7 +280,7 @@ func (la *LabelAttribute) SelectValue(axis ConfigurationAxis, config string) Lab
switch axis.configurationType {
case noConfig:
return *la.Value
case arch, os, osArch, bionic, productVariables:
case arch, os, osArch, productVariables:
return *la.ConfigurableValues[axis][config]
default:
panic(fmt.Errorf("Unrecognized ConfigurationAxis %s", axis))
@ -337,7 +337,7 @@ func (ba *BoolAttribute) SetSelectValue(axis ConfigurationAxis, config string, v
switch axis.configurationType {
case noConfig:
ba.Value = value
case arch, os, osArch, bionic, productVariables:
case arch, os, osArch, productVariables:
if ba.ConfigurableValues == nil {
ba.ConfigurableValues = make(configurableBools)
}
@ -353,7 +353,7 @@ func (ba BoolAttribute) SelectValue(axis ConfigurationAxis, config string) *bool
switch axis.configurationType {
case noConfig:
return ba.Value
case arch, os, osArch, bionic, productVariables:
case arch, os, osArch, productVariables:
if v, ok := ba.ConfigurableValues[axis][config]; ok {
return &v
} else {
@ -459,7 +459,7 @@ func (lla *LabelListAttribute) SetSelectValue(axis ConfigurationAxis, config str
switch axis.configurationType {
case noConfig:
lla.Value = list
case arch, os, osArch, bionic, productVariables:
case arch, os, osArch, productVariables:
if lla.ConfigurableValues == nil {
lla.ConfigurableValues = make(configurableLabelLists)
}
@ -475,7 +475,7 @@ func (lla *LabelListAttribute) SelectValue(axis ConfigurationAxis, config string
switch axis.configurationType {
case noConfig:
return lla.Value
case arch, os, osArch, bionic, productVariables:
case arch, os, osArch, productVariables:
return lla.ConfigurableValues[axis][config]
default:
panic(fmt.Errorf("Unrecognized ConfigurationAxis %s", axis))
@ -773,7 +773,7 @@ func (sla *StringListAttribute) SetSelectValue(axis ConfigurationAxis, config st
switch axis.configurationType {
case noConfig:
sla.Value = list
case arch, os, osArch, bionic, productVariables:
case arch, os, osArch, productVariables:
if sla.ConfigurableValues == nil {
sla.ConfigurableValues = make(configurableStringLists)
}
@ -789,7 +789,7 @@ func (sla *StringListAttribute) SelectValue(axis ConfigurationAxis, config strin
switch axis.configurationType {
case noConfig:
return sla.Value
case arch, os, osArch, bionic, productVariables:
case arch, os, osArch, productVariables:
return sla.ConfigurableValues[axis][config]
default:
panic(fmt.Errorf("Unrecognized ConfigurationAxis %s", axis))

View file

@ -131,12 +131,13 @@ cc_library {
"//build/bazel/platforms/arch:x86_64": ["x86_64.cpp"],
"//conditions:default": [],
}) + select({
"//build/bazel/platforms/os:android": ["android.cpp"],
"//build/bazel/platforms/os:android": [
"android.cpp",
"bionic.cpp",
],
"//build/bazel/platforms/os:darwin": ["darwin.cpp"],
"//build/bazel/platforms/os:linux": ["linux.cpp"],
"//conditions:default": [],
}) + select({
"//build/bazel/platforms/os:bionic": ["bionic.cpp"],
"//build/bazel/platforms/os:linux_bionic": ["bionic.cpp"],
"//conditions:default": [],
}),
)`}})
@ -1571,3 +1572,68 @@ cc_library {
)`},
})
}
func TestCcLibraryOsSelects(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
description: "cc_library - selects for all os targets",
moduleTypeUnderTest: "cc_library",
moduleTypeUnderTestFactory: cc.LibraryFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
filesystem: map[string]string{},
blueprint: soongCcLibraryPreamble + `
cc_library_headers { name: "some-headers" }
cc_library {
name: "foo-lib",
srcs: ["base.cpp"],
target: {
android: {
srcs: ["android.cpp"],
},
linux: {
srcs: ["linux.cpp"],
},
linux_glibc: {
srcs: ["linux_glibc.cpp"],
},
darwin: {
srcs: ["darwin.cpp"],
},
bionic: {
srcs: ["bionic.cpp"],
},
linux_musl: {
srcs: ["linux_musl.cpp"],
},
windows: {
srcs: ["windows.cpp"],
},
},
include_build_directory: false,
}
`,
expectedBazelTargets: []string{`cc_library(
name = "foo-lib",
srcs = ["base.cpp"] + select({
"//build/bazel/platforms/os:android": [
"android.cpp",
"bionic.cpp",
"linux.cpp",
],
"//build/bazel/platforms/os:darwin": ["darwin.cpp"],
"//build/bazel/platforms/os:linux": [
"linux.cpp",
"linux_glibc.cpp",
],
"//build/bazel/platforms/os:linux_bionic": [
"bionic.cpp",
"linux.cpp",
],
"//build/bazel/platforms/os:linux_musl": [
"linux.cpp",
"linux_musl.cpp",
],
"//build/bazel/platforms/os:windows": ["windows.cpp"],
"//conditions:default": [],
}),
)`}})
}

View file

@ -1382,7 +1382,8 @@ cc_library_static {
expectedBazelTargets: []string{`cc_library_static(
name = "target_bionic",
system_dynamic_deps = select({
"//build/bazel/platforms/os:bionic": [":libc"],
"//build/bazel/platforms/os:android": [":libc"],
"//build/bazel/platforms/os:linux_bionic": [":libc"],
"//conditions:default": [],
}),
)`},