bp2build: Add support for export_.*headers props
Soong supports export_.*_headers properties, the libraries contained in
this list must also be within a shared/static/whole_static/header libs
property. For bp2build, we eliminate this duplication. The libraries
not listed in an export_.*_headers property will migrate to an attribute
prepended with implementation_, those in export_.*_headers will not have
a prefix.
Test: build/bazel/ci/bp2build.sh
Test: build/bazel/ci/mixed_libc.sh
Bug: 198241472
Change-Id: I3eb84c983ec5d241c8a568e411dfd5619d3184a7
diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go
index b3a1053..ec8882b 100644
--- a/bp2build/cc_library_conversion_test.go
+++ b/bp2build/cc_library_conversion_test.go
@@ -349,21 +349,21 @@
expectedBazelTargets: []string{`cc_library(
name = "a",
copts = ["bothflag"],
- dynamic_deps = [":shared_dep_for_both"],
implementation_deps = [":static_dep_for_both"],
+ implementation_dynamic_deps = [":shared_dep_for_both"],
shared = {
"copts": ["sharedflag"],
- "dynamic_deps": [":shared_dep_for_shared"],
+ "implementation_deps": [":static_dep_for_shared"],
+ "implementation_dynamic_deps": [":shared_dep_for_shared"],
"srcs": ["sharedonly.cpp"],
- "static_deps": [":static_dep_for_shared"],
"whole_archive_deps": [":whole_static_lib_for_shared"],
},
srcs = ["both.cpp"],
static = {
"copts": ["staticflag"],
- "dynamic_deps": [":shared_dep_for_static"],
+ "implementation_deps": [":static_dep_for_static"],
+ "implementation_dynamic_deps": [":shared_dep_for_static"],
"srcs": ["staticonly.cpp"],
- "static_deps": [":static_dep_for_static"],
"whole_archive_deps": [":whole_static_lib_for_static"],
},
whole_archive_deps = [":whole_static_lib_for_both"],
@@ -371,6 +371,105 @@
})
}
+func TestCcLibraryDeps(t *testing.T) {
+ runCcLibraryTestCase(t, bp2buildTestCase{
+ description: "cc_library shared/static props",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
+ moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ filesystem: map[string]string{
+ "both.cpp": "",
+ "sharedonly.cpp": "",
+ "staticonly.cpp": "",
+ },
+ blueprint: soongCcLibraryPreamble + `
+cc_library {
+ name: "a",
+ srcs: ["both.cpp"],
+ cflags: ["bothflag"],
+ shared_libs: ["implementation_shared_dep_for_both", "shared_dep_for_both"],
+ export_shared_lib_headers: ["shared_dep_for_both"],
+ static_libs: ["implementation_static_dep_for_both", "static_dep_for_both"],
+ export_static_lib_headers: ["static_dep_for_both", "whole_static_dep_for_both"],
+ whole_static_libs: ["not_explicitly_exported_whole_static_dep_for_both", "whole_static_dep_for_both"],
+ static: {
+ srcs: ["staticonly.cpp"],
+ cflags: ["staticflag"],
+ shared_libs: ["implementation_shared_dep_for_static", "shared_dep_for_static"],
+ export_shared_lib_headers: ["shared_dep_for_static"],
+ static_libs: ["implementation_static_dep_for_static", "static_dep_for_static"],
+ export_static_lib_headers: ["static_dep_for_static", "whole_static_dep_for_static"],
+ whole_static_libs: ["not_explicitly_exported_whole_static_dep_for_static", "whole_static_dep_for_static"],
+ },
+ shared: {
+ srcs: ["sharedonly.cpp"],
+ cflags: ["sharedflag"],
+ shared_libs: ["implementation_shared_dep_for_shared", "shared_dep_for_shared"],
+ export_shared_lib_headers: ["shared_dep_for_shared"],
+ static_libs: ["implementation_static_dep_for_shared", "static_dep_for_shared"],
+ export_static_lib_headers: ["static_dep_for_shared", "whole_static_dep_for_shared"],
+ whole_static_libs: ["not_explicitly_exported_whole_static_dep_for_shared", "whole_static_dep_for_shared"],
+ },
+ include_build_directory: false,
+}
+` + simpleModuleDoNotConvertBp2build("cc_library_static", "static_dep_for_shared") +
+ simpleModuleDoNotConvertBp2build("cc_library_static", "implementation_static_dep_for_shared") +
+ simpleModuleDoNotConvertBp2build("cc_library_static", "static_dep_for_static") +
+ simpleModuleDoNotConvertBp2build("cc_library_static", "implementation_static_dep_for_static") +
+ simpleModuleDoNotConvertBp2build("cc_library_static", "static_dep_for_both") +
+ simpleModuleDoNotConvertBp2build("cc_library_static", "implementation_static_dep_for_both") +
+ simpleModuleDoNotConvertBp2build("cc_library_static", "whole_static_dep_for_shared") +
+ simpleModuleDoNotConvertBp2build("cc_library_static", "not_explicitly_exported_whole_static_dep_for_shared") +
+ simpleModuleDoNotConvertBp2build("cc_library_static", "whole_static_dep_for_static") +
+ simpleModuleDoNotConvertBp2build("cc_library_static", "not_explicitly_exported_whole_static_dep_for_static") +
+ simpleModuleDoNotConvertBp2build("cc_library_static", "whole_static_dep_for_both") +
+ simpleModuleDoNotConvertBp2build("cc_library_static", "not_explicitly_exported_whole_static_dep_for_both") +
+ simpleModuleDoNotConvertBp2build("cc_library", "shared_dep_for_shared") +
+ simpleModuleDoNotConvertBp2build("cc_library", "implementation_shared_dep_for_shared") +
+ simpleModuleDoNotConvertBp2build("cc_library", "shared_dep_for_static") +
+ simpleModuleDoNotConvertBp2build("cc_library", "implementation_shared_dep_for_static") +
+ simpleModuleDoNotConvertBp2build("cc_library", "shared_dep_for_both") +
+ simpleModuleDoNotConvertBp2build("cc_library", "implementation_shared_dep_for_both"),
+ expectedBazelTargets: []string{`cc_library(
+ name = "a",
+ copts = ["bothflag"],
+ deps = [":static_dep_for_both"],
+ dynamic_deps = [":shared_dep_for_both"],
+ implementation_deps = [":implementation_static_dep_for_both"],
+ implementation_dynamic_deps = [":implementation_shared_dep_for_both"],
+ shared = {
+ "copts": ["sharedflag"],
+ "deps": [":static_dep_for_shared"],
+ "dynamic_deps": [":shared_dep_for_shared"],
+ "implementation_deps": [":implementation_static_dep_for_shared"],
+ "implementation_dynamic_deps": [":implementation_shared_dep_for_shared"],
+ "srcs": ["sharedonly.cpp"],
+ "whole_archive_deps": [
+ ":not_explicitly_exported_whole_static_dep_for_shared",
+ ":whole_static_dep_for_shared",
+ ],
+ },
+ srcs = ["both.cpp"],
+ static = {
+ "copts": ["staticflag"],
+ "deps": [":static_dep_for_static"],
+ "dynamic_deps": [":shared_dep_for_static"],
+ "implementation_deps": [":implementation_static_dep_for_static"],
+ "implementation_dynamic_deps": [":implementation_shared_dep_for_static"],
+ "srcs": ["staticonly.cpp"],
+ "whole_archive_deps": [
+ ":not_explicitly_exported_whole_static_dep_for_static",
+ ":whole_static_dep_for_static",
+ ],
+ },
+ whole_archive_deps = [
+ ":not_explicitly_exported_whole_static_dep_for_both",
+ ":whole_static_dep_for_both",
+ ],
+)`},
+ })
+}
+
func TestCcLibraryWholeStaticLibsAlwaysLink(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
moduleTypeUnderTest: "cc_library",
@@ -506,7 +605,14 @@
"//build/bazel/platforms/os_arch:android_arm": ["-DANDROID_ARM_SHARED"],
"//conditions:default": [],
}),
- "dynamic_deps": select({
+ "implementation_deps": [":static_dep_for_shared"] + select({
+ "//build/bazel/platforms/arch:arm": [":arm_static_dep_for_shared"],
+ "//conditions:default": [],
+ }) + select({
+ "//build/bazel/platforms/os:android": [":android_dep_for_shared"],
+ "//conditions:default": [],
+ }),
+ "implementation_dynamic_deps": select({
"//build/bazel/platforms/arch:arm": [":arm_shared_dep_for_shared"],
"//conditions:default": [],
}),
@@ -517,13 +623,6 @@
"//build/bazel/platforms/os:android": ["android_shared.cpp"],
"//conditions:default": [],
}),
- "static_deps": [":static_dep_for_shared"] + select({
- "//build/bazel/platforms/arch:arm": [":arm_static_dep_for_shared"],
- "//conditions:default": [],
- }) + select({
- "//build/bazel/platforms/os:android": [":android_dep_for_shared"],
- "//conditions:default": [],
- }),
"whole_archive_deps": select({
"//build/bazel/platforms/arch:arm": [":arm_whole_static_dep_for_shared"],
"//conditions:default": [],
@@ -535,12 +634,12 @@
"//build/bazel/platforms/arch:x86": ["-DX86_STATIC"],
"//conditions:default": [],
}),
- "srcs": ["staticonly.cpp"] + select({
- "//build/bazel/platforms/arch:x86": ["x86_static.cpp"],
+ "implementation_deps": [":static_dep_for_static"] + select({
+ "//build/bazel/platforms/arch:x86": [":x86_dep_for_static"],
"//conditions:default": [],
}),
- "static_deps": [":static_dep_for_static"] + select({
- "//build/bazel/platforms/arch:x86": [":x86_dep_for_static"],
+ "srcs": ["staticonly.cpp"] + select({
+ "//build/bazel/platforms/arch:x86": ["x86_static.cpp"],
"//conditions:default": [],
}),
},
@@ -767,7 +866,7 @@
`,
expectedBazelTargets: []string{`cc_library(
name = "a",
- dynamic_deps = [":mylib"],
+ implementation_dynamic_deps = [":mylib"],
)`},
})
}
@@ -1013,13 +1112,6 @@
expectedBazelTargets: []string{
`cc_library(
name = "foo_static",
- dynamic_deps = select({
- "//build/bazel/platforms/arch:arm": [],
- "//conditions:default": [":arm_shared_lib_excludes"],
- }) + select({
- "//build/bazel/product_variables:malloc_not_svelte": [":malloc_not_svelte_shared_lib"],
- "//conditions:default": [],
- }),
implementation_deps = select({
"//build/bazel/platforms/arch:arm": [],
"//conditions:default": [":arm_static_lib_excludes_bp2build_cc_library_static"],
@@ -1027,6 +1119,13 @@
"//build/bazel/product_variables:malloc_not_svelte": [],
"//conditions:default": [":malloc_not_svelte_static_lib_excludes_bp2build_cc_library_static"],
}),
+ implementation_dynamic_deps = select({
+ "//build/bazel/platforms/arch:arm": [],
+ "//conditions:default": [":arm_shared_lib_excludes"],
+ }) + select({
+ "//build/bazel/product_variables:malloc_not_svelte": [":malloc_not_svelte_shared_lib"],
+ "//conditions:default": [],
+ }),
srcs_c = ["common.c"],
whole_archive_deps = select({
"//build/bazel/platforms/arch:arm": [],