summaryrefslogtreecommitdiff
path: root/android/filegroup.go
diff options
context:
space:
mode:
Diffstat (limited to 'android/filegroup.go')
-rw-r--r--android/filegroup.go75
1 files changed, 62 insertions, 13 deletions
diff --git a/android/filegroup.go b/android/filegroup.go
index 9e5769a82..7d3923814 100644
--- a/android/filegroup.go
+++ b/android/filegroup.go
@@ -15,6 +15,7 @@
package android
import (
+ "path/filepath"
"strings"
"android/soong/bazel"
@@ -41,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(
@@ -66,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 {
@@ -98,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
@@ -164,12 +189,17 @@ func (fg *fileGroup) IsMixedBuildSupported(ctx BaseModuleContext) bool {
}
func (fg *fileGroup) ProcessBazelQueryResponse(ctx ModuleContext) {
- fg.srcs = PathsForModuleSrcExcludes(ctx, fg.properties.Srcs, fg.properties.Exclude_srcs)
+ bazelCtx := ctx.Config().BazelContext
+ // This is a short-term solution because we rely on info from Android.bp to handle
+ // a converted module. This will block when we want to remove Android.bp for all
+ // converted modules at some point.
+ // TODO(b/242847534): Implement a long-term solution in which we don't need to rely
+ // on info form Android.bp for modules that are already converted to Bazel
+ relativeRoot := ctx.ModuleDir()
if fg.properties.Path != nil {
- fg.srcs = PathsWithModuleSrcSubDir(ctx, fg.srcs, String(fg.properties.Path))
+ relativeRoot = filepath.Join(relativeRoot, *fg.properties.Path)
}
- bazelCtx := ctx.Config().BazelContext
filePaths, err := bazelCtx.GetOutputFiles(fg.GetBazelLabel(ctx, fg), configKey{Common.String(), CommonOS})
if err != nil {
ctx.ModuleErrorf(err.Error())
@@ -178,8 +208,27 @@ func (fg *fileGroup) ProcessBazelQueryResponse(ctx ModuleContext) {
bazelOuts := make(Paths, 0, len(filePaths))
for _, p := range filePaths {
- bazelOuts = append(bazelOuts, PathForBazelOutRelative(ctx, ctx.ModuleDir(), p))
+ bazelOuts = append(bazelOuts, PathForBazelOutRelative(ctx, relativeRoot, p))
}
-
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)
+ }
+}