Treat src=name filegroups as handcrafted targets
This is groundwork for allowlist v2, as such targets are still effectively referencable via their file syntax; thus, rdep targets of these filegroups should still be treated as convertible. Fixes: 302025822 Test: Unit test update Change-Id: I93445ff75e7c0570530725d086e47c1532833c06
This commit is contained in:
parent
dec9ce6693
commit
2ef472be7a
2 changed files with 16 additions and 3 deletions
|
@ -22,7 +22,6 @@ import (
|
||||||
"android/soong/bazel"
|
"android/soong/bazel"
|
||||||
"android/soong/bazel/cquery"
|
"android/soong/bazel/cquery"
|
||||||
"android/soong/ui/metrics/bp2build_metrics_proto"
|
"android/soong/ui/metrics/bp2build_metrics_proto"
|
||||||
|
|
||||||
"github.com/google/blueprint"
|
"github.com/google/blueprint"
|
||||||
"github.com/google/blueprint/proptools"
|
"github.com/google/blueprint/proptools"
|
||||||
)
|
)
|
||||||
|
@ -106,8 +105,10 @@ func (fg *fileGroup) ConvertWithBp2build(ctx Bp2buildMutatorContext) {
|
||||||
if f.Label == fg.Name() {
|
if f.Label == fg.Name() {
|
||||||
if len(srcs.Value.Includes) > 1 {
|
if len(srcs.Value.Includes) > 1 {
|
||||||
ctx.ModuleErrorf("filegroup '%s' cannot contain a file with the same name", fg.Name())
|
ctx.ModuleErrorf("filegroup '%s' cannot contain a file with the same name", fg.Name())
|
||||||
}
|
|
||||||
ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_SRC_NAME_COLLISION, "")
|
ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_SRC_NAME_COLLISION, "")
|
||||||
|
} else {
|
||||||
|
panic("This situation should have been handled by FileGroupFactory's call to InitBazelModuleAsHandcrafted")
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -253,6 +254,16 @@ func FileGroupFactory() Module {
|
||||||
module.AddProperties(&module.properties)
|
module.AddProperties(&module.properties)
|
||||||
InitAndroidModule(module)
|
InitAndroidModule(module)
|
||||||
InitBazelModule(module)
|
InitBazelModule(module)
|
||||||
|
AddBazelHandcraftedHook(module, func(ctx LoadHookContext) string {
|
||||||
|
// If there is a single src with the same name as the filegroup module name,
|
||||||
|
// then don't generate this filegroup. It will be OK for other targets
|
||||||
|
// to depend on this source file by name directly.
|
||||||
|
fg := ctx.Module().(*fileGroup)
|
||||||
|
if len(fg.properties.Srcs) == 1 && fg.Name() == fg.properties.Srcs[0] {
|
||||||
|
return fg.Name()
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
})
|
||||||
InitDefaultableModule(module)
|
InitDefaultableModule(module)
|
||||||
return module
|
return module
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,9 @@ filegroup {
|
||||||
srcs: ["foo"],
|
srcs: ["foo"],
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
ExpectedBazelTargets: []string{}})
|
ExpectedBazelTargets: []string{},
|
||||||
|
ExpectedHandcraftedModules: []string{"foo"}},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilegroupSameNameAsFile_MultipleFiles(t *testing.T) {
|
func TestFilegroupSameNameAsFile_MultipleFiles(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue