Merge "Default apex's compile_multilib to "first" in bp2build" am: 827db14152

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2243697

Change-Id: I6ffdf6e089443358751840e99981184ddd4d6a8c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Vinh Tran
2022-10-17 14:37:59 +00:00
committed by Automerger Merge Worker
3 changed files with 156 additions and 38 deletions

View File

@@ -3391,7 +3391,12 @@ func convertWithBp2build(a *apexBundle, ctx android.TopDownMutatorContext) (baze
Native_shared_libs_32: bazel.LabelListAttribute{}, Native_shared_libs_32: bazel.LabelListAttribute{},
Native_shared_libs_64: bazel.LabelListAttribute{}, Native_shared_libs_64: bazel.LabelListAttribute{},
} }
compileMultilib := "both"
// https://cs.android.com/android/platform/superproject/+/master:build/soong/android/arch.go;l=698;drc=f05b0d35d2fbe51be9961ce8ce8031f840295c68
// https://cs.android.com/android/platform/superproject/+/master:build/soong/apex/apex.go;l=2549;drc=ec731a83e3e2d80a1254e32fd4ad7ef85e262669
// In Soong, decodeMultilib, used to get multilib, return "first" if defaultMultilib is set to "common".
// Since apex sets defaultMultilib to be "common", equivalent compileMultilib in bp2build for apex should be "first"
compileMultilib := "first"
if a.CompileMultilib() != nil { if a.CompileMultilib() != nil {
compileMultilib = *a.CompileMultilib() compileMultilib = *a.CompileMultilib()
} }

View File

@@ -4130,6 +4130,76 @@ func TestApexName(t *testing.T) {
ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n") ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n")
} }
func TestCompileMultilibProp(t *testing.T) {
testCases := []struct {
compileMultiLibProp string
containedLibs []string
notContainedLibs []string
}{
{
containedLibs: []string{
"image.apex/lib64/mylib.so",
"image.apex/lib/mylib.so",
},
compileMultiLibProp: `compile_multilib: "both",`,
},
{
containedLibs: []string{"image.apex/lib64/mylib.so"},
notContainedLibs: []string{"image.apex/lib/mylib.so"},
compileMultiLibProp: `compile_multilib: "first",`,
},
{
containedLibs: []string{"image.apex/lib64/mylib.so"},
notContainedLibs: []string{"image.apex/lib/mylib.so"},
// compile_multilib, when unset, should result to the same output as when compile_multilib is "first"
},
{
containedLibs: []string{"image.apex/lib64/mylib.so"},
notContainedLibs: []string{"image.apex/lib/mylib.so"},
compileMultiLibProp: `compile_multilib: "64",`,
},
{
containedLibs: []string{"image.apex/lib/mylib.so"},
notContainedLibs: []string{"image.apex/lib64/mylib.so"},
compileMultiLibProp: `compile_multilib: "32",`,
},
}
for _, testCase := range testCases {
ctx := testApex(t, fmt.Sprintf(`
apex {
name: "myapex",
key: "myapex.key",
%s
native_shared_libs: ["mylib"],
updatable: false,
}
apex_key {
name: "myapex.key",
public_key: "testkey.avbpubkey",
private_key: "testkey.pem",
}
cc_library {
name: "mylib",
srcs: ["mylib.cpp"],
apex_available: [
"//apex_available:platform",
"myapex",
],
}
`, testCase.compileMultiLibProp),
)
module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
apexRule := module.Rule("apexRule")
copyCmds := apexRule.Args["copy_commands"]
for _, containedLib := range testCase.containedLibs {
ensureContains(t, copyCmds, containedLib)
}
for _, notContainedLib := range testCase.notContainedLibs {
ensureNotContains(t, copyCmds, notContainedLib)
}
}
}
func TestNonTestApex(t *testing.T) { func TestNonTestApex(t *testing.T) {
ctx := testApex(t, ` ctx := testApex(t, `
apex { apex {

View File

@@ -22,6 +22,7 @@ import (
"android/soong/java" "android/soong/java"
"android/soong/sh" "android/soong/sh"
"fmt"
"testing" "testing"
) )
@@ -153,10 +154,17 @@ apex {
"key": `":com.android.apogee.key"`, "key": `":com.android.apogee.key"`,
"manifest": `"apogee_manifest.json"`, "manifest": `"apogee_manifest.json"`,
"min_sdk_version": `"29"`, "min_sdk_version": `"29"`,
"native_shared_libs_32": `[ "native_shared_libs_32": `select({
":native_shared_lib_1", "//build/bazel/platforms/arch:arm": [
":native_shared_lib_2", ":native_shared_lib_1",
]`, ":native_shared_lib_2",
],
"//build/bazel/platforms/arch:x86": [
":native_shared_lib_1",
":native_shared_lib_2",
],
"//conditions:default": [],
})`,
"native_shared_libs_64": `select({ "native_shared_libs_64": `select({
"//build/bazel/platforms/arch:arm64": [ "//build/bazel/platforms/arch:arm64": [
":native_shared_lib_1", ":native_shared_lib_1",
@@ -273,10 +281,11 @@ filegroup {
} }
`, `,
}, },
Blueprint: createMultilibBlueprint("both"), Blueprint: createMultilibBlueprint(`compile_multilib: "both",`),
ExpectedBazelTargets: []string{ ExpectedBazelTargets: []string{
MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
"native_shared_libs_32": `[ "native_shared_libs_32": `[
":unnested_native_shared_lib",
":native_shared_lib_for_both", ":native_shared_lib_for_both",
":native_shared_lib_for_lib32", ":native_shared_lib_for_lib32",
] + select({ ] + select({
@@ -286,11 +295,13 @@ filegroup {
})`, })`,
"native_shared_libs_64": `select({ "native_shared_libs_64": `select({
"//build/bazel/platforms/arch:arm64": [ "//build/bazel/platforms/arch:arm64": [
":unnested_native_shared_lib",
":native_shared_lib_for_both", ":native_shared_lib_for_both",
":native_shared_lib_for_lib64", ":native_shared_lib_for_lib64",
":native_shared_lib_for_first", ":native_shared_lib_for_first",
], ],
"//build/bazel/platforms/arch:x86_64": [ "//build/bazel/platforms/arch:x86_64": [
":unnested_native_shared_lib",
":native_shared_lib_for_both", ":native_shared_lib_for_both",
":native_shared_lib_for_lib64", ":native_shared_lib_for_lib64",
":native_shared_lib_for_first", ":native_shared_lib_for_first",
@@ -303,53 +314,69 @@ filegroup {
}}) }})
} }
func TestApexBundleCompileMultilibFirst(t *testing.T) { func TestApexBundleCompileMultilibFirstAndDefaultValue(t *testing.T) {
runApexTestCase(t, Bp2buildTestCase{ expectedBazelTargets := []string{
Description: "apex - example with compile_multilib=first", MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
ModuleTypeUnderTest: "apex", "native_shared_libs_32": `select({
ModuleTypeUnderTestFactory: apex.BundleFactory,
Filesystem: map[string]string{
"system/sepolicy/apex/Android.bp": `
filegroup {
name: "com.android.apogee-file_contexts",
srcs: [ "apogee-file_contexts", ],
bazel_module: { bp2build_available: false },
}
`,
},
Blueprint: createMultilibBlueprint("first"),
ExpectedBazelTargets: []string{
MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
"native_shared_libs_32": `select({
"//build/bazel/platforms/arch:arm": [ "//build/bazel/platforms/arch:arm": [
":unnested_native_shared_lib",
":native_shared_lib_for_both", ":native_shared_lib_for_both",
":native_shared_lib_for_lib32", ":native_shared_lib_for_lib32",
":native_shared_lib_for_first", ":native_shared_lib_for_first",
], ],
"//build/bazel/platforms/arch:x86": [ "//build/bazel/platforms/arch:x86": [
":unnested_native_shared_lib",
":native_shared_lib_for_both", ":native_shared_lib_for_both",
":native_shared_lib_for_lib32", ":native_shared_lib_for_lib32",
":native_shared_lib_for_first", ":native_shared_lib_for_first",
], ],
"//conditions:default": [], "//conditions:default": [],
})`, })`,
"native_shared_libs_64": `select({ "native_shared_libs_64": `select({
"//build/bazel/platforms/arch:arm64": [ "//build/bazel/platforms/arch:arm64": [
":unnested_native_shared_lib",
":native_shared_lib_for_both", ":native_shared_lib_for_both",
":native_shared_lib_for_lib64", ":native_shared_lib_for_lib64",
":native_shared_lib_for_first", ":native_shared_lib_for_first",
], ],
"//build/bazel/platforms/arch:x86_64": [ "//build/bazel/platforms/arch:x86_64": [
":unnested_native_shared_lib",
":native_shared_lib_for_both", ":native_shared_lib_for_both",
":native_shared_lib_for_lib64", ":native_shared_lib_for_lib64",
":native_shared_lib_for_first", ":native_shared_lib_for_first",
], ],
"//conditions:default": [], "//conditions:default": [],
})`, })`,
"file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
"manifest": `"apex_manifest.json"`, "manifest": `"apex_manifest.json"`,
}), }),
}}) }
// "first" is the default value of compile_multilib prop so `compile_multilib_: "first"` and unset compile_multilib
// should result to the same bp2build output
compileMultiLibPropValues := []string{`compile_multilib: "first",`, ""}
for _, compileMultiLibProp := range compileMultiLibPropValues {
descriptionSuffix := compileMultiLibProp
if descriptionSuffix == "" {
descriptionSuffix = "compile_multilib unset"
}
runApexTestCase(t, Bp2buildTestCase{
Description: "apex - example with " + compileMultiLibProp,
ModuleTypeUnderTest: "apex",
ModuleTypeUnderTestFactory: apex.BundleFactory,
Filesystem: map[string]string{
"system/sepolicy/apex/Android.bp": `
filegroup {
name: "com.android.apogee-file_contexts",
srcs: [ "apogee-file_contexts", ],
bazel_module: { bp2build_available: false },
}
`,
},
Blueprint: createMultilibBlueprint(compileMultiLibProp),
ExpectedBazelTargets: expectedBazelTargets,
})
}
} }
func TestApexBundleCompileMultilib32(t *testing.T) { func TestApexBundleCompileMultilib32(t *testing.T) {
@@ -366,10 +393,11 @@ filegroup {
} }
`, `,
}, },
Blueprint: createMultilibBlueprint("32"), Blueprint: createMultilibBlueprint(`compile_multilib: "32",`),
ExpectedBazelTargets: []string{ ExpectedBazelTargets: []string{
MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
"native_shared_libs_32": `[ "native_shared_libs_32": `[
":unnested_native_shared_lib",
":native_shared_lib_for_both", ":native_shared_lib_for_both",
":native_shared_lib_for_lib32", ":native_shared_lib_for_lib32",
] + select({ ] + select({
@@ -397,16 +425,18 @@ filegroup {
} }
`, `,
}, },
Blueprint: createMultilibBlueprint("64"), Blueprint: createMultilibBlueprint(`compile_multilib: "64",`),
ExpectedBazelTargets: []string{ ExpectedBazelTargets: []string{
MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
"native_shared_libs_64": `select({ "native_shared_libs_64": `select({
"//build/bazel/platforms/arch:arm64": [ "//build/bazel/platforms/arch:arm64": [
":unnested_native_shared_lib",
":native_shared_lib_for_both", ":native_shared_lib_for_both",
":native_shared_lib_for_lib64", ":native_shared_lib_for_lib64",
":native_shared_lib_for_first", ":native_shared_lib_for_first",
], ],
"//build/bazel/platforms/arch:x86_64": [ "//build/bazel/platforms/arch:x86_64": [
":unnested_native_shared_lib",
":native_shared_lib_for_both", ":native_shared_lib_for_both",
":native_shared_lib_for_lib64", ":native_shared_lib_for_lib64",
":native_shared_lib_for_first", ":native_shared_lib_for_first",
@@ -420,7 +450,7 @@ filegroup {
} }
func createMultilibBlueprint(compile_multilib string) string { func createMultilibBlueprint(compile_multilib string) string {
return ` return fmt.Sprintf(`
cc_library { cc_library {
name: "native_shared_lib_for_both", name: "native_shared_lib_for_both",
bazel_module: { bp2build_available: false }, bazel_module: { bp2build_available: false },
@@ -441,9 +471,15 @@ cc_library {
bazel_module: { bp2build_available: false }, bazel_module: { bp2build_available: false },
} }
cc_library {
name: "unnested_native_shared_lib",
bazel_module: { bp2build_available: false },
}
apex { apex {
name: "com.android.apogee", name: "com.android.apogee",
compile_multilib: "` + compile_multilib + `", %s
native_shared_libs: ["unnested_native_shared_lib"],
multilib: { multilib: {
both: { both: {
native_shared_libs: [ native_shared_libs: [
@@ -466,7 +502,7 @@ apex {
], ],
}, },
}, },
}` }`, compile_multilib)
} }
func TestApexBundleDefaultPropertyValues(t *testing.T) { func TestApexBundleDefaultPropertyValues(t *testing.T) {
@@ -636,10 +672,17 @@ override_apex {
"key": `":com.google.android.apogee.key"`, "key": `":com.google.android.apogee.key"`,
"manifest": `"apogee_manifest.json"`, "manifest": `"apogee_manifest.json"`,
"min_sdk_version": `"29"`, "min_sdk_version": `"29"`,
"native_shared_libs_32": `[ "native_shared_libs_32": `select({
":native_shared_lib_1", "//build/bazel/platforms/arch:arm": [
":native_shared_lib_2", ":native_shared_lib_1",
]`, ":native_shared_lib_2",
],
"//build/bazel/platforms/arch:x86": [
":native_shared_lib_1",
":native_shared_lib_2",
],
"//conditions:default": [],
})`,
"native_shared_libs_64": `select({ "native_shared_libs_64": `select({
"//build/bazel/platforms/arch:arm64": [ "//build/bazel/platforms/arch:arm64": [
":native_shared_lib_1", ":native_shared_lib_1",