Converters for contributions to systemapi and vendorapi
The module types in scope of this conversion are
1. cc_library and cc_library_shared (non-null llndk or stubs prop)
2. cc_library_headers (all)
For (2), we need some postprocessing on the results of the parser
bp2BuildParseBaseProps. This is necessary because arch and os specific
API exports need to be flattened and added to the generateed API headers
target along NoConfigAxis
e.g.
```
The api equivalent of
cc_library_headers (
name = "lifoo",
deps = select({
"//build/bazel/platforms/arch:arm": ["arm_deps"],
"//build/bazel/platforms/arch:arm64": ["arm64_deps"],
}),
)
should be
cc_api_library_headers (
name = "lifoo",
deps = ["arm_deps", "arm64_deps"],
)
```
For (1), we also need to generate 1:many header api targets so that
arch-specific deps can propagate arch metadata to the top-level
api_domain rule
Test: go test ./bp2build
Test: go test ./cc
Change-Id: Ie40cba1ac8e89f290b3d926c190d5e93abd52859
diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go
index d4461b6..0d6d5b8 100644
--- a/bp2build/cc_library_conversion_test.go
+++ b/bp2build/cc_library_conversion_test.go
@@ -2743,6 +2743,205 @@
)
}
+func TestCcApiContributionsWithHdrs(t *testing.T) {
+ bp := `
+ cc_library {
+ name: "libfoo",
+ stubs: { symbol_file: "libfoo.map.txt", versions: ["28", "29", "current"] },
+ llndk: { symbol_file: "libfoo.map.txt", override_export_include_dirs: ["dir2"]},
+ export_include_dirs: ["dir1"],
+ }
+ `
+ expectedBazelTargets := []string{
+ MakeBazelTarget(
+ "cc_api_library_headers",
+ "libfoo.systemapi.headers",
+ AttrNameToString{
+ "export_includes": `["dir1"]`,
+ }),
+ MakeBazelTarget(
+ "cc_api_library_headers",
+ "libfoo.vendorapi.headers",
+ AttrNameToString{
+ "export_includes": `["dir2"]`,
+ }),
+ MakeBazelTarget(
+ "cc_api_contribution",
+ "libfoo.contribution",
+ AttrNameToString{
+ "api": `"libfoo.map.txt"`,
+ "library_name": `"libfoo"`,
+ "api_surfaces": `[
+ "systemapi",
+ "vendorapi",
+ ]`,
+ "hdrs": `[
+ ":libfoo.systemapi.headers",
+ ":libfoo.vendorapi.headers",
+ ]`,
+ }),
+ }
+ RunApiBp2BuildTestCase(t, cc.RegisterLibraryBuildComponents, Bp2buildTestCase{
+ Blueprint: bp,
+ Description: "cc API contributions to systemapi and vendorapi",
+ ExpectedBazelTargets: expectedBazelTargets,
+ })
+}
+
+func TestCcApiSurfaceCombinations(t *testing.T) {
+ testCases := []struct {
+ bp string
+ expectedApi string
+ expectedApiSurfaces string
+ description string
+ }{
+ {
+ bp: `
+ cc_library {
+ name: "a",
+ stubs: {symbol_file: "a.map.txt"},
+ }`,
+ expectedApi: `"a.map.txt"`,
+ expectedApiSurfaces: `["systemapi"]`,
+ description: "Library that contributes to systemapi",
+ },
+ {
+ bp: `
+ cc_library {
+ name: "a",
+ llndk: {symbol_file: "a.map.txt"},
+ }`,
+ expectedApi: `"a.map.txt"`,
+ expectedApiSurfaces: `["vendorapi"]`,
+ description: "Library that contributes to vendorapi",
+ },
+ {
+ bp: `
+ cc_library {
+ name: "a",
+ llndk: {symbol_file: "a.map.txt"},
+ stubs: {symbol_file: "a.map.txt"},
+ }`,
+ expectedApi: `"a.map.txt"`,
+ expectedApiSurfaces: `[
+ "systemapi",
+ "vendorapi",
+ ]`,
+ description: "Library that contributes to systemapi and vendorapi",
+ },
+ }
+ for _, testCase := range testCases {
+ expectedBazelTargets := []string{
+ MakeBazelTarget(
+ "cc_api_contribution",
+ "a.contribution",
+ AttrNameToString{
+ "library_name": `"a"`,
+ "hdrs": `[]`,
+ "api": testCase.expectedApi,
+ "api_surfaces": testCase.expectedApiSurfaces,
+ },
+ ),
+ }
+ RunApiBp2BuildTestCase(t, cc.RegisterLibraryBuildComponents, Bp2buildTestCase{
+ Blueprint: testCase.bp,
+ Description: testCase.description,
+ ExpectedBazelTargets: expectedBazelTargets,
+ })
+ }
+}
+
+// llndk struct property in Soong provides users with several options to configure the exported include dirs
+// Test the generated bazel targets for the different configurations
+func TestCcVendorApiHeaders(t *testing.T) {
+ testCases := []struct {
+ bp string
+ expectedIncludes string
+ expectedSystemIncludes string
+ description string
+ }{
+ {
+ bp: `
+ cc_library {
+ name: "a",
+ export_include_dirs: ["include"],
+ export_system_include_dirs: ["base_system_include"],
+ llndk: {
+ symbol_file: "a.map.txt",
+ export_headers_as_system: true,
+ },
+ }
+ `,
+ expectedIncludes: "",
+ expectedSystemIncludes: `[
+ "base_system_include",
+ "include",
+ ]`,
+ description: "Headers are exported as system to API surface",
+ },
+ {
+ bp: `
+ cc_library {
+ name: "a",
+ export_include_dirs: ["include"],
+ export_system_include_dirs: ["base_system_include"],
+ llndk: {
+ symbol_file: "a.map.txt",
+ override_export_include_dirs: ["llndk_include"],
+ },
+ }
+ `,
+ expectedIncludes: `["llndk_include"]`,
+ expectedSystemIncludes: `["base_system_include"]`,
+ description: "Non-system Headers are ovverriden before export to API surface",
+ },
+ {
+ bp: `
+ cc_library {
+ name: "a",
+ export_include_dirs: ["include"],
+ export_system_include_dirs: ["base_system_include"],
+ llndk: {
+ symbol_file: "a.map.txt",
+ override_export_include_dirs: ["llndk_include"],
+ export_headers_as_system: true,
+ },
+ }
+ `,
+ expectedIncludes: "", // includes are set to nil
+ expectedSystemIncludes: `[
+ "base_system_include",
+ "llndk_include",
+ ]`,
+ description: "System Headers are extended before export to API surface",
+ },
+ }
+ for _, testCase := range testCases {
+ attrs := AttrNameToString{}
+ if testCase.expectedIncludes != "" {
+ attrs["export_includes"] = testCase.expectedIncludes
+ }
+ if testCase.expectedSystemIncludes != "" {
+ attrs["export_system_includes"] = testCase.expectedSystemIncludes
+ }
+
+ expectedBazelTargets := []string{
+ MakeBazelTarget("cc_api_library_headers", "a.vendorapi.headers", attrs),
+ // Create a target for cc_api_contribution target
+ MakeBazelTarget("cc_api_contribution", "a.contribution", AttrNameToString{
+ "api": `"a.map.txt"`,
+ "api_surfaces": `["vendorapi"]`,
+ "hdrs": `[":a.vendorapi.headers"]`,
+ "library_name": `"a"`,
+ }),
+ }
+ RunApiBp2BuildTestCase(t, cc.RegisterLibraryBuildComponents, Bp2buildTestCase{
+ Blueprint: testCase.bp,
+ ExpectedBazelTargets: expectedBazelTargets,
+ })
+ }
+}
+
func TestCcLibraryStubsAcrossConfigsDuplicatesRemoved(t *testing.T) {
runCcLibraryTestCase(t, Bp2buildTestCase{
Description: "stub target generation of the same lib across configs should not result in duplicates",