diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go index 94503ddb3..da4f72a67 100644 --- a/android/allowlists/allowlists.go +++ b/android/allowlists/allowlists.go @@ -941,6 +941,7 @@ var ( "license", "linker_config", "ndk_library", + "ndk_headers", "sysprop_library", "xsd_config", } diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go index ec603c294..c11600842 100644 --- a/bp2build/cc_library_conversion_test.go +++ b/bp2build/cc_library_conversion_test.go @@ -5184,3 +5184,30 @@ ndk_library { } runCcLibraryTestCase(t, tc) } + +func TestNdkHeadersConversion(t *testing.T) { + tc := Bp2buildTestCase{ + Description: "ndk_headers conversion", + ModuleTypeUnderTest: "ndk_headers", + ModuleTypeUnderTestFactory: cc.NdkHeadersFactory, + Blueprint: ` +ndk_headers { + name: "libfoo_headers", + from: "from", + to: "to", + srcs: ["foo.h", "foo_other.h"] +} +`, + ExpectedBazelTargets: []string{ + MakeBazelTargetNoRestrictions("ndk_headers", "libfoo_headers", AttrNameToString{ + "strip_import_prefix": `"from"`, + "import_prefix": `"to"`, + "hdrs": `[ + "foo.h", + "foo_other.h", + ]`, + }), + }, + } + runCcLibraryTestCase(t, tc) +} diff --git a/cc/ndk_headers.go b/cc/ndk_headers.go index 1a8e90fd9..da5db1c19 100644 --- a/cc/ndk_headers.go +++ b/cc/ndk_headers.go @@ -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 } diff --git a/cc/ndk_sysroot.go b/cc/ndk_sysroot.go index 9ec2ae4ea..54a2ee267 100644 --- a/cc/ndk_sysroot.go +++ b/cc/ndk_sysroot.go @@ -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) diff --git a/cc/testing.go b/cc/testing.go index 21745c3d1..36bc261e0 100644 --- a/cc/testing.go +++ b/cc/testing.go @@ -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 {