diff options
| -rw-r--r-- | android/allowlists/allowlists.go | 8 | ||||
| -rw-r--r-- | android/bazel.go | 6 | ||||
| -rw-r--r-- | android/filegroup.go | 60 | ||||
| -rw-r--r-- | bp2build/filegroup_conversion_test.go | 65 |
4 files changed, 131 insertions, 8 deletions
diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go index 9c6ee34fc..a932a9128 100644 --- a/android/allowlists/allowlists.go +++ b/android/allowlists/allowlists.go @@ -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{ diff --git a/android/bazel.go b/android/bazel.go index 183a2f324..aff611660 100644 --- a/android/bazel.go +++ b/android/bazel.go @@ -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 diff --git a/android/filegroup.go b/android/filegroup.go index 504223de9..7d3923814 100644 --- a/android/filegroup.go +++ b/android/filegroup.go @@ -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) + } 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) + 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) + } +} diff --git a/bp2build/filegroup_conversion_test.go b/bp2build/filegroup_conversion_test.go index b598b855e..de09a1787 100644 --- a/bp2build/filegroup_conversion_test.go +++ b/bp2build/filegroup_conversion_test.go @@ -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", + ]`}), + }}) +} |