Merge "Convert filegroup with AIDL srcs to aidl_library"
This commit is contained in:
commit
88b3ba2ae2
4 changed files with 131 additions and 8 deletions
|
@ -307,6 +307,7 @@ var (
|
|||
"libandroid_runtime_vm_headers",
|
||||
"libaudioclient_aidl_conversion_util",
|
||||
"libaudioutils_fixedfft",
|
||||
"libbinder_aidl",
|
||||
"libbinder_headers",
|
||||
"libbinder_headers_platform_shared",
|
||||
"libbluetooth-types-header",
|
||||
|
@ -394,6 +395,13 @@ var (
|
|||
//system/libhidl
|
||||
// needed by cc_hidl_library
|
||||
"libhidlbase",
|
||||
|
||||
//frameworks/native
|
||||
"framework_native_aidl_binder",
|
||||
"framework_native_aidl_gui",
|
||||
|
||||
//frameworks/native/libs/input
|
||||
"inputconstants_aidl",
|
||||
}
|
||||
|
||||
Bp2buildModuleTypeAlwaysConvertList = []string{
|
||||
|
|
|
@ -35,6 +35,12 @@ const (
|
|||
Bp2BuildTopLevel = "."
|
||||
)
|
||||
|
||||
// Bp2buildAidlLibrary describes a filegroup module that are converted to aidl_library
|
||||
type Bp2buildAidlLibrary interface {
|
||||
ShouldConvertToAidlLibrary(ctx BazelConversionPathContext) bool
|
||||
GetAidlLibraryLabel(ctx BazelConversionPathContext) string
|
||||
}
|
||||
|
||||
type BazelConversionStatus struct {
|
||||
// Information about _all_ bp2build targets generated by this module. Multiple targets are
|
||||
// supported as Soong handles some things within a single target that we may choose to split into
|
||||
|
|
|
@ -42,6 +42,11 @@ type bazelFilegroupAttributes struct {
|
|||
Srcs bazel.LabelListAttribute
|
||||
}
|
||||
|
||||
type bazelAidlLibraryAttributes struct {
|
||||
Srcs bazel.LabelListAttribute
|
||||
Strip_import_prefix *string
|
||||
}
|
||||
|
||||
// ConvertWithBp2build performs bp2build conversion of filegroup
|
||||
func (fg *fileGroup) ConvertWithBp2build(ctx TopDownMutatorContext) {
|
||||
srcs := bazel.MakeLabelListAttribute(
|
||||
|
@ -67,16 +72,33 @@ func (fg *fileGroup) ConvertWithBp2build(ctx TopDownMutatorContext) {
|
|||
}
|
||||
}
|
||||
|
||||
attrs := &bazelFilegroupAttributes{
|
||||
Srcs: srcs,
|
||||
}
|
||||
// Convert module that has only AIDL files to aidl_library
|
||||
// If the module has a mixed bag of AIDL and non-AIDL files, split the filegroup manually
|
||||
// and then convert
|
||||
if fg.ShouldConvertToAidlLibrary(ctx) {
|
||||
attrs := &bazelAidlLibraryAttributes{
|
||||
Srcs: srcs,
|
||||
Strip_import_prefix: fg.properties.Path,
|
||||
}
|
||||
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "filegroup",
|
||||
Bzl_load_location: "//build/bazel/rules:filegroup.bzl",
|
||||
}
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "aidl_library",
|
||||
Bzl_load_location: "//build/bazel/rules/aidl:library.bzl",
|
||||
}
|
||||
|
||||
ctx.CreateBazelTargetModule(props, CommonAttributes{Name: fg.Name()}, attrs)
|
||||
ctx.CreateBazelTargetModule(props, CommonAttributes{Name: fg.Name()}, attrs)
|
||||
} else {
|
||||
attrs := &bazelFilegroupAttributes{
|
||||
Srcs: srcs,
|
||||
}
|
||||
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "filegroup",
|
||||
Bzl_load_location: "//build/bazel/rules:filegroup.bzl",
|
||||
}
|
||||
|
||||
ctx.CreateBazelTargetModule(props, CommonAttributes{Name: fg.Name()}, attrs)
|
||||
}
|
||||
}
|
||||
|
||||
type fileGroupProperties struct {
|
||||
|
@ -99,12 +121,14 @@ type fileGroupProperties struct {
|
|||
type fileGroup struct {
|
||||
ModuleBase
|
||||
BazelModuleBase
|
||||
Bp2buildAidlLibrary
|
||||
properties fileGroupProperties
|
||||
srcs Paths
|
||||
}
|
||||
|
||||
var _ MixedBuildBuildable = (*fileGroup)(nil)
|
||||
var _ SourceFileProducer = (*fileGroup)(nil)
|
||||
var _ Bp2buildAidlLibrary = (*fileGroup)(nil)
|
||||
|
||||
// filegroup contains a list of files that are referenced by other modules
|
||||
// properties (such as "srcs") using the syntax ":<name>". filegroup are
|
||||
|
@ -188,3 +212,23 @@ func (fg *fileGroup) ProcessBazelQueryResponse(ctx ModuleContext) {
|
|||
}
|
||||
fg.srcs = bazelOuts
|
||||
}
|
||||
|
||||
func (fg *fileGroup) ShouldConvertToAidlLibrary(ctx BazelConversionPathContext) bool {
|
||||
if len(fg.properties.Srcs) == 0 || !fg.ShouldConvertWithBp2build(ctx) {
|
||||
return false
|
||||
}
|
||||
for _, src := range fg.properties.Srcs {
|
||||
if !strings.HasSuffix(src, ".aidl") {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (fg *fileGroup) GetAidlLibraryLabel(ctx BazelConversionPathContext) string {
|
||||
if ctx.OtherModuleDir(fg.module) == ctx.ModuleDir() {
|
||||
return ":" + fg.Name()
|
||||
} else {
|
||||
return fg.GetBazelLabel(ctx, fg)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,3 +56,68 @@ filegroup {
|
|||
ExpectedErr: fmt.Errorf("filegroup 'foo' cannot contain a file with the same name"),
|
||||
})
|
||||
}
|
||||
|
||||
func TestFilegroupWithAidlSrcs(t *testing.T) {
|
||||
testcases := []struct {
|
||||
name string
|
||||
bp string
|
||||
expectedBazelAttrs AttrNameToString
|
||||
}{
|
||||
{
|
||||
name: "filegroup with only aidl srcs",
|
||||
bp: `
|
||||
filegroup {
|
||||
name: "foo",
|
||||
srcs: ["aidl/foo.aidl"],
|
||||
path: "aidl",
|
||||
}`,
|
||||
expectedBazelAttrs: AttrNameToString{
|
||||
"srcs": `["aidl/foo.aidl"]`,
|
||||
"strip_import_prefix": `"aidl"`,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "filegroup without path",
|
||||
bp: `
|
||||
filegroup {
|
||||
name: "foo",
|
||||
srcs: ["aidl/foo.aidl"],
|
||||
}`,
|
||||
expectedBazelAttrs: AttrNameToString{
|
||||
"srcs": `["aidl/foo.aidl"]`,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testcases {
|
||||
expectedBazelTargets := []string{
|
||||
MakeBazelTargetNoRestrictions("aidl_library", "foo", test.expectedBazelAttrs),
|
||||
}
|
||||
runFilegroupTestCase(t, Bp2buildTestCase{
|
||||
Description: test.name,
|
||||
Blueprint: test.bp,
|
||||
ExpectedBazelTargets: expectedBazelTargets,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilegroupWithAidlAndNonAidlSrcs(t *testing.T) {
|
||||
runFilegroupTestCase(t, Bp2buildTestCase{
|
||||
Description: "filegroup with aidl and non-aidl srcs",
|
||||
Filesystem: map[string]string{},
|
||||
Blueprint: `
|
||||
filegroup {
|
||||
name: "foo",
|
||||
srcs: [
|
||||
"aidl/foo.aidl",
|
||||
"buf.proto",
|
||||
],
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTargetNoRestrictions("filegroup", "foo", AttrNameToString{
|
||||
"srcs": `[
|
||||
"aidl/foo.aidl",
|
||||
"buf.proto",
|
||||
]`}),
|
||||
}})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue