Merge "Create a bp2build converter for ndk_headers" into main

This commit is contained in:
Spandan Das 2023-09-21 23:11:33 +00:00 committed by Gerrit Code Review
commit 7ba007a3c6
5 changed files with 57 additions and 3 deletions

View file

@ -971,6 +971,7 @@ var (
"license",
"linker_config",
"ndk_library",
"ndk_headers",
"sysprop_library",
"xsd_config",
// go/keep-sorted end

View file

@ -5183,3 +5183,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)
}

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 {