Create a bp2build converter for ndk_headers

And add this module type to alwaysConvertList

Test: go test ./bp2build
Bug: 300504837
Change-Id: Ic09738ab47e7c497287b73de0f952d52aa78dd17
This commit is contained in:
Spandan Das
2023-09-19 19:04:41 +00:00
parent e993475ca6
commit 319711b0bc
5 changed files with 57 additions and 3 deletions

View File

@@ -21,6 +21,7 @@ import (
"github.com/google/blueprint"
"android/soong/android"
"android/soong/bazel"
)
var (
@@ -79,6 +80,7 @@ type headerProperties struct {
type headerModule struct {
android.ModuleBase
android.BazelModuleBase
properties headerProperties
@@ -145,6 +147,29 @@ func (m *headerModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
}
}
type bazelNdkHeadersAttributes struct {
Strip_import_prefix *string
Import_prefix *string
Hdrs bazel.LabelListAttribute
}
func (h *headerModule) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) {
props := bazel.BazelTargetModuleProperties{
Rule_class: "ndk_headers",
Bzl_load_location: "//build/bazel/rules/cc:ndk_headers.bzl",
}
attrs := &bazelNdkHeadersAttributes{
Strip_import_prefix: h.properties.From,
Import_prefix: h.properties.To,
Hdrs: bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrcExcludes(ctx, h.properties.Srcs, h.properties.Exclude_srcs)),
}
ctx.CreateBazelTargetModule(
props,
android.CommonAttributes{Name: h.Name()},
attrs,
)
}
// ndk_headers installs the sets of ndk headers defined in the srcs property
// to the sysroot base + "usr/include" + to directory + directory component.
// ndk_headers requires the license file to be specified. Example:
@@ -155,10 +180,11 @@ func (m *headerModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
// to = "bar"
// header = "include/foo/woodly/doodly.h"
// output path = "ndk/sysroot/usr/include/bar/woodly/doodly.h"
func ndkHeadersFactory() android.Module {
func NdkHeadersFactory() android.Module {
module := &headerModule{}
module.AddProperties(&module.properties)
android.InitAndroidModule(module)
android.InitBazelModule(module)
return module
}

View File

@@ -62,7 +62,7 @@ func init() {
}
func RegisterNdkModuleTypes(ctx android.RegistrationContext) {
ctx.RegisterModuleType("ndk_headers", ndkHeadersFactory)
ctx.RegisterModuleType("ndk_headers", NdkHeadersFactory)
ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
ctx.RegisterModuleType("versioned_ndk_headers", versionedNdkHeadersFactory)
ctx.RegisterModuleType("preprocessed_ndk_headers", preprocessedNdkHeadersFactory)

View File

@@ -42,7 +42,7 @@ func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
ctx.RegisterModuleType("ndk_prebuilt_shared_stl", NdkPrebuiltSharedStlFactory)
ctx.RegisterModuleType("ndk_prebuilt_static_stl", NdkPrebuiltStaticStlFactory)
ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
ctx.RegisterModuleType("ndk_headers", ndkHeadersFactory)
ctx.RegisterModuleType("ndk_headers", NdkHeadersFactory)
}
func GatherRequiredDepsForTest(oses ...android.OsType) string {