Support `suffix` property in bp2build
Support this in cc_{binary,library{,_shared}}
Bug: 204811222
Test: Suffix additions to cc_{binary,library{,_shared}}_conversion_test.go
Test: mixed_{libc,droid}.sh also builds newly allowlisted
Change-Id: I596694794b01b04c542cbcd7d54baeb7d914ba50
diff --git a/bp2build/cc_binary_conversion_test.go b/bp2build/cc_binary_conversion_test.go
index 9e449eb..67d4a1c 100644
--- a/bp2build/cc_binary_conversion_test.go
+++ b/bp2build/cc_binary_conversion_test.go
@@ -605,8 +605,67 @@
"//conditions:default": [],
})`,
"local_includes": `["."]`,
- },
- },
+ }},
+ },
+ })
+}
+
+func TestCcBinaryEmptySuffix(t *testing.T) {
+ runCcBinaryTests(t, ccBinaryBp2buildTestCase{
+ description: "binary with empty suffix",
+ blueprint: `
+{rule_name} {
+ name: "foo",
+ suffix: "",
+}`,
+ targets: []testBazelTarget{
+ {"cc_binary", "foo", AttrNameToString{
+ "local_includes": `["."]`,
+ "suffix": `""`,
+ }},
+ },
+ })
+}
+
+func TestCcBinarySuffix(t *testing.T) {
+ runCcBinaryTests(t, ccBinaryBp2buildTestCase{
+ description: "binary with suffix",
+ blueprint: `
+{rule_name} {
+ name: "foo",
+ suffix: "-suf",
+}
+`,
+ targets: []testBazelTarget{
+ {"cc_binary", "foo", AttrNameToString{
+ "local_includes": `["."]`,
+ "suffix": `"-suf"`,
+ }},
+ },
+ })
+}
+
+func TestCcArchVariantBinarySuffix(t *testing.T) {
+ runCcBinaryTests(t, ccBinaryBp2buildTestCase{
+ description: "binary with suffix",
+ blueprint: `
+{rule_name} {
+ name: "foo",
+ arch: {
+ arm64: { suffix: "-64" },
+ arm: { suffix: "-32" },
+ },
+}
+`,
+ targets: []testBazelTarget{
+ {"cc_binary", "foo", AttrNameToString{
+ "local_includes": `["."]`,
+ "suffix": `select({
+ "//build/bazel/platforms/arch:arm": "-32",
+ "//build/bazel/platforms/arch:arm64": "-64",
+ "//conditions:default": None,
+ })`,
+ }},
},
})
}
diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go
index 024d4e0..c1b4cd0 100644
--- a/bp2build/cc_library_conversion_test.go
+++ b/bp2build/cc_library_conversion_test.go
@@ -2593,6 +2593,91 @@
})
}
+func TestCcLibraryEmptySuffix(t *testing.T) {
+ runCcLibraryTestCase(t, Bp2buildTestCase{
+ Description: "cc_library with empty suffix",
+ ModuleTypeUnderTest: "cc_library",
+ ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ Filesystem: map[string]string{
+ "foo.c": "",
+ },
+ Blueprint: `cc_library {
+ name: "foo",
+ suffix: "",
+ srcs: ["foo.c"],
+ include_build_directory: false,
+}`,
+ ExpectedBazelTargets: []string{
+ makeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
+ "srcs_c": `["foo.c"]`,
+ }),
+ makeBazelTarget("cc_library_shared", "foo", AttrNameToString{
+ "srcs_c": `["foo.c"]`,
+ "suffix": `""`,
+ }),
+ },
+ })
+}
+
+func TestCcLibrarySuffix(t *testing.T) {
+ runCcLibraryTestCase(t, Bp2buildTestCase{
+ Description: "cc_library with suffix",
+ ModuleTypeUnderTest: "cc_library",
+ ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ Filesystem: map[string]string{
+ "foo.c": "",
+ },
+ Blueprint: `cc_library {
+ name: "foo",
+ suffix: "-suf",
+ srcs: ["foo.c"],
+ include_build_directory: false,
+}`,
+ ExpectedBazelTargets: []string{
+ makeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
+ "srcs_c": `["foo.c"]`,
+ }),
+ makeBazelTarget("cc_library_shared", "foo", AttrNameToString{
+ "srcs_c": `["foo.c"]`,
+ "suffix": `"-suf"`,
+ }),
+ },
+ })
+}
+
+func TestCcLibraryArchVariantSuffix(t *testing.T) {
+ runCcLibraryTestCase(t, Bp2buildTestCase{
+ Description: "cc_library with arch-variant suffix",
+ ModuleTypeUnderTest: "cc_library",
+ ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ Filesystem: map[string]string{
+ "foo.c": "",
+ },
+ Blueprint: `cc_library {
+ name: "foo",
+ arch: {
+ arm64: { suffix: "-64" },
+ arm: { suffix: "-32" },
+ },
+ srcs: ["foo.c"],
+ include_build_directory: false,
+}`,
+ ExpectedBazelTargets: []string{
+ makeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
+ "srcs_c": `["foo.c"]`,
+ }),
+ makeBazelTarget("cc_library_shared", "foo", AttrNameToString{
+ "srcs_c": `["foo.c"]`,
+ "suffix": `select({
+ "//build/bazel/platforms/arch:arm": "-32",
+ "//build/bazel/platforms/arch:arm64": "-64",
+ "//conditions:default": None,
+ })`,
+ }),
+ },
+ })
+}
+
func TestCcLibraryWithAidlSrcs(t *testing.T) {
runCcLibraryTestCase(t, Bp2buildTestCase{
Description: "cc_library with aidl srcs",
diff --git a/bp2build/cc_library_shared_conversion_test.go b/bp2build/cc_library_shared_conversion_test.go
index 7a44f69..ed983bf 100644
--- a/bp2build/cc_library_shared_conversion_test.go
+++ b/bp2build/cc_library_shared_conversion_test.go
@@ -641,3 +641,76 @@
},
})
}
+
+func TestCcLibrarySharedEmptySuffix(t *testing.T) {
+ runCcLibrarySharedTestCase(t, Bp2buildTestCase{
+ Description: "cc_library_shared with empty suffix",
+ Filesystem: map[string]string{
+ "foo.c": "",
+ },
+ Blueprint: soongCcLibrarySharedPreamble + `
+cc_library_shared {
+ name: "foo_shared",
+ suffix: "",
+ srcs: ["foo.c"],
+ include_build_directory: false,
+}`,
+ ExpectedBazelTargets: []string{
+ makeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
+ "srcs_c": `["foo.c"]`,
+ "suffix": `""`,
+ }),
+ },
+ })
+}
+
+func TestCcLibrarySharedSuffix(t *testing.T) {
+ runCcLibrarySharedTestCase(t, Bp2buildTestCase{
+ Description: "cc_library_shared with suffix",
+ Filesystem: map[string]string{
+ "foo.c": "",
+ },
+ Blueprint: soongCcLibrarySharedPreamble + `
+cc_library_shared {
+ name: "foo_shared",
+ suffix: "-suf",
+ srcs: ["foo.c"],
+ include_build_directory: false,
+}`,
+ ExpectedBazelTargets: []string{
+ makeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
+ "srcs_c": `["foo.c"]`,
+ "suffix": `"-suf"`,
+ }),
+ },
+ })
+}
+
+func TestCcLibrarySharedArchVariantSuffix(t *testing.T) {
+ runCcLibrarySharedTestCase(t, Bp2buildTestCase{
+ Description: "cc_library_shared with arch-variant suffix",
+ Filesystem: map[string]string{
+ "foo.c": "",
+ },
+ Blueprint: soongCcLibrarySharedPreamble + `
+cc_library_shared {
+ name: "foo_shared",
+ arch: {
+ arm64: { suffix: "-64" },
+ arm: { suffix: "-32" },
+ },
+ srcs: ["foo.c"],
+ include_build_directory: false,
+}`,
+ ExpectedBazelTargets: []string{
+ makeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
+ "srcs_c": `["foo.c"]`,
+ "suffix": `select({
+ "//build/bazel/platforms/arch:arm": "-32",
+ "//build/bazel/platforms/arch:arm64": "-64",
+ "//conditions:default": None,
+ })`,
+ }),
+ },
+ })
+}