summaryrefslogtreecommitdiff
path: root/android/filegroup.go
diff options
context:
space:
mode:
Diffstat (limited to 'android/filegroup.go')
-rw-r--r--android/filegroup.go23
1 files changed, 22 insertions, 1 deletions
diff --git a/android/filegroup.go b/android/filegroup.go
index 54d01d39f..4db165f87 100644
--- a/android/filegroup.go
+++ b/android/filegroup.go
@@ -42,6 +42,27 @@ func FilegroupBp2Build(ctx TopDownMutatorContext) {
srcs := bazel.MakeLabelListAttribute(
BazelLabelForModuleSrcExcludes(ctx, fg.properties.Srcs, fg.properties.Exclude_srcs))
+
+ // For Bazel compatibility, don't generate the filegroup if there is only 1
+ // source file, and that the source file is named the same as the module
+ // itself. In Bazel, eponymous filegroups like this would be an error.
+ //
+ // Instead, dependents on this single-file filegroup can just depend
+ // on the file target, instead of rule target, directly.
+ //
+ // You may ask: what if a filegroup has multiple files, and one of them
+ // shares the name? The answer: we haven't seen that in the wild, and
+ // should lock Soong itself down to prevent the behavior. For now,
+ // we raise an error if bp2build sees this problem.
+ for _, f := range srcs.Value.Includes {
+ if f.Label == fg.Name() {
+ if len(srcs.Value.Includes) > 1 {
+ ctx.ModuleErrorf("filegroup '%s' cannot contain a file with the same name", fg.Name())
+ }
+ return
+ }
+ }
+
attrs := &bazelFilegroupAttributes{
Srcs: srcs,
}
@@ -97,7 +118,7 @@ func (fg *fileGroup) GenerateBazelBuildActions(ctx ModuleContext) bool {
}
bazelCtx := ctx.Config().BazelContext
- filePaths, ok := bazelCtx.GetOutputFiles(fg.GetBazelLabel(ctx, fg), ctx.Arch().ArchType)
+ filePaths, ok := bazelCtx.GetOutputFiles(fg.GetBazelLabel(ctx, fg), Common)
if !ok {
return false
}