Support building libcrypto via mixed builds
This required the following fixes to bp2build: - Correctly handle Bionic_* and Linux_* targets - Correctly handle cc_object's selects - Generate linker_script, stl, and system_dynamic_deps for cc_object in bp2build Test: USE_BAZEL_ANALYSIS=1 m adbd Change-Id: I753fd18df8ae551fb69df07e4174527c5388f289
This commit is contained in:
@@ -1999,12 +1999,7 @@ func (m *ModuleBase) GetArchVariantProperties(ctx ArchVariantContext, propertySe
|
|||||||
// Create a new instance of the requested property set
|
// Create a new instance of the requested property set
|
||||||
value := reflect.New(reflect.ValueOf(propertySet).Elem().Type()).Interface()
|
value := reflect.New(reflect.ValueOf(propertySet).Elem().Type()).Interface()
|
||||||
|
|
||||||
// Merge all the structs together
|
archToProp[arch.Name] = mergeStructs(ctx, propertyStructs, value)
|
||||||
for _, propertyStruct := range propertyStructs {
|
|
||||||
mergePropertyStruct(ctx, value, propertyStruct)
|
|
||||||
}
|
|
||||||
|
|
||||||
archToProp[arch.Name] = value
|
|
||||||
}
|
}
|
||||||
axisToProps[bazel.ArchConfigurationAxis] = archToProp
|
axisToProps[bazel.ArchConfigurationAxis] = archToProp
|
||||||
|
|
||||||
@@ -2016,19 +2011,50 @@ func (m *ModuleBase) GetArchVariantProperties(ctx ArchVariantContext, propertySe
|
|||||||
// It looks like this OS value is not used in Blueprint files
|
// It looks like this OS value is not used in Blueprint files
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
osToProp[os.Name] = getTargetStruct(ctx, propertySet, archProperties, os.Field)
|
osStructs, ok := getTargetStructs(ctx, archProperties, os.Field)
|
||||||
|
if ok {
|
||||||
|
osToProp[os.Name] = mergeStructs(ctx, osStructs, propertySet)
|
||||||
|
}
|
||||||
|
|
||||||
// For arm, x86, ...
|
// For arm, x86, ...
|
||||||
for _, arch := range osArchTypeMap[os] {
|
for _, arch := range osArchTypeMap[os] {
|
||||||
|
osArchStructs := make([]reflect.Value, 0)
|
||||||
|
|
||||||
targetField := GetCompoundTargetField(os, arch)
|
targetField := GetCompoundTargetField(os, arch)
|
||||||
targetName := fmt.Sprintf("%s_%s", os.Name, arch.Name)
|
targetName := fmt.Sprintf("%s_%s", os.Name, arch.Name)
|
||||||
archOsToProp[targetName] = getTargetStruct(ctx, propertySet, archProperties, targetField)
|
targetStructs, ok := getTargetStructs(ctx, archProperties, targetField)
|
||||||
|
if ok {
|
||||||
|
osArchStructs = append(osArchStructs, targetStructs...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Auto-combine with Linux_ and Bionic_ targets. This potentially results in
|
||||||
|
// repetition and select() bloat, but use of Linux_* and Bionic_* targets is rare.
|
||||||
|
// TODO(b/201423152): Look into cleanup.
|
||||||
|
if os.Linux() {
|
||||||
|
targetField := "Linux_" + arch.Name
|
||||||
|
targetStructs, ok := getTargetStructs(ctx, archProperties, targetField)
|
||||||
|
if ok {
|
||||||
|
osArchStructs = append(osArchStructs, targetStructs...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if os.Bionic() {
|
||||||
|
targetField := "Bionic_" + arch.Name
|
||||||
|
targetStructs, ok := getTargetStructs(ctx, archProperties, targetField)
|
||||||
|
if ok {
|
||||||
|
osArchStructs = append(osArchStructs, targetStructs...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
archOsToProp[targetName] = mergeStructs(ctx, osArchStructs, propertySet)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
axisToProps[bazel.OsConfigurationAxis] = osToProp
|
axisToProps[bazel.OsConfigurationAxis] = osToProp
|
||||||
axisToProps[bazel.OsArchConfigurationAxis] = archOsToProp
|
axisToProps[bazel.OsArchConfigurationAxis] = archOsToProp
|
||||||
|
|
||||||
|
bionicStructs, ok := getTargetStructs(ctx, archProperties, "Bionic")
|
||||||
|
if ok {
|
||||||
axisToProps[bazel.BionicConfigurationAxis] = map[string]interface{}{
|
axisToProps[bazel.BionicConfigurationAxis] = map[string]interface{}{
|
||||||
"bionic": getTargetStruct(ctx, propertySet, archProperties, "Bionic"),
|
"bionic": mergeStructs(ctx, bionicStructs, propertySet)}
|
||||||
}
|
}
|
||||||
|
|
||||||
return axisToProps
|
return axisToProps
|
||||||
@@ -2048,7 +2074,7 @@ func (m *ModuleBase) GetArchVariantProperties(ctx ArchVariantContext, propertySe
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// This would return a BaseCompilerProperties with BaseCompilerProperties.Srcs = ["foo.c"]
|
// This would return a BaseCompilerProperties with BaseCompilerProperties.Srcs = ["foo.c"]
|
||||||
func getTargetStruct(ctx ArchVariantContext, propertySet interface{}, archProperties []interface{}, targetName string) interface{} {
|
func getTargetStructs(ctx ArchVariantContext, archProperties []interface{}, targetName string) ([]reflect.Value, bool) {
|
||||||
propertyStructs := make([]reflect.Value, 0)
|
propertyStructs := make([]reflect.Value, 0)
|
||||||
for _, archProperty := range archProperties {
|
for _, archProperty := range archProperties {
|
||||||
archPropValues := reflect.ValueOf(archProperty).Elem()
|
archPropValues := reflect.ValueOf(archProperty).Elem()
|
||||||
@@ -2056,9 +2082,15 @@ func getTargetStruct(ctx ArchVariantContext, propertySet interface{}, archProper
|
|||||||
targetStruct, ok := getChildPropertyStruct(ctx, targetProp, targetName, targetName)
|
targetStruct, ok := getChildPropertyStruct(ctx, targetProp, targetName, targetName)
|
||||||
if ok {
|
if ok {
|
||||||
propertyStructs = append(propertyStructs, targetStruct)
|
propertyStructs = append(propertyStructs, targetStruct)
|
||||||
|
} else {
|
||||||
|
return propertyStructs, false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return propertyStructs, true
|
||||||
|
}
|
||||||
|
|
||||||
|
func mergeStructs(ctx ArchVariantContext, propertyStructs []reflect.Value, propertySet interface{}) interface{} {
|
||||||
// Create a new instance of the requested property set
|
// Create a new instance of the requested property set
|
||||||
value := reflect.New(reflect.ValueOf(propertySet).Elem().Type()).Interface()
|
value := reflect.New(reflect.ValueOf(propertySet).Elem().Type()).Interface()
|
||||||
|
|
||||||
|
@@ -179,6 +179,7 @@ var (
|
|||||||
"build/bazel/examples/apex/minimal": Bp2BuildDefaultTrueRecursively,
|
"build/bazel/examples/apex/minimal": Bp2BuildDefaultTrueRecursively,
|
||||||
"development/sdk": Bp2BuildDefaultTrueRecursively,
|
"development/sdk": Bp2BuildDefaultTrueRecursively,
|
||||||
"external/arm-optimized-routines": Bp2BuildDefaultTrueRecursively,
|
"external/arm-optimized-routines": Bp2BuildDefaultTrueRecursively,
|
||||||
|
"external/boringssl": Bp2BuildDefaultTrueRecursively,
|
||||||
"external/brotli": Bp2BuildDefaultTrue,
|
"external/brotli": Bp2BuildDefaultTrue,
|
||||||
"external/fmtlib": Bp2BuildDefaultTrueRecursively,
|
"external/fmtlib": Bp2BuildDefaultTrueRecursively,
|
||||||
"external/gwp_asan": Bp2BuildDefaultTrueRecursively,
|
"external/gwp_asan": Bp2BuildDefaultTrueRecursively,
|
||||||
@@ -191,8 +192,18 @@ var (
|
|||||||
"external/python/six": Bp2BuildDefaultTrueRecursively,
|
"external/python/six": Bp2BuildDefaultTrueRecursively,
|
||||||
"external/scudo": Bp2BuildDefaultTrueRecursively,
|
"external/scudo": Bp2BuildDefaultTrueRecursively,
|
||||||
"external/zlib": Bp2BuildDefaultTrueRecursively,
|
"external/zlib": Bp2BuildDefaultTrueRecursively,
|
||||||
|
"frameworks/native/libs/adbd_auth": Bp2BuildDefaultTrueRecursively,
|
||||||
|
"packages/modules/adb": Bp2BuildDefaultTrue,
|
||||||
|
"packages/modules/adb/crypto": Bp2BuildDefaultTrueRecursively,
|
||||||
|
"packages/modules/adb/libs": Bp2BuildDefaultTrueRecursively,
|
||||||
|
"packages/modules/adb/pairing_auth": Bp2BuildDefaultTrueRecursively,
|
||||||
|
"packages/modules/adb/pairing_connection": Bp2BuildDefaultTrueRecursively,
|
||||||
|
"packages/modules/adb/proto": Bp2BuildDefaultTrueRecursively,
|
||||||
|
"packages/modules/adb/tls": Bp2BuildDefaultTrueRecursively,
|
||||||
"prebuilts/clang/host/linux-x86": Bp2BuildDefaultTrueRecursively,
|
"prebuilts/clang/host/linux-x86": Bp2BuildDefaultTrueRecursively,
|
||||||
|
"system/core/diagnose_usb": Bp2BuildDefaultTrueRecursively,
|
||||||
"system/core/libasyncio": Bp2BuildDefaultTrue,
|
"system/core/libasyncio": Bp2BuildDefaultTrue,
|
||||||
|
"system/core/libcrypto_utils": Bp2BuildDefaultTrueRecursively,
|
||||||
"system/core/libcutils": Bp2BuildDefaultTrueRecursively,
|
"system/core/libcutils": Bp2BuildDefaultTrueRecursively,
|
||||||
"system/core/libprocessgroup": Bp2BuildDefaultTrue,
|
"system/core/libprocessgroup": Bp2BuildDefaultTrue,
|
||||||
"system/core/property_service/libpropertyinfoparser": Bp2BuildDefaultTrueRecursively,
|
"system/core/property_service/libpropertyinfoparser": Bp2BuildDefaultTrueRecursively,
|
||||||
@@ -212,8 +223,8 @@ var (
|
|||||||
"libc_malloc_debug", // http://b/186824339, cc_library_static, depends on //system/libbase:libbase (http://b/186823646)
|
"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)
|
"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", // 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)
|
//"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)
|
"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/libziparchive:libziparchive (http://b/186823656)
|
||||||
@@ -232,15 +243,13 @@ var (
|
|||||||
"libbase_ndk", // http://b/186826477, cc_library, no such target '//build/bazel/platforms/os:darwin' when --platforms //build/bazel/platforms:android_x86 is added
|
"libbase_ndk", // http://b/186826477, cc_library, no such target '//build/bazel/platforms/os:darwin' when --platforms //build/bazel/platforms:android_x86 is added
|
||||||
// libcxx
|
// libcxx
|
||||||
"libBionicBenchmarksUtils", // cc_library_static, fatal error: 'map' file not found, from libcxx
|
"libBionicBenchmarksUtils", // cc_library_static, fatal error: 'map' file not found, from libcxx
|
||||||
"libbase", // Depends on fmtlib via static_libs and also whole_static_libs, which results in bazel errors.
|
|
||||||
|
|
||||||
"libfdtrack", // depends on liblzma and libbase
|
|
||||||
|
|
||||||
"libprotobuf-python", // contains .proto sources
|
"libprotobuf-python", // contains .proto sources
|
||||||
"libprotobuf-internal-protos", // we don't handle path property for fileegroups
|
"libprotobuf-internal-protos", // we don't handle path property for fileegroups
|
||||||
"libprotobuf-internal-python-srcs", // we don't handle path property for fileegroups
|
"libprotobuf-internal-python-srcs", // we don't handle path property for fileegroups
|
||||||
|
|
||||||
"libseccomp_policy", // depends on libbase
|
"libseccomp_policy", // b/201094425: depends on func_to_syscall_nrs, which depends on py_binary, which is unsupported in mixed builds.
|
||||||
|
"libfdtrack", // depends on libunwindstack, which depends on unsupported module art_cc_library_statics
|
||||||
|
|
||||||
"gwp_asan_crash_handler", // cc_library, ld.lld: error: undefined symbol: memset
|
"gwp_asan_crash_handler", // cc_library, ld.lld: error: undefined symbol: memset
|
||||||
|
|
||||||
@@ -262,6 +271,20 @@ var (
|
|||||||
|
|
||||||
// APEX support
|
// APEX support
|
||||||
"com.android.runtime", // http://b/194746715, apex, depends on 'libc_malloc_debug' and 'libc_malloc_hooks'
|
"com.android.runtime", // http://b/194746715, apex, depends on 'libc_malloc_debug' and 'libc_malloc_hooks'
|
||||||
|
|
||||||
|
"libadb_crypto", // Depends on libadb_protos
|
||||||
|
"libadb_crypto_static", // Depends on libadb_protos_static
|
||||||
|
"libadb_pairing_connection", // Depends on libadb_protos
|
||||||
|
"libadb_pairing_connection_static", // Depends on libadb_protos_static
|
||||||
|
"libadb_pairing_server", // Depends on libadb_protos
|
||||||
|
"libadb_pairing_server_static", // Depends on libadb_protos_static
|
||||||
|
"libadbd", // Depends on libadbd_core
|
||||||
|
"libadbd_core", // Depends on libadb_protos
|
||||||
|
"libadbd_services", // Depends on libadb_protos
|
||||||
|
|
||||||
|
"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
|
||||||
}
|
}
|
||||||
|
|
||||||
// Per-module denylist of cc_library modules to only generate the static
|
// Per-module denylist of cc_library modules to only generate the static
|
||||||
|
@@ -71,6 +71,7 @@ func TestCcObjectSimple(t *testing.T) {
|
|||||||
".",
|
".",
|
||||||
],
|
],
|
||||||
srcs = ["a/b/c.c"],
|
srcs = ["a/b/c.c"],
|
||||||
|
system_dynamic_deps = [],
|
||||||
)`,
|
)`,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -116,6 +117,7 @@ cc_defaults {
|
|||||||
],
|
],
|
||||||
local_includes = ["."],
|
local_includes = ["."],
|
||||||
srcs = ["a/b/c.c"],
|
srcs = ["a/b/c.c"],
|
||||||
|
system_dynamic_deps = [],
|
||||||
)`,
|
)`,
|
||||||
}})
|
}})
|
||||||
}
|
}
|
||||||
@@ -149,11 +151,13 @@ cc_object {
|
|||||||
name = "bar",
|
name = "bar",
|
||||||
copts = ["-fno-addrsig"],
|
copts = ["-fno-addrsig"],
|
||||||
srcs = ["x/y/z.c"],
|
srcs = ["x/y/z.c"],
|
||||||
|
system_dynamic_deps = [],
|
||||||
)`, `cc_object(
|
)`, `cc_object(
|
||||||
name = "foo",
|
name = "foo",
|
||||||
copts = ["-fno-addrsig"],
|
copts = ["-fno-addrsig"],
|
||||||
deps = [":bar"],
|
deps = [":bar"],
|
||||||
srcs = ["a/b/c.c"],
|
srcs = ["a/b/c.c"],
|
||||||
|
system_dynamic_deps = [],
|
||||||
)`,
|
)`,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -180,6 +184,7 @@ func TestCcObjectIncludeBuildDirFalse(t *testing.T) {
|
|||||||
name = "foo",
|
name = "foo",
|
||||||
copts = ["-fno-addrsig"],
|
copts = ["-fno-addrsig"],
|
||||||
srcs = ["a/b/c.c"],
|
srcs = ["a/b/c.c"],
|
||||||
|
system_dynamic_deps = [],
|
||||||
)`,
|
)`,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -211,6 +216,7 @@ func TestCcObjectProductVariable(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
copts = ["-fno-addrsig"],
|
copts = ["-fno-addrsig"],
|
||||||
srcs_as = ["src.S"],
|
srcs_as = ["src.S"],
|
||||||
|
system_dynamic_deps = [],
|
||||||
)`,
|
)`,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -248,6 +254,7 @@ func TestCcObjectCflagsOneArch(t *testing.T) {
|
|||||||
"//build/bazel/platforms/arch:arm": ["arch/arm/file.cpp"],
|
"//build/bazel/platforms/arch:arm": ["arch/arm/file.cpp"],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
}),
|
}),
|
||||||
|
system_dynamic_deps = [],
|
||||||
)`,
|
)`,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -301,30 +308,126 @@ func TestCcObjectCflagsFourArch(t *testing.T) {
|
|||||||
"//build/bazel/platforms/arch:x86_64": ["x86_64.cpp"],
|
"//build/bazel/platforms/arch:x86_64": ["x86_64.cpp"],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
}),
|
}),
|
||||||
|
system_dynamic_deps = [],
|
||||||
)`,
|
)`,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCcObjectCflagsMultiOs(t *testing.T) {
|
func TestCcObjectLinkerScript(t *testing.T) {
|
||||||
runCcObjectTestCase(t, bp2buildTestCase{
|
runCcObjectTestCase(t, bp2buildTestCase{
|
||||||
description: "cc_object setting cflags for multiple OSes",
|
description: "cc_object setting linker_script",
|
||||||
moduleTypeUnderTest: "cc_object",
|
moduleTypeUnderTest: "cc_object",
|
||||||
moduleTypeUnderTestFactory: cc.ObjectFactory,
|
moduleTypeUnderTestFactory: cc.ObjectFactory,
|
||||||
moduleTypeUnderTestBp2BuildMutator: cc.ObjectBp2Build,
|
moduleTypeUnderTestBp2BuildMutator: cc.ObjectBp2Build,
|
||||||
blueprint: `cc_object {
|
blueprint: `cc_object {
|
||||||
name: "foo",
|
name: "foo",
|
||||||
|
srcs: ["base.cpp"],
|
||||||
|
linker_script: "bunny.lds",
|
||||||
|
include_build_directory: false,
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
expectedBazelTargets: []string{
|
||||||
|
`cc_object(
|
||||||
|
name = "foo",
|
||||||
|
copts = ["-fno-addrsig"],
|
||||||
|
linker_script = "bunny.lds",
|
||||||
|
srcs = ["base.cpp"],
|
||||||
|
)`,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCcObjectDepsAndLinkerScriptSelects(t *testing.T) {
|
||||||
|
runCcObjectTestCase(t, bp2buildTestCase{
|
||||||
|
description: "cc_object setting deps and linker_script across archs",
|
||||||
|
moduleTypeUnderTest: "cc_object",
|
||||||
|
moduleTypeUnderTestFactory: cc.ObjectFactory,
|
||||||
|
moduleTypeUnderTestBp2BuildMutator: cc.ObjectBp2Build,
|
||||||
|
blueprint: `cc_object {
|
||||||
|
name: "foo",
|
||||||
|
srcs: ["base.cpp"],
|
||||||
|
arch: {
|
||||||
|
x86: {
|
||||||
|
objs: ["x86_obj"],
|
||||||
|
linker_script: "x86.lds",
|
||||||
|
},
|
||||||
|
x86_64: {
|
||||||
|
objs: ["x86_64_obj"],
|
||||||
|
linker_script: "x86_64.lds",
|
||||||
|
},
|
||||||
|
arm: {
|
||||||
|
objs: ["arm_obj"],
|
||||||
|
linker_script: "arm.lds",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
include_build_directory: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_object {
|
||||||
|
name: "x86_obj",
|
||||||
system_shared_libs: [],
|
system_shared_libs: [],
|
||||||
|
srcs: ["x86.cpp"],
|
||||||
|
include_build_directory: false,
|
||||||
|
bazel_module: { bp2build_available: false },
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_object {
|
||||||
|
name: "x86_64_obj",
|
||||||
|
system_shared_libs: [],
|
||||||
|
srcs: ["x86_64.cpp"],
|
||||||
|
include_build_directory: false,
|
||||||
|
bazel_module: { bp2build_available: false },
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_object {
|
||||||
|
name: "arm_obj",
|
||||||
|
system_shared_libs: [],
|
||||||
|
srcs: ["arm.cpp"],
|
||||||
|
include_build_directory: false,
|
||||||
|
bazel_module: { bp2build_available: false },
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
expectedBazelTargets: []string{
|
||||||
|
`cc_object(
|
||||||
|
name = "foo",
|
||||||
|
copts = ["-fno-addrsig"],
|
||||||
|
deps = select({
|
||||||
|
"//build/bazel/platforms/arch:arm": [":arm_obj"],
|
||||||
|
"//build/bazel/platforms/arch:x86": [":x86_obj"],
|
||||||
|
"//build/bazel/platforms/arch:x86_64": [":x86_64_obj"],
|
||||||
|
"//conditions:default": [],
|
||||||
|
}),
|
||||||
|
linker_script = select({
|
||||||
|
"//build/bazel/platforms/arch:arm": "arm.lds",
|
||||||
|
"//build/bazel/platforms/arch:x86": "x86.lds",
|
||||||
|
"//build/bazel/platforms/arch:x86_64": "x86_64.lds",
|
||||||
|
"//conditions:default": None,
|
||||||
|
}),
|
||||||
|
srcs = ["base.cpp"],
|
||||||
|
)`,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCcObjectSelectOnLinuxAndBionicArchs(t *testing.T) {
|
||||||
|
runCcObjectTestCase(t, bp2buildTestCase{
|
||||||
|
description: "cc_object setting srcs based on linux and bionic archs",
|
||||||
|
moduleTypeUnderTest: "cc_object",
|
||||||
|
moduleTypeUnderTestFactory: cc.ObjectFactory,
|
||||||
|
moduleTypeUnderTestBp2BuildMutator: cc.ObjectBp2Build,
|
||||||
|
blueprint: `cc_object {
|
||||||
|
name: "foo",
|
||||||
srcs: ["base.cpp"],
|
srcs: ["base.cpp"],
|
||||||
target: {
|
target: {
|
||||||
android: {
|
linux_arm64: {
|
||||||
cflags: ["-fPIC"],
|
srcs: ["linux_arm64.cpp",]
|
||||||
},
|
},
|
||||||
windows: {
|
linux_x86: {
|
||||||
cflags: ["-fPIC"],
|
srcs: ["linux_x86.cpp",]
|
||||||
},
|
},
|
||||||
darwin: {
|
bionic_arm64: {
|
||||||
cflags: ["-Wall"],
|
srcs: ["bionic_arm64.cpp",]
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
include_build_directory: false,
|
include_build_directory: false,
|
||||||
@@ -333,13 +436,21 @@ func TestCcObjectCflagsMultiOs(t *testing.T) {
|
|||||||
expectedBazelTargets: []string{
|
expectedBazelTargets: []string{
|
||||||
`cc_object(
|
`cc_object(
|
||||||
name = "foo",
|
name = "foo",
|
||||||
copts = ["-fno-addrsig"] + select({
|
copts = ["-fno-addrsig"],
|
||||||
"//build/bazel/platforms/os:android": ["-fPIC"],
|
srcs = ["base.cpp"] + select({
|
||||||
"//build/bazel/platforms/os:darwin": ["-Wall"],
|
"//build/bazel/platforms/os_arch:android_arm64": [
|
||||||
"//build/bazel/platforms/os:windows": ["-fPIC"],
|
"bionic_arm64.cpp",
|
||||||
|
"linux_arm64.cpp",
|
||||||
|
],
|
||||||
|
"//build/bazel/platforms/os_arch:android_x86": ["linux_x86.cpp"],
|
||||||
|
"//build/bazel/platforms/os_arch:linux_bionic_arm64": [
|
||||||
|
"bionic_arm64.cpp",
|
||||||
|
"linux_arm64.cpp",
|
||||||
|
],
|
||||||
|
"//build/bazel/platforms/os_arch:linux_glibc_x86": ["linux_x86.cpp"],
|
||||||
|
"//build/bazel/platforms/os_arch:linux_musl_x86": ["linux_x86.cpp"],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
}),
|
}),
|
||||||
srcs = ["base.cpp"],
|
|
||||||
)`,
|
)`,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
26
cc/object.go
26
cc/object.go
@@ -126,10 +126,13 @@ type bazelObjectAttributes struct {
|
|||||||
Srcs_as bazel.LabelListAttribute
|
Srcs_as bazel.LabelListAttribute
|
||||||
Hdrs bazel.LabelListAttribute
|
Hdrs bazel.LabelListAttribute
|
||||||
Deps bazel.LabelListAttribute
|
Deps bazel.LabelListAttribute
|
||||||
|
System_dynamic_deps bazel.LabelListAttribute
|
||||||
Copts bazel.StringListAttribute
|
Copts bazel.StringListAttribute
|
||||||
Asflags bazel.StringListAttribute
|
Asflags bazel.StringListAttribute
|
||||||
Local_includes bazel.StringListAttribute
|
Local_includes bazel.StringListAttribute
|
||||||
Absolute_includes bazel.StringListAttribute
|
Absolute_includes bazel.StringListAttribute
|
||||||
|
Stl *string
|
||||||
|
Linker_script bazel.LabelAttribute
|
||||||
}
|
}
|
||||||
|
|
||||||
// ObjectBp2Build is the bp2build converter from cc_object modules to the
|
// ObjectBp2Build is the bp2build converter from cc_object modules to the
|
||||||
@@ -153,12 +156,26 @@ func ObjectBp2Build(ctx android.TopDownMutatorContext) {
|
|||||||
// Set arch-specific configurable attributes
|
// Set arch-specific configurable attributes
|
||||||
compilerAttrs := bp2BuildParseCompilerProps(ctx, m)
|
compilerAttrs := bp2BuildParseCompilerProps(ctx, m)
|
||||||
var deps bazel.LabelListAttribute
|
var deps bazel.LabelListAttribute
|
||||||
for _, props := range m.linker.linkerProps() {
|
systemDynamicDeps := bazel.LabelListAttribute{ForceSpecifyEmptyList: true}
|
||||||
|
|
||||||
|
var linkerScript bazel.LabelAttribute
|
||||||
|
|
||||||
|
for axis, configToProps := range m.GetArchVariantProperties(ctx, &ObjectLinkerProperties{}) {
|
||||||
|
for config, props := range configToProps {
|
||||||
if objectLinkerProps, ok := props.(*ObjectLinkerProperties); ok {
|
if objectLinkerProps, ok := props.(*ObjectLinkerProperties); ok {
|
||||||
deps = bazel.MakeLabelListAttribute(
|
if objectLinkerProps.Linker_script != nil {
|
||||||
android.BazelLabelForModuleDeps(ctx, objectLinkerProps.Objs))
|
linkerScript.SetSelectValue(axis, config, android.BazelLabelForModuleSrcSingle(ctx, *objectLinkerProps.Linker_script))
|
||||||
|
}
|
||||||
|
deps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, objectLinkerProps.Objs))
|
||||||
|
systemSharedLibs := objectLinkerProps.System_shared_libs
|
||||||
|
if len(systemSharedLibs) > 0 {
|
||||||
|
systemSharedLibs = android.FirstUniqueStrings(systemSharedLibs)
|
||||||
|
}
|
||||||
|
systemDynamicDeps.SetSelectValue(axis, config, bazelLabelForSharedDeps(ctx, systemSharedLibs))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
deps.ResolveExcludes()
|
||||||
|
|
||||||
// Don't split cc_object srcs across languages. Doing so would add complexity,
|
// Don't split cc_object srcs across languages. Doing so would add complexity,
|
||||||
// and this isn't typically done for cc_object.
|
// and this isn't typically done for cc_object.
|
||||||
@@ -175,10 +192,13 @@ func ObjectBp2Build(ctx android.TopDownMutatorContext) {
|
|||||||
Srcs: srcs,
|
Srcs: srcs,
|
||||||
Srcs_as: compilerAttrs.asSrcs,
|
Srcs_as: compilerAttrs.asSrcs,
|
||||||
Deps: deps,
|
Deps: deps,
|
||||||
|
System_dynamic_deps: systemDynamicDeps,
|
||||||
Copts: compilerAttrs.copts,
|
Copts: compilerAttrs.copts,
|
||||||
Asflags: asFlags,
|
Asflags: asFlags,
|
||||||
Local_includes: compilerAttrs.localIncludes,
|
Local_includes: compilerAttrs.localIncludes,
|
||||||
Absolute_includes: compilerAttrs.absoluteIncludes,
|
Absolute_includes: compilerAttrs.absoluteIncludes,
|
||||||
|
Stl: compilerAttrs.stl,
|
||||||
|
Linker_script: linkerScript,
|
||||||
}
|
}
|
||||||
|
|
||||||
props := bazel.BazelTargetModuleProperties{
|
props := bazel.BazelTargetModuleProperties{
|
||||||
|
Reference in New Issue
Block a user