bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go
index 8dcba55..bff192f 100644
--- a/bp2build/cc_library_conversion_test.go
+++ b/bp2build/cc_library_conversion_test.go
@@ -1454,3 +1454,213 @@
)`},
})
}
+
+func TestCcLibrary_SystemSharedLibsRootEmpty(t *testing.T) {
+ runCcLibraryTestCase(t, bp2buildTestCase{
+ description: "cc_library system_shared_libs empty at root",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
+ moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ blueprint: soongCcLibraryPreamble + `
+cc_library {
+ name: "root_empty",
+ system_shared_libs: [],
+}
+`,
+ expectedBazelTargets: []string{`cc_library(
+ name = "root_empty",
+ copts = [
+ "-I.",
+ "-I$(BINDIR)/.",
+ ],
+ system_dynamic_deps = [],
+)`},
+ })
+}
+
+func TestCcLibrary_SystemSharedLibsStaticEmpty(t *testing.T) {
+ runCcLibraryTestCase(t, bp2buildTestCase{
+ description: "cc_library system_shared_libs empty for static variant",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
+ moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ blueprint: soongCcLibraryPreamble + `
+cc_library {
+ name: "static_empty",
+ static: {
+ system_shared_libs: [],
+ },
+}
+`,
+ expectedBazelTargets: []string{`cc_library(
+ name = "static_empty",
+ copts = [
+ "-I.",
+ "-I$(BINDIR)/.",
+ ],
+ static = {
+ "system_dynamic_deps": [],
+ },
+)`},
+ })
+}
+
+func TestCcLibrary_SystemSharedLibsSharedEmpty(t *testing.T) {
+ runCcLibraryTestCase(t, bp2buildTestCase{
+ description: "cc_library system_shared_libs empty for shared variant",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
+ moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ blueprint: soongCcLibraryPreamble + `
+cc_library {
+ name: "shared_empty",
+ shared: {
+ system_shared_libs: [],
+ },
+}
+`,
+ expectedBazelTargets: []string{`cc_library(
+ name = "shared_empty",
+ copts = [
+ "-I.",
+ "-I$(BINDIR)/.",
+ ],
+ shared = {
+ "system_dynamic_deps": [],
+ },
+)`},
+ })
+}
+
+func TestCcLibrary_SystemSharedLibsSharedBionicEmpty(t *testing.T) {
+ runCcLibraryTestCase(t, bp2buildTestCase{
+ description: "cc_library system_shared_libs empty for shared, bionic variant",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
+ moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ blueprint: soongCcLibraryPreamble + `
+cc_library {
+ name: "shared_empty",
+ target: {
+ bionic: {
+ shared: {
+ system_shared_libs: [],
+ }
+ }
+ },
+}
+`,
+ expectedBazelTargets: []string{`cc_library(
+ name = "shared_empty",
+ copts = [
+ "-I.",
+ "-I$(BINDIR)/.",
+ ],
+ shared = {
+ "system_dynamic_deps": [],
+ },
+)`},
+ })
+}
+
+func TestCcLibrary_SystemSharedLibsLinuxBionicEmpty(t *testing.T) {
+ // Note that this behavior is technically incorrect (it's a simplification).
+ // The correct behavior would be if bp2build wrote `system_dynamic_deps = []`
+ // only for linux_bionic, but `android` had `["libc", "libdl", "libm"].
+ // b/195791252 tracks the fix.
+ runCcLibraryTestCase(t, bp2buildTestCase{
+ description: "cc_library system_shared_libs empty for linux_bionic variant",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
+ moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ blueprint: soongCcLibraryPreamble + `
+cc_library {
+ name: "target_linux_bionic_empty",
+ target: {
+ linux_bionic: {
+ system_shared_libs: [],
+ },
+ },
+}
+`,
+ expectedBazelTargets: []string{`cc_library(
+ name = "target_linux_bionic_empty",
+ copts = [
+ "-I.",
+ "-I$(BINDIR)/.",
+ ],
+ system_dynamic_deps = [],
+)`},
+ })
+}
+
+func TestCcLibrary_SystemSharedLibsBionicEmpty(t *testing.T) {
+ runCcLibraryTestCase(t, bp2buildTestCase{
+ description: "cc_library system_shared_libs empty for bionic variant",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
+ moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ blueprint: soongCcLibraryPreamble + `
+cc_library {
+ name: "target_bionic_empty",
+ target: {
+ bionic: {
+ system_shared_libs: [],
+ },
+ },
+}
+`,
+ expectedBazelTargets: []string{`cc_library(
+ name = "target_bionic_empty",
+ copts = [
+ "-I.",
+ "-I$(BINDIR)/.",
+ ],
+ system_dynamic_deps = [],
+)`},
+ })
+}
+
+func TestCcLibrary_SystemSharedLibsSharedAndRoot(t *testing.T) {
+ runCcLibraryTestCase(t, bp2buildTestCase{
+ description: "cc_library system_shared_libs set for shared and root",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
+ moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ blueprint: soongCcLibraryPreamble + `
+cc_library {name: "libc"}
+cc_library {name: "libm"}
+
+cc_library {
+ name: "foo",
+ system_shared_libs: ["libc"],
+ shared: {
+ system_shared_libs: ["libm"],
+ },
+}
+`,
+ expectedBazelTargets: []string{`cc_library(
+ name = "foo",
+ copts = [
+ "-I.",
+ "-I$(BINDIR)/.",
+ ],
+ shared = {
+ "system_dynamic_deps": [":libm"],
+ },
+ system_dynamic_deps = [":libc"],
+)`, `cc_library(
+ name = "libc",
+ copts = [
+ "-I.",
+ "-I$(BINDIR)/.",
+ ],
+)`, `cc_library(
+ name = "libm",
+ copts = [
+ "-I.",
+ "-I$(BINDIR)/.",
+ ],
+)`},
+ })
+}