Support multilib in apex.

Bug: b/208325023
Test: Added unit tests, also tested with adbd apex build manually.
Change-Id: I47e04cd4eb5d05227f0a84683dcb66dff00e3514
This commit is contained in:
Yu Liu
2022-01-05 17:17:23 -08:00
parent 8f5399889b
commit 4ae55d17f6
3 changed files with 334 additions and 26 deletions

View File

@@ -131,10 +131,21 @@ apex {
"key": `":com.android.apogee.key"`,
"manifest": `"apogee_manifest.json"`,
"min_sdk_version": `"29"`,
"native_shared_libs": `[
"native_shared_libs_32": `[
":native_shared_lib_1",
":native_shared_lib_2",
]`,
"native_shared_libs_64": `select({
"//build/bazel/platforms/arch:arm64": [
":native_shared_lib_1",
":native_shared_lib_2",
],
"//build/bazel/platforms/arch:x86_64": [
":native_shared_lib_1",
":native_shared_lib_2",
],
"//conditions:default": [],
})`,
"prebuilts": `[
":pretend_prebuilt_1",
":pretend_prebuilt_2",
@@ -144,6 +155,126 @@ apex {
}})
}
func TestApexBundleCompileMultilibBoth(t *testing.T) {
runApexTestCase(t, bp2buildTestCase{
description: "apex - example with compile_multilib=both",
moduleTypeUnderTest: "apex",
moduleTypeUnderTestFactory: apex.BundleFactory,
filesystem: map[string]string{},
blueprint: createMultilibBlueprint("both"),
expectedBazelTargets: []string{
makeBazelTarget("apex", "com.android.apogee", attrNameToString{
"native_shared_libs_32": `[
":native_shared_lib_1",
":native_shared_lib_3",
] + select({
"//build/bazel/platforms/arch:arm": [":native_shared_lib_2"],
"//build/bazel/platforms/arch:x86": [":native_shared_lib_2"],
"//conditions:default": [],
})`,
"native_shared_libs_64": `select({
"//build/bazel/platforms/arch:arm64": [
":native_shared_lib_1",
":native_shared_lib_4",
":native_shared_lib_2",
],
"//build/bazel/platforms/arch:x86_64": [
":native_shared_lib_1",
":native_shared_lib_4",
":native_shared_lib_2",
],
"//conditions:default": [],
})`,
}),
}})
}
func TestApexBundleCompileMultilibFirst(t *testing.T) {
runApexTestCase(t, bp2buildTestCase{
description: "apex - example with compile_multilib=first",
moduleTypeUnderTest: "apex",
moduleTypeUnderTestFactory: apex.BundleFactory,
filesystem: map[string]string{},
blueprint: createMultilibBlueprint("first"),
expectedBazelTargets: []string{
makeBazelTarget("apex", "com.android.apogee", attrNameToString{
"native_shared_libs_32": `select({
"//build/bazel/platforms/arch:arm": [
":native_shared_lib_1",
":native_shared_lib_3",
":native_shared_lib_2",
],
"//build/bazel/platforms/arch:x86": [
":native_shared_lib_1",
":native_shared_lib_3",
":native_shared_lib_2",
],
"//conditions:default": [],
})`,
"native_shared_libs_64": `select({
"//build/bazel/platforms/arch:arm64": [
":native_shared_lib_1",
":native_shared_lib_4",
":native_shared_lib_2",
],
"//build/bazel/platforms/arch:x86_64": [
":native_shared_lib_1",
":native_shared_lib_4",
":native_shared_lib_2",
],
"//conditions:default": [],
})`,
}),
}})
}
func TestApexBundleCompileMultilib32(t *testing.T) {
runApexTestCase(t, bp2buildTestCase{
description: "apex - example with compile_multilib=32",
moduleTypeUnderTest: "apex",
moduleTypeUnderTestFactory: apex.BundleFactory,
filesystem: map[string]string{},
blueprint: createMultilibBlueprint("32"),
expectedBazelTargets: []string{
makeBazelTarget("apex", "com.android.apogee", attrNameToString{
"native_shared_libs_32": `[
":native_shared_lib_1",
":native_shared_lib_3",
] + select({
"//build/bazel/platforms/arch:arm": [":native_shared_lib_2"],
"//build/bazel/platforms/arch:x86": [":native_shared_lib_2"],
"//conditions:default": [],
})`,
}),
}})
}
func TestApexBundleCompileMultilib64(t *testing.T) {
runApexTestCase(t, bp2buildTestCase{
description: "apex - example with compile_multilib=64",
moduleTypeUnderTest: "apex",
moduleTypeUnderTestFactory: apex.BundleFactory,
filesystem: map[string]string{},
blueprint: createMultilibBlueprint("64"),
expectedBazelTargets: []string{
makeBazelTarget("apex", "com.android.apogee", attrNameToString{
"native_shared_libs_64": `select({
"//build/bazel/platforms/arch:arm64": [
":native_shared_lib_1",
":native_shared_lib_4",
":native_shared_lib_2",
],
"//build/bazel/platforms/arch:x86_64": [
":native_shared_lib_1",
":native_shared_lib_4",
":native_shared_lib_2",
],
"//conditions:default": [],
})`,
}),
}})
}
func TestApexBundleDefaultPropertyValues(t *testing.T) {
runApexTestCase(t, bp2buildTestCase{
description: "apex - default property values",
@@ -180,3 +311,53 @@ apex {
}),
}})
}
func createMultilibBlueprint(compile_multilib string) string {
return `
cc_library {
name: "native_shared_lib_1",
bazel_module: { bp2build_available: false },
}
cc_library {
name: "native_shared_lib_2",
bazel_module: { bp2build_available: false },
}
cc_library {
name: "native_shared_lib_3",
bazel_module: { bp2build_available: false },
}
cc_library {
name: "native_shared_lib_4",
bazel_module: { bp2build_available: false },
}
apex {
name: "com.android.apogee",
compile_multilib: "` + compile_multilib + `",
multilib: {
both: {
native_shared_libs: [
"native_shared_lib_1",
],
},
first: {
native_shared_libs: [
"native_shared_lib_2",
],
},
lib32: {
native_shared_libs: [
"native_shared_lib_3",
],
},
lib64: {
native_shared_libs: [
"native_shared_lib_4",
],
},
},
}`
}