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/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,
+ )
+}