Make bp2buildMutators registration local to TestContext.

The previous implementation relied on the implicit registration of Bp2Build mutators, resulting in test non-hermeticity. Refactor bp2build tests to explicitly specify the bp2build mutators under test.

Test: Soong tests

Test: TH
Change-Id: I9b9674bad1ea533b3bd31b07077a9e02c99b4c1d
This commit is contained in:
Jingwen Chen
2021-01-26 21:57:27 -05:00
parent 801a669566
commit a42d6417b3
4 changed files with 41 additions and 32 deletions

View File

@@ -23,7 +23,7 @@ import (
func init() {
RegisterModuleType("filegroup", FileGroupFactory)
RegisterBp2BuildMutator("filegroup", bp2buildMutator)
RegisterBp2BuildMutator("filegroup", FilegroupBp2Build)
}
// https://docs.bazel.build/versions/master/be/general.html#filegroup
@@ -51,7 +51,7 @@ func (bfg *bazelFilegroup) Name() string {
func (bfg *bazelFilegroup) GenerateAndroidBuildActions(ctx ModuleContext) {}
// TODO: Create helper functions to avoid this boilerplate.
func bp2buildMutator(ctx TopDownMutatorContext) {
func FilegroupBp2Build(ctx TopDownMutatorContext) {
if m, ok := ctx.Module().(*fileGroup); ok {
name := "__bp2build__" + m.base().BaseModuleName()
ctx.CreateModule(BazelFileGroupFactory, &bazelFilegroupAttributes{