Use one mutator for all bp2build conversion.
Each conversion required defining a separate mutator, which will each
operate on _all_ modules and requires each to repeat checks whether the
mutator should operator. Instead, we introduce a single mutator and
modules can define a ConvertWithBp2build to implement bp2build
conversion for that module.
Test: bp2build.sh
Bug: 183079158
Change-Id: I99d4b51f441c2903879092c5b56313d606d4338d
diff --git a/android/mutator.go b/android/mutator.go
index bf1cf80..dbd8c04 100644
--- a/android/mutator.go
+++ b/android/mutator.go
@@ -16,7 +16,6 @@
import (
"reflect"
- "sync"
"android/soong/bazel"
@@ -34,12 +33,12 @@
// continue on to GenerateAndroidBuildActions
// RegisterMutatorsForBazelConversion is a alternate registration pipeline for bp2build. Exported for testing.
-func RegisterMutatorsForBazelConversion(ctx *Context, preArchMutators, bp2buildMutators []RegisterMutatorFunc) {
+func RegisterMutatorsForBazelConversion(ctx *Context, preArchMutators []RegisterMutatorFunc) {
mctx := ®isterMutatorsContext{
bazelConversionMode: true,
}
- bp2buildPreArchMutators = append([]RegisterMutatorFunc{
+ bp2buildMutators := append([]RegisterMutatorFunc{
RegisterNamespaceMutator,
RegisterDefaultsPreArchMutators,
// TODO(b/165114590): this is required to resolve deps that are only prebuilts, but we should
@@ -47,10 +46,7 @@
RegisterPrebuiltsPreArchMutators,
},
preArchMutators...)
-
- for _, f := range bp2buildPreArchMutators {
- f(mctx)
- }
+ bp2buildMutators = append(bp2buildMutators, registerBp2buildConversionMutator)
// Register bp2build mutators
for _, f := range bp2buildMutators {
@@ -216,10 +212,6 @@
}
var bp2buildPreArchMutators = []RegisterMutatorFunc{}
-var bp2buildMutators = map[string]RegisterMutatorFunc{}
-
-// See http://b/192523357
-var bp2buildLock sync.Mutex
// A minimal context for Bp2build conversion
type Bp2buildMutatorContext interface {
@@ -228,21 +220,6 @@
CreateBazelTargetModule(bazel.BazelTargetModuleProperties, CommonAttributes, interface{})
}
-// RegisterBp2BuildMutator registers specially crafted mutators for
-// converting Blueprint/Android modules into special modules that can
-// be code-generated into Bazel BUILD targets.
-//
-// TODO(b/178068862): bring this into TestContext.
-func RegisterBp2BuildMutator(moduleType string, m func(TopDownMutatorContext)) {
- f := func(ctx RegisterMutatorsContext) {
- ctx.TopDown(moduleType, m)
- }
- // Use a lock to avoid a concurrent map write if RegisterBp2BuildMutator is called in parallel
- bp2buildLock.Lock()
- defer bp2buildLock.Unlock()
- bp2buildMutators[moduleType] = f
-}
-
// PreArchBp2BuildMutators adds mutators to be register for converting Android Blueprint modules
// into Bazel BUILD targets that should run prior to deps and conversion.
func PreArchBp2BuildMutators(f RegisterMutatorFunc) {