Use a minimal set of mutators, module types, and singletons for tests

Calling android.NewContext() in tests results in a context that
contains all the mutators, module types, and singletons, which
causes unexpected interactions in unit tests.  Create an empty
context instead, and add in only the necessary mutators, module
types, and singletons.

Bug: 36366816
Test: soong tests
Change-Id: Ic61262c37e3436b3ad4ccaca18b737021c304be6
This commit is contained in:
Colin Cross
2017-03-16 16:50:10 -07:00
parent 4c48f724e1
commit 795c377e14
4 changed files with 74 additions and 49 deletions

View File

@@ -15,8 +15,6 @@
package android
import (
"sync"
"github.com/google/blueprint"
)
@@ -51,8 +49,6 @@ func RegisterSingletonType(name string, factory blueprint.SingletonFactory) {
singletons = append(singletons, singleton{name, factory})
}
var registerMutatorsOnce sync.Once
func NewContext() *blueprint.Context {
ctx := blueprint.NewContext()
@@ -64,19 +60,8 @@ func NewContext() *blueprint.Context {
ctx.RegisterSingletonType(t.name, t.factory)
}
registerMutatorsOnce.Do(registerMutators)
registerMutators(ctx)
for _, t := range mutators {
var handle blueprint.MutatorHandle
if t.bottomUpMutator != nil {
handle = ctx.RegisterBottomUpMutator(t.name, t.bottomUpMutator)
} else if t.topDownMutator != nil {
handle = ctx.RegisterTopDownMutator(t.name, t.topDownMutator)
}
if t.parallel {
handle.Parallel()
}
}
ctx.RegisterSingletonType("env", EnvSingleton)
return ctx