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:
Chris Parsons
2021-09-28 16:47:36 -04:00
parent dcc42b6f7e
commit a37e195182
4 changed files with 260 additions and 74 deletions

View File

@@ -71,6 +71,7 @@ func TestCcObjectSimple(t *testing.T) {
".",
],
srcs = ["a/b/c.c"],
system_dynamic_deps = [],
)`,
},
})
@@ -116,6 +117,7 @@ cc_defaults {
],
local_includes = ["."],
srcs = ["a/b/c.c"],
system_dynamic_deps = [],
)`,
}})
}
@@ -149,11 +151,13 @@ cc_object {
name = "bar",
copts = ["-fno-addrsig"],
srcs = ["x/y/z.c"],
system_dynamic_deps = [],
)`, `cc_object(
name = "foo",
copts = ["-fno-addrsig"],
deps = [":bar"],
srcs = ["a/b/c.c"],
system_dynamic_deps = [],
)`,
},
})
@@ -180,6 +184,7 @@ func TestCcObjectIncludeBuildDirFalse(t *testing.T) {
name = "foo",
copts = ["-fno-addrsig"],
srcs = ["a/b/c.c"],
system_dynamic_deps = [],
)`,
},
})
@@ -211,6 +216,7 @@ func TestCcObjectProductVariable(t *testing.T) {
}),
copts = ["-fno-addrsig"],
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"],
"//conditions:default": [],
}),
system_dynamic_deps = [],
)`,
},
})
@@ -301,30 +308,126 @@ func TestCcObjectCflagsFourArch(t *testing.T) {
"//build/bazel/platforms/arch:x86_64": ["x86_64.cpp"],
"//conditions:default": [],
}),
system_dynamic_deps = [],
)`,
},
})
}
func TestCcObjectCflagsMultiOs(t *testing.T) {
func TestCcObjectLinkerScript(t *testing.T) {
runCcObjectTestCase(t, bp2buildTestCase{
description: "cc_object setting cflags for multiple OSes",
description: "cc_object setting linker_script",
moduleTypeUnderTest: "cc_object",
moduleTypeUnderTestFactory: cc.ObjectFactory,
moduleTypeUnderTestBp2BuildMutator: cc.ObjectBp2Build,
blueprint: `cc_object {
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: [],
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"],
target: {
android: {
cflags: ["-fPIC"],
linux_arm64: {
srcs: ["linux_arm64.cpp",]
},
windows: {
cflags: ["-fPIC"],
linux_x86: {
srcs: ["linux_x86.cpp",]
},
darwin: {
cflags: ["-Wall"],
bionic_arm64: {
srcs: ["bionic_arm64.cpp",]
},
},
include_build_directory: false,
@@ -333,13 +436,21 @@ func TestCcObjectCflagsMultiOs(t *testing.T) {
expectedBazelTargets: []string{
`cc_object(
name = "foo",
copts = ["-fno-addrsig"] + select({
"//build/bazel/platforms/os:android": ["-fPIC"],
"//build/bazel/platforms/os:darwin": ["-Wall"],
"//build/bazel/platforms/os:windows": ["-fPIC"],
copts = ["-fno-addrsig"],
srcs = ["base.cpp"] + select({
"//build/bazel/platforms/os_arch:android_arm64": [
"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": [],
}),
srcs = ["base.cpp"],
)`,
},
})