Move registration into android package
Mutator registration is tightly coupled with the android package, move
all registration from the soong package to the android package.
Test: build.ninja identical
Change-Id: Ie183d0b52cc7431c9e05b231934d189208ef1efe
diff --git a/android/androidmk.go b/android/androidmk.go
index a408933..28c2290 100644
--- a/android/androidmk.go
+++ b/android/androidmk.go
@@ -24,14 +24,12 @@
"sort"
"strings"
- "android/soong"
-
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
)
func init() {
- soong.RegisterSingletonType("androidmk", AndroidMkSingleton)
+ RegisterSingletonType("androidmk", AndroidMkSingleton)
}
type AndroidMkDataProvider interface {
diff --git a/android/env.go b/android/env.go
index f9d8030..3b523a2 100644
--- a/android/env.go
+++ b/android/env.go
@@ -15,7 +15,6 @@
package android
import (
- "android/soong"
"android/soong/env"
"github.com/google/blueprint"
@@ -29,7 +28,7 @@
// a manifest regeneration.
func init() {
- soong.RegisterSingletonType("env", EnvSingleton)
+ RegisterSingletonType("env", EnvSingleton)
}
func EnvSingleton() blueprint.Singleton {
diff --git a/android/makevars.go b/android/makevars.go
index e431f11..482fbde 100644
--- a/android/makevars.go
+++ b/android/makevars.go
@@ -20,8 +20,6 @@
"io/ioutil"
"os"
- "android/soong"
-
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
)
@@ -66,7 +64,7 @@
///////////////////////////////////////////////////////////////////////////////
func init() {
- soong.RegisterSingletonType("makevars", makeVarsSingletonFunc)
+ RegisterSingletonType("makevars", makeVarsSingletonFunc)
}
func makeVarsSingletonFunc() blueprint.Singleton {
diff --git a/android/module.go b/android/module.go
index 00219ae..d6eee44 100644
--- a/android/module.go
+++ b/android/module.go
@@ -19,7 +19,6 @@
"path/filepath"
"strings"
- "android/soong"
"android/soong/glob"
"github.com/google/blueprint"
@@ -710,7 +709,7 @@
}
func init() {
- soong.RegisterSingletonType("buildtarget", BuildTargetSingleton)
+ RegisterSingletonType("buildtarget", BuildTargetSingleton)
}
func BuildTargetSingleton() blueprint.Singleton {
diff --git a/android/mutator.go b/android/mutator.go
index 3d5a177..ff2f9ad 100644
--- a/android/mutator.go
+++ b/android/mutator.go
@@ -14,11 +14,7 @@
package android
-import (
- "android/soong"
-
- "github.com/google/blueprint"
-)
+import "github.com/google/blueprint"
type AndroidTopDownMutator func(TopDownMutatorContext)
@@ -44,26 +40,41 @@
androidBaseContextImpl
}
-func RegisterBottomUpMutator(name string, mutator AndroidBottomUpMutator) soong.MutatorHandle {
- return soong.RegisterBottomUpMutator(name, func(ctx blueprint.BottomUpMutatorContext) {
+func RegisterBottomUpMutator(name string, m AndroidBottomUpMutator) MutatorHandle {
+ f := func(ctx blueprint.BottomUpMutatorContext) {
if a, ok := ctx.Module().(Module); ok {
actx := &androidBottomUpMutatorContext{
BottomUpMutatorContext: ctx,
androidBaseContextImpl: a.base().androidBaseContextFactory(ctx),
}
- mutator(actx)
+ m(actx)
}
- })
+ }
+ mutator := &mutator{name: name, bottomUpMutator: f}
+ mutators = append(mutators, mutator)
+ return mutator
}
-func RegisterTopDownMutator(name string, mutator AndroidTopDownMutator) soong.MutatorHandle {
- return soong.RegisterTopDownMutator(name, func(ctx blueprint.TopDownMutatorContext) {
+func RegisterTopDownMutator(name string, m AndroidTopDownMutator) MutatorHandle {
+ f := func(ctx blueprint.TopDownMutatorContext) {
if a, ok := ctx.Module().(Module); ok {
actx := &androidTopDownMutatorContext{
TopDownMutatorContext: ctx,
androidBaseContextImpl: a.base().androidBaseContextFactory(ctx),
}
- mutator(actx)
+ m(actx)
}
- })
+ }
+ mutator := &mutator{name: name, topDownMutator: f}
+ mutators = append(mutators, mutator)
+ return mutator
+}
+
+type MutatorHandle interface {
+ Parallel() MutatorHandle
+}
+
+func (mutator *mutator) Parallel() MutatorHandle {
+ mutator.parallel = true
+ return mutator
}
diff --git a/android/register.go b/android/register.go
new file mode 100644
index 0000000..7cc9d50
--- /dev/null
+++ b/android/register.go
@@ -0,0 +1,74 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package android
+
+import "github.com/google/blueprint"
+
+type moduleType struct {
+ name string
+ factory blueprint.ModuleFactory
+}
+
+var moduleTypes []moduleType
+
+type singleton struct {
+ name string
+ factory blueprint.SingletonFactory
+}
+
+var singletons []singleton
+
+type mutator struct {
+ name string
+ bottomUpMutator blueprint.BottomUpMutator
+ topDownMutator blueprint.TopDownMutator
+ parallel bool
+}
+
+var mutators []*mutator
+
+func RegisterModuleType(name string, factory blueprint.ModuleFactory) {
+ moduleTypes = append(moduleTypes, moduleType{name, factory})
+}
+
+func RegisterSingletonType(name string, factory blueprint.SingletonFactory) {
+ singletons = append(singletons, singleton{name, factory})
+}
+
+func NewContext() *blueprint.Context {
+ ctx := blueprint.NewContext()
+
+ for _, t := range moduleTypes {
+ ctx.RegisterModuleType(t.name, t.factory)
+ }
+
+ for _, t := range singletons {
+ ctx.RegisterSingletonType(t.name, t.factory)
+ }
+
+ 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()
+ }
+ }
+
+ return ctx
+}