Remove apex_available tag in cc_library_static generated from stubs-providing lib
When a cc library has stubs, its static variant shouldn't be included in an apex to ensure the library with stubs isn't statically linked. See https://cs.android.com/android/platform/superproject/+/master:build/soong/apex/apex.go;l=2804;drc=89b01aeaa9e19377ff547baab791277719b8aaf3
This CL modifies bp2build so that it excludes apex_available tag from the static target if the library has stubs. This way, we can ensure that no apex can depend on the static target which results to static linking.
Test: go test
Bug: 255589949
Change-Id: Iedf248994b808436f2440570b094fd06d6284ae9
diff --git a/bp2build/apex_conversion_test.go b/bp2build/apex_conversion_test.go
index 714b848..1c0e563 100644
--- a/bp2build/apex_conversion_test.go
+++ b/bp2build/apex_conversion_test.go
@@ -1146,6 +1146,76 @@
}})
}
+func TestApexWithStubLib(t *testing.T) {
+ runApexTestCase(t, Bp2buildTestCase{
+ Description: "apex - static variant of stub lib should not have apex_available tag",
+ ModuleTypeUnderTest: "apex",
+ ModuleTypeUnderTestFactory: apex.BundleFactory,
+ Filesystem: map[string]string{},
+ Blueprint: `
+cc_library{
+ name: "foo",
+ stubs: { symbol_file: "foo.map.txt", versions: ["28", "29", "current"] },
+ apex_available: ["myapex"],
+}
+
+cc_binary{
+ name: "bar",
+ static_libs: ["foo"],
+ apex_available: ["myapex"],
+}
+
+apex {
+ name: "myapex",
+ manifest: "myapex_manifest.json",
+ file_contexts: ":myapex-file_contexts",
+ binaries: ["bar"],
+ native_shared_libs: ["foo"],
+}
+` + simpleModuleDoNotConvertBp2build("filegroup", "myapex-file_contexts"),
+ ExpectedBazelTargets: []string{
+ MakeBazelTarget("cc_binary", "bar", AttrNameToString{
+ "local_includes": `["."]`,
+ "deps": `[":foo_bp2build_cc_library_static"]`,
+ "tags": `["apex_available=myapex"]`,
+ }),
+ MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
+ "local_includes": `["."]`,
+ }),
+ MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
+ "local_includes": `["."]`,
+ "stubs_symbol_file": `"foo.map.txt"`,
+ "tags": `["apex_available=myapex"]`,
+ }),
+ MakeBazelTarget("cc_stub_suite", "foo_stub_libs", AttrNameToString{
+ "soname": `"foo.so"`,
+ "source_library": `":foo"`,
+ "symbol_file": `"foo.map.txt"`,
+ "versions": `[
+ "28",
+ "29",
+ "current",
+ ]`,
+ }),
+ MakeBazelTarget("apex", "myapex", AttrNameToString{
+ "file_contexts": `":myapex-file_contexts"`,
+ "manifest": `"myapex_manifest.json"`,
+ "binaries": `[":bar"]`,
+ "native_shared_libs_32": `select({
+ "//build/bazel/platforms/arch:arm": [":foo"],
+ "//build/bazel/platforms/arch:x86": [":foo"],
+ "//conditions:default": [],
+ })`,
+ "native_shared_libs_64": `select({
+ "//build/bazel/platforms/arch:arm64": [":foo"],
+ "//build/bazel/platforms/arch:x86_64": [":foo"],
+ "//conditions:default": [],
+ })`,
+ }),
+ },
+ })
+}
+
func TestApexCertificateIsSrc(t *testing.T) {
runApexTestCase(t, Bp2buildTestCase{
Description: "apex - certificate is src",