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.bp b/Android.bp
index 0202ea7..0ba669c 100644
--- a/Android.bp
+++ b/Android.bp
@@ -45,7 +45,6 @@
     ],
     srcs: [
         "doc.go",
-        "register.go",
     ],
 }
 
@@ -73,6 +72,7 @@
         "android/onceper.go",
         "android/package_ctx.go",
         "android/paths.go",
+        "android/register.go",
         "android/util.go",
         "android/variable.go",
 
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/register.go b/android/register.go
similarity index 76%
rename from register.go
rename to android/register.go
index 2a1bd91..7cc9d50 100644
--- a/register.go
+++ b/android/register.go
@@ -12,7 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package soong
+package android
 
 import "github.com/google/blueprint"
 
@@ -47,27 +47,6 @@
 	singletons = append(singletons, singleton{name, factory})
 }
 
-func RegisterBottomUpMutator(name string, m blueprint.BottomUpMutator) MutatorHandle {
-	mutator := &mutator{name: name, bottomUpMutator: m}
-	mutators = append(mutators, mutator)
-	return mutator
-}
-
-func RegisterTopDownMutator(name string, m blueprint.TopDownMutator) MutatorHandle {
-	mutator := &mutator{name: name, topDownMutator: m}
-	mutators = append(mutators, mutator)
-	return mutator
-}
-
-type MutatorHandle interface {
-	Parallel() MutatorHandle
-}
-
-func (mutator *mutator) Parallel() MutatorHandle {
-	mutator.parallel = true
-	return mutator
-}
-
 func NewContext() *blueprint.Context {
 	ctx := blueprint.NewContext()
 
diff --git a/cc/binary.go b/cc/binary.go
index 083cf0d..0965886 100644
--- a/cc/binary.go
+++ b/cc/binary.go
@@ -18,7 +18,6 @@
 	"github.com/google/blueprint"
 	"github.com/google/blueprint/proptools"
 
-	"android/soong"
 	"android/soong/android"
 )
 
@@ -42,8 +41,8 @@
 }
 
 func init() {
-	soong.RegisterModuleType("cc_binary", binaryFactory)
-	soong.RegisterModuleType("cc_binary_host", binaryHostFactory)
+	android.RegisterModuleType("cc_binary", binaryFactory)
+	android.RegisterModuleType("cc_binary_host", binaryHostFactory)
 }
 
 // Module factory for binaries
diff --git a/cc/cc.go b/cc/cc.go
index 75292aa..791d9ea 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -26,14 +26,13 @@
 	"github.com/google/blueprint"
 	"github.com/google/blueprint/proptools"
 
-	"android/soong"
 	"android/soong/android"
 	"android/soong/cc/config"
 	"android/soong/genrule"
 )
 
 func init() {
-	soong.RegisterModuleType("cc_defaults", defaultsFactory)
+	android.RegisterModuleType("cc_defaults", defaultsFactory)
 
 	// LinkageMutator must be registered after common.ArchMutator, but that is guaranteed by
 	// the Go initialization order because this package depends on common, so common's init
diff --git a/cc/library.go b/cc/library.go
index 2c5f22f..cb4dc61 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -20,7 +20,6 @@
 	"github.com/google/blueprint"
 	"github.com/google/blueprint/pathtools"
 
-	"android/soong"
 	"android/soong/android"
 )
 
@@ -77,11 +76,11 @@
 }
 
 func init() {
-	soong.RegisterModuleType("cc_library_static", libraryStaticFactory)
-	soong.RegisterModuleType("cc_library_shared", librarySharedFactory)
-	soong.RegisterModuleType("cc_library", libraryFactory)
-	soong.RegisterModuleType("cc_library_host_static", libraryHostStaticFactory)
-	soong.RegisterModuleType("cc_library_host_shared", libraryHostSharedFactory)
+	android.RegisterModuleType("cc_library_static", libraryStaticFactory)
+	android.RegisterModuleType("cc_library_shared", librarySharedFactory)
+	android.RegisterModuleType("cc_library", libraryFactory)
+	android.RegisterModuleType("cc_library_host_static", libraryHostStaticFactory)
+	android.RegisterModuleType("cc_library_host_shared", libraryHostSharedFactory)
 }
 
 // Module factory for combined static + shared libraries, device by default but with possible host
diff --git a/cc/ndk_prebuilt.go b/cc/ndk_prebuilt.go
index 407a026..106c9b5 100644
--- a/cc/ndk_prebuilt.go
+++ b/cc/ndk_prebuilt.go
@@ -20,16 +20,15 @@
 
 	"github.com/google/blueprint"
 
-	"android/soong"
 	"android/soong/android"
 	"android/soong/cc/config"
 )
 
 func init() {
-	soong.RegisterModuleType("ndk_prebuilt_library", ndkPrebuiltLibraryFactory)
-	soong.RegisterModuleType("ndk_prebuilt_object", ndkPrebuiltObjectFactory)
-	soong.RegisterModuleType("ndk_prebuilt_static_stl", ndkPrebuiltStaticStlFactory)
-	soong.RegisterModuleType("ndk_prebuilt_shared_stl", ndkPrebuiltSharedStlFactory)
+	android.RegisterModuleType("ndk_prebuilt_library", ndkPrebuiltLibraryFactory)
+	android.RegisterModuleType("ndk_prebuilt_object", ndkPrebuiltObjectFactory)
+	android.RegisterModuleType("ndk_prebuilt_static_stl", ndkPrebuiltStaticStlFactory)
+	android.RegisterModuleType("ndk_prebuilt_shared_stl", ndkPrebuiltSharedStlFactory)
 }
 
 // NDK prebuilt libraries.
diff --git a/cc/ndk_sysroot.go b/cc/ndk_sysroot.go
index 144d91c..cbdaa26 100644
--- a/cc/ndk_sysroot.go
+++ b/cc/ndk_sysroot.go
@@ -55,14 +55,13 @@
 import (
 	"github.com/google/blueprint"
 
-	"android/soong"
 	"android/soong/android"
 )
 
 func init() {
-	soong.RegisterModuleType("ndk_headers", ndkHeadersFactory)
-	soong.RegisterModuleType("ndk_library", ndkLibraryFactory)
-	soong.RegisterSingletonType("ndk", NdkSingleton)
+	android.RegisterModuleType("ndk_headers", ndkHeadersFactory)
+	android.RegisterModuleType("ndk_library", ndkLibraryFactory)
+	android.RegisterSingletonType("ndk", NdkSingleton)
 
 	pctx.Import("android/soong/common")
 }
diff --git a/cc/object.go b/cc/object.go
index c9f0a06..72fd55b 100644
--- a/cc/object.go
+++ b/cc/object.go
@@ -19,7 +19,6 @@
 
 	"github.com/google/blueprint"
 
-	"android/soong"
 	"android/soong/android"
 )
 
@@ -28,7 +27,7 @@
 //
 
 func init() {
-	soong.RegisterModuleType("cc_object", objectFactory)
+	android.RegisterModuleType("cc_object", objectFactory)
 }
 
 type objectLinker struct {
diff --git a/cc/test.go b/cc/test.go
index 9c7c0de..9cc30c9 100644
--- a/cc/test.go
+++ b/cc/test.go
@@ -21,7 +21,6 @@
 
 	"github.com/google/blueprint"
 
-	"android/soong"
 	"android/soong/android"
 )
 
@@ -37,11 +36,11 @@
 }
 
 func init() {
-	soong.RegisterModuleType("cc_test", testFactory)
-	soong.RegisterModuleType("cc_test_library", testLibraryFactory)
-	soong.RegisterModuleType("cc_benchmark", benchmarkFactory)
-	soong.RegisterModuleType("cc_test_host", testHostFactory)
-	soong.RegisterModuleType("cc_benchmark_host", benchmarkHostFactory)
+	android.RegisterModuleType("cc_test", testFactory)
+	android.RegisterModuleType("cc_test_library", testLibraryFactory)
+	android.RegisterModuleType("cc_benchmark", benchmarkFactory)
+	android.RegisterModuleType("cc_test_host", testHostFactory)
+	android.RegisterModuleType("cc_benchmark_host", benchmarkHostFactory)
 }
 
 // Module factory for tests
diff --git a/cc/toolchain_library.go b/cc/toolchain_library.go
index 0548da9..0097ca3 100644
--- a/cc/toolchain_library.go
+++ b/cc/toolchain_library.go
@@ -18,7 +18,6 @@
 	"github.com/google/blueprint"
 	"github.com/google/blueprint/proptools"
 
-	"android/soong"
 	"android/soong/android"
 )
 
@@ -27,7 +26,7 @@
 //
 
 func init() {
-	soong.RegisterModuleType("toolchain_library", toolchainLibraryFactory)
+	android.RegisterModuleType("toolchain_library", toolchainLibraryFactory)
 }
 
 type toolchainLibraryDecorator struct {
diff --git a/cmd/soong_build/main.go b/cmd/soong_build/main.go
index 5b0c83c..ed8f2fd 100644
--- a/cmd/soong_build/main.go
+++ b/cmd/soong_build/main.go
@@ -22,8 +22,6 @@
 
 	"github.com/google/blueprint/bootstrap"
 
-	"android/soong"
-
 	"android/soong/android"
 )
 
@@ -33,7 +31,7 @@
 	// The top-level Blueprints file is passed as the first argument.
 	srcDir := filepath.Dir(flag.Arg(0))
 
-	ctx := soong.NewContext()
+	ctx := android.NewContext()
 
 	configuration, err := android.NewConfig(srcDir, bootstrap.BuildDir)
 	if err != nil {
diff --git a/genrule/genrule.go b/genrule/genrule.go
index 4a9b336..baa6b33 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -19,13 +19,12 @@
 
 	"github.com/google/blueprint"
 
-	"android/soong"
 	"android/soong/android"
 )
 
 func init() {
-	soong.RegisterModuleType("gensrcs", GenSrcsFactory)
-	soong.RegisterModuleType("genrule", GenRuleFactory)
+	android.RegisterModuleType("gensrcs", GenSrcsFactory)
+	android.RegisterModuleType("genrule", GenRuleFactory)
 
 	android.RegisterBottomUpMutator("genrule_deps", genruleDepsMutator).Parallel()
 }
diff --git a/java/java.go b/java/java.go
index 315ee49..808e1db 100644
--- a/java/java.go
+++ b/java/java.go
@@ -24,22 +24,21 @@
 
 	"github.com/google/blueprint"
 
-	"android/soong"
 	"android/soong/android"
 	"android/soong/genrule"
 )
 
 func init() {
-	soong.RegisterModuleType("java_library", JavaLibraryFactory)
-	soong.RegisterModuleType("java_library_static", JavaLibraryFactory)
-	soong.RegisterModuleType("java_library_host", JavaLibraryHostFactory)
-	soong.RegisterModuleType("java_binary", JavaBinaryFactory)
-	soong.RegisterModuleType("java_binary_host", JavaBinaryHostFactory)
-	soong.RegisterModuleType("prebuilt_java_library", JavaPrebuiltFactory)
-	soong.RegisterModuleType("prebuilt_sdk", SdkPrebuiltFactory)
-	soong.RegisterModuleType("android_app", AndroidAppFactory)
+	android.RegisterModuleType("java_library", JavaLibraryFactory)
+	android.RegisterModuleType("java_library_static", JavaLibraryFactory)
+	android.RegisterModuleType("java_library_host", JavaLibraryHostFactory)
+	android.RegisterModuleType("java_binary", JavaBinaryFactory)
+	android.RegisterModuleType("java_binary_host", JavaBinaryHostFactory)
+	android.RegisterModuleType("prebuilt_java_library", JavaPrebuiltFactory)
+	android.RegisterModuleType("prebuilt_sdk", SdkPrebuiltFactory)
+	android.RegisterModuleType("android_app", AndroidAppFactory)
 
-	soong.RegisterSingletonType("logtags", LogtagsSingleton)
+	android.RegisterSingletonType("logtags", LogtagsSingleton)
 }
 
 // TODO: