bp2build converter for ndk_library
ndk_libary will be converted to a cc_stub_suite target. Its api_surface
attribute will be publicapi
The headers corresponding to this stub target will be added in a followup bug
(tracked in b/300504837)
Bug: 298085502
Test: Added a unit test
Change-Id: If9745083b18e0bcf5ecb89229a0f709b949d401c
diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go
index 3957ff7..76dc590 100644
--- a/bp2build/cc_library_conversion_test.go
+++ b/bp2build/cc_library_conversion_test.go
@@ -65,6 +65,7 @@
ctx.RegisterModuleType("cc_prebuilt_library_static", cc.PrebuiltStaticLibraryFactory)
ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory)
ctx.RegisterModuleType("aidl_library", aidl_library.AidlLibraryFactory)
+ ctx.RegisterModuleType("ndk_library", cc.NdkLibraryFactory)
}
func TestCcLibrarySimple(t *testing.T) {
@@ -5131,3 +5132,38 @@
}
runCcLibraryTestCase(t, tc)
}
+
+func TestNdkLibraryConversion(t *testing.T) {
+ tc := Bp2buildTestCase{
+ Description: "ndk_library conversion",
+ ModuleTypeUnderTest: "cc_library",
+ ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ Blueprint: `
+cc_library {
+ name: "libfoo",
+ bazel_module: { bp2build_available: false },
+}
+ndk_library {
+ name: "libfoo",
+ first_version: "29",
+ symbol_file: "libfoo.map.txt",
+}
+`,
+ ExpectedBazelTargets: []string{
+ MakeBazelTarget("cc_stub_suite", "libfoo.ndk_stub_libs", AttrNameToString{
+ "api_surface": `"publicapi"`,
+ "soname": `"libfoo.so"`,
+ "source_library_label": `"//:libfoo"`,
+ "symbol_file": `"libfoo.map.txt"`,
+ "versions": `[
+ "29",
+ "30",
+ "S",
+ "Tiramisu",
+ "current",
+ ]`,
+ }),
+ },
+ }
+ runCcLibraryTestCase(t, tc)
+}
diff --git a/cc/cc.go b/cc/cc.go
index 8d79df2..e28d056 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -4255,6 +4255,8 @@
}
case ndkPrebuiltStl:
ndkPrebuiltStlBp2build(ctx, c)
+ case ndkLibrary:
+ ndkLibraryBp2build(ctx, c)
default:
ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_TYPE_UNSUPPORTED, "")
}
diff --git a/cc/ndk_library.go b/cc/ndk_library.go
index b201dd8..bb40b45 100644
--- a/cc/ndk_library.go
+++ b/cc/ndk_library.go
@@ -581,3 +581,40 @@
}
return android.BazelLabelForModuleDepsWithFn(ctx, hdrLibs, addSuffix)
}
+
+func ndkLibraryBp2build(ctx android.TopDownMutatorContext, c *Module) {
+ ndk, _ := c.linker.(*stubDecorator)
+ props := bazel.BazelTargetModuleProperties{
+ Rule_class: "cc_stub_suite",
+ Bzl_load_location: "//build/bazel/rules/cc:cc_stub_library.bzl",
+ }
+ sourceLibraryName := strings.TrimSuffix(c.Name(), ".ndk")
+ fromApiLevel, err := android.ApiLevelFromUser(ctx, proptools.String(ndk.properties.First_version))
+ if err != nil {
+ ctx.PropertyErrorf("first_version", "error converting first_version %v", proptools.String(ndk.properties.First_version))
+ }
+ symbolFileLabel := android.BazelLabelForModuleSrcSingle(ctx, proptools.String(ndk.properties.Symbol_file))
+ attrs := &bazelCcStubSuiteAttributes{
+ // TODO - b/300504837 Add ndk headers
+ Symbol_file: proptools.StringPtr(symbolFileLabel.Label),
+ Soname: proptools.StringPtr(sourceLibraryName + ".so"),
+ Api_surface: proptools.StringPtr(android.PublicApi.String()),
+ }
+ if sourceLibrary, exists := ctx.ModuleFromName(sourceLibraryName); exists {
+ // the source library might not exist in minimal/unbuildable branches like kernel-build-tools.
+ // check for its existence
+ attrs.Source_library_label = proptools.StringPtr(c.GetBazelLabel(ctx, sourceLibrary))
+ }
+ if ctx.Config().RawPlatformSdkVersion() != nil {
+ // This is a hack to populate `versions` only on branches that set a platform_sdk_version
+ // This prevents errors on branches such as kernel-build-tools
+ // This hack is acceptable since we are not required to support NDK Bazel builds on those branches
+ attrs.Versions = bazel.MakeStringListAttribute(ndkLibraryVersions(ctx, fromApiLevel))
+ }
+
+ ctx.CreateBazelTargetModule(
+ props,
+ android.CommonAttributes{Name: c.Name() + "_stub_libs"},
+ attrs,
+ )
+}