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
This commit is contained in:
Spandan Das 2023-09-14 22:34:34 +00:00
parent 9f7028852c
commit 63acae9af1
3 changed files with 75 additions and 0 deletions

View file

@ -65,6 +65,7 @@ func registerCcLibraryModuleTypes(ctx android.RegistrationContext) {
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 @@ cc_library {
}
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)
}

View file

@ -4255,6 +4255,8 @@ func (c *Module) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
}
case ndkPrebuiltStl:
ndkPrebuiltStlBp2build(ctx, c)
case ndkLibrary:
ndkLibraryBp2build(ctx, c)
default:
ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_TYPE_UNSUPPORTED, "")
}

View file

@ -581,3 +581,40 @@ func apiHeaderLabels(ctx android.TopDownMutatorContext, hdrLibs []string) bazel.
}
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,
)
}