Pass Config to NewTestContext instead of ctx.Register

Prepare for using Config when adding singletons by passing
Config to NewTestContext and NewContext instead of to ctx.Register.
This will enable a followup change to store SingletonMakeVarsProviders
registered on the Context in the Config, which is necessary to run
multiple tests in parallel without data races.

Test: all soong tests
Change-Id: Id229629a4e42ff4487d317241673837726c075fc
diff --git a/android/androidmk_test.go b/android/androidmk_test.go
index a558f45..10527b9 100644
--- a/android/androidmk_test.go
+++ b/android/androidmk_test.go
@@ -80,10 +80,10 @@
 	config := TestConfig(buildDir, nil, bp, nil)
 	config.inMake = true // Enable androidmk Singleton
 
-	ctx := NewTestContext()
+	ctx := NewTestContext(config)
 	ctx.RegisterSingletonType("androidmk", AndroidMkSingleton)
 	ctx.RegisterModuleType("custom", customModuleFactory)
-	ctx.Register(config)
+	ctx.Register()
 
 	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
 	FailIfErrored(t, errs)
@@ -252,10 +252,10 @@
 		config := TestConfig(buildDir, nil, testCase.bp, nil)
 		config.inMake = true // Enable androidmk Singleton
 
-		ctx := NewTestContext()
+		ctx := NewTestContext(config)
 		ctx.RegisterSingletonType("androidmk", AndroidMkSingleton)
 		ctx.RegisterModuleType("custom", customModuleFactory)
-		ctx.Register(config)
+		ctx.Register()
 
 		_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
 		FailIfErrored(t, errs)
diff --git a/android/arch_test.go b/android/arch_test.go
index 8525b03..4cef4c8 100644
--- a/android/arch_test.go
+++ b/android/arch_test.go
@@ -353,9 +353,9 @@
 		t.Run(tt.name, func(t *testing.T) {
 			config := TestArchConfig(buildDir, nil, bp, nil)
 
-			ctx := NewTestArchContext()
+			ctx := NewTestArchContext(config)
 			ctx.RegisterModuleType("module", archTestModuleFactory)
-			ctx.Register(config)
+			ctx.Register()
 			if tt.config != nil {
 				tt.config(config)
 			}
@@ -442,9 +442,9 @@
 		t.Run(tt.name, func(t *testing.T) {
 			config := TestArchConfigNativeBridge(buildDir, nil, bp, nil)
 
-			ctx := NewTestArchContext()
+			ctx := NewTestArchContext(config)
 			ctx.RegisterModuleType("module", archTestModuleFactory)
-			ctx.Register(config)
+			ctx.Register()
 			if tt.config != nil {
 				tt.config(config)
 			}
diff --git a/android/csuite_config_test.go b/android/csuite_config_test.go
index bf1a19a..9ac959e 100644
--- a/android/csuite_config_test.go
+++ b/android/csuite_config_test.go
@@ -21,9 +21,9 @@
 func testCSuiteConfig(test *testing.T, bpFileContents string) *TestContext {
 	config := TestArchConfig(buildDir, nil, bpFileContents, nil)
 
-	ctx := NewTestArchContext()
+	ctx := NewTestArchContext(config)
 	ctx.RegisterModuleType("csuite_config", CSuiteConfigFactory)
-	ctx.Register(config)
+	ctx.Register()
 	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
 	FailIfErrored(test, errs)
 	_, errs = ctx.PrepareBuildActions(config)
diff --git a/android/defaults_test.go b/android/defaults_test.go
index d096b2f..2689d86 100644
--- a/android/defaults_test.go
+++ b/android/defaults_test.go
@@ -80,14 +80,14 @@
 
 	config := TestConfig(buildDir, nil, bp, nil)
 
-	ctx := NewTestContext()
+	ctx := NewTestContext(config)
 
 	ctx.RegisterModuleType("test", defaultsTestModuleFactory)
 	ctx.RegisterModuleType("defaults", defaultsTestDefaultsFactory)
 
 	ctx.PreArchMutators(RegisterDefaultsPreArchMutators)
 
-	ctx.Register(config)
+	ctx.Register()
 
 	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
 	FailIfErrored(t, errs)
@@ -125,7 +125,7 @@
 	config := TestConfig(buildDir, nil, bp, nil)
 	config.TestProductVariables.Allow_missing_dependencies = proptools.BoolPtr(true)
 
-	ctx := NewTestContext()
+	ctx := NewTestContext(config)
 	ctx.SetAllowMissingDependencies(true)
 
 	ctx.RegisterModuleType("test", defaultsTestModuleFactory)
@@ -133,7 +133,7 @@
 
 	ctx.PreArchMutators(RegisterDefaultsPreArchMutators)
 
-	ctx.Register(config)
+	ctx.Register()
 
 	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
 	FailIfErrored(t, errs)
diff --git a/android/module_test.go b/android/module_test.go
index 3a039e2..6cc1813 100644
--- a/android/module_test.go
+++ b/android/module_test.go
@@ -164,9 +164,6 @@
 }
 
 func TestErrorDependsOnDisabledModule(t *testing.T) {
-	ctx := NewTestContext()
-	ctx.RegisterModuleType("deps", depsModuleFactory)
-
 	bp := `
 		deps {
 			name: "foo",
@@ -180,7 +177,9 @@
 
 	config := TestConfig(buildDir, nil, bp, nil)
 
-	ctx.Register(config)
+	ctx := NewTestContext(config)
+	ctx.RegisterModuleType("deps", depsModuleFactory)
+	ctx.Register()
 
 	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
 	FailIfErrored(t, errs)
diff --git a/android/mutator_test.go b/android/mutator_test.go
index 191b535..1c395c7 100644
--- a/android/mutator_test.go
+++ b/android/mutator_test.go
@@ -70,7 +70,7 @@
 	config := TestConfig(buildDir, nil, bp, nil)
 	config.TestProductVariables.Allow_missing_dependencies = proptools.BoolPtr(true)
 
-	ctx := NewTestContext()
+	ctx := NewTestContext(config)
 	ctx.SetAllowMissingDependencies(true)
 
 	ctx.RegisterModuleType("test", mutatorTestModuleFactory)
@@ -78,7 +78,7 @@
 		ctx.TopDown("add_missing_dependencies", addMissingDependenciesMutator)
 	})
 
-	ctx.Register(config)
+	ctx.Register()
 	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
 	FailIfErrored(t, errs)
 	_, errs = ctx.PrepareBuildActions(config)
@@ -92,7 +92,15 @@
 }
 
 func TestModuleString(t *testing.T) {
-	ctx := NewTestContext()
+	bp := `
+		test {
+			name: "foo",
+		}
+	`
+
+	config := TestConfig(buildDir, nil, bp, nil)
+
+	ctx := NewTestContext(config)
 
 	var moduleStrings []string
 
@@ -130,15 +138,7 @@
 
 	ctx.RegisterModuleType("test", mutatorTestModuleFactory)
 
-	bp := `
-		test {
-			name: "foo",
-		}
-	`
-
-	config := TestConfig(buildDir, nil, bp, nil)
-
-	ctx.Register(config)
+	ctx.Register()
 
 	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
 	FailIfErrored(t, errs)
@@ -190,7 +190,21 @@
 }
 
 func TestFinalDepsPhase(t *testing.T) {
-	ctx := NewTestContext()
+	bp := `
+		test {
+			name: "common_dep_1",
+		}
+		test {
+			name: "common_dep_2",
+		}
+		test {
+			name: "foo",
+		}
+	`
+
+	config := TestConfig(buildDir, nil, bp, nil)
+
+	ctx := NewTestContext(config)
 
 	finalGot := map[string]int{}
 
@@ -228,20 +242,7 @@
 
 	ctx.RegisterModuleType("test", mutatorTestModuleFactory)
 
-	bp := `
-		test {
-			name: "common_dep_1",
-		}
-		test {
-			name: "common_dep_2",
-		}
-		test {
-			name: "foo",
-		}
-	`
-
-	config := TestConfig(buildDir, nil, bp, nil)
-	ctx.Register(config)
+	ctx.Register()
 
 	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
 	FailIfErrored(t, errs)
@@ -267,7 +268,8 @@
 }
 
 func TestNoCreateVariationsInFinalDeps(t *testing.T) {
-	ctx := NewTestContext()
+	config := TestConfig(buildDir, nil, `test {name: "foo"}`, nil)
+	ctx := NewTestContext(config)
 
 	checkErr := func() {
 		if err := recover(); err == nil || !strings.Contains(fmt.Sprintf("%s", err), "not allowed in FinalDepsMutators") {
@@ -287,8 +289,7 @@
 	})
 
 	ctx.RegisterModuleType("test", mutatorTestModuleFactory)
-	config := TestConfig(buildDir, nil, `test {name: "foo"}`, nil)
-	ctx.Register(config)
+	ctx.Register()
 
 	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
 	FailIfErrored(t, errs)
diff --git a/android/namespace_test.go b/android/namespace_test.go
index 66c0d89..45e2cdb 100644
--- a/android/namespace_test.go
+++ b/android/namespace_test.go
@@ -635,7 +635,7 @@
 func setupTestFromFiles(bps map[string][]byte) (ctx *TestContext, errs []error) {
 	config := TestConfig(buildDir, nil, "", bps)
 
-	ctx = NewTestContext()
+	ctx = NewTestContext(config)
 	ctx.RegisterModuleType("test_module", newTestModule)
 	ctx.RegisterModuleType("soong_namespace", NamespaceFactory)
 	ctx.Context.RegisterModuleType("blueprint_test_module", newBlueprintTestModule)
@@ -643,7 +643,7 @@
 	ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
 		ctx.BottomUp("rename", renameMutator)
 	})
-	ctx.Register(config)
+	ctx.Register()
 
 	_, errs = ctx.ParseBlueprintsFiles("Android.bp")
 	if len(errs) > 0 {
diff --git a/android/neverallow_test.go b/android/neverallow_test.go
index 56a07dc..1d454e5 100644
--- a/android/neverallow_test.go
+++ b/android/neverallow_test.go
@@ -359,14 +359,14 @@
 }
 
 func testNeverallow(config Config) (*TestContext, []error) {
-	ctx := NewTestContext()
+	ctx := NewTestContext(config)
 	ctx.RegisterModuleType("cc_library", newMockCcLibraryModule)
 	ctx.RegisterModuleType("java_library", newMockJavaLibraryModule)
 	ctx.RegisterModuleType("java_library_host", newMockJavaLibraryModule)
 	ctx.RegisterModuleType("java_device_for_host", newMockJavaLibraryModule)
 	ctx.RegisterModuleType("makefile_goal", newMockMakefileGoalModule)
 	ctx.PostDepsMutators(RegisterNeverallowMutator)
-	ctx.Register(config)
+	ctx.Register()
 
 	_, errs := ctx.ParseBlueprintsFiles("Android.bp")
 	if len(errs) > 0 {
diff --git a/android/package_test.go b/android/package_test.go
index 04dfc08..ade95d4 100644
--- a/android/package_test.go
+++ b/android/package_test.go
@@ -86,9 +86,9 @@
 	// Create a new config per test as visibility information is stored in the config.
 	config := TestArchConfig(buildDir, nil, "", fs)
 
-	ctx := NewTestArchContext()
+	ctx := NewTestArchContext(config)
 	RegisterPackageBuildComponents(ctx)
-	ctx.Register(config)
+	ctx.Register()
 
 	_, errs := ctx.ParseBlueprintsFiles(".")
 	if len(errs) > 0 {
diff --git a/android/path_properties_test.go b/android/path_properties_test.go
index f367b82..f964d9f 100644
--- a/android/path_properties_test.go
+++ b/android/path_properties_test.go
@@ -116,12 +116,12 @@
 			`
 
 			config := TestArchConfig(buildDir, nil, bp, nil)
-			ctx := NewTestArchContext()
+			ctx := NewTestArchContext(config)
 
 			ctx.RegisterModuleType("test", pathDepsMutatorTestModuleFactory)
 			ctx.RegisterModuleType("filegroup", FileGroupFactory)
 
-			ctx.Register(config)
+			ctx.Register()
 			_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
 			FailIfErrored(t, errs)
 			_, errs = ctx.PrepareBuildActions(config)
diff --git a/android/paths_test.go b/android/paths_test.go
index e7fd763..14a4773 100644
--- a/android/paths_test.go
+++ b/android/paths_test.go
@@ -980,12 +980,6 @@
 func testPathForModuleSrc(t *testing.T, buildDir string, tests []pathForModuleSrcTestCase) {
 	for _, test := range tests {
 		t.Run(test.name, func(t *testing.T) {
-			ctx := NewTestContext()
-
-			ctx.RegisterModuleType("test", pathForModuleSrcTestModuleFactory)
-			ctx.RegisterModuleType("output_file_provider", pathForModuleSrcOutputFileProviderModuleFactory)
-			ctx.RegisterModuleType("filegroup", FileGroupFactory)
-
 			fgBp := `
 				filegroup {
 					name: "a",
@@ -1015,7 +1009,13 @@
 
 			config := TestConfig(buildDir, nil, "", mockFS)
 
-			ctx.Register(config)
+			ctx := NewTestContext(config)
+
+			ctx.RegisterModuleType("test", pathForModuleSrcTestModuleFactory)
+			ctx.RegisterModuleType("output_file_provider", pathForModuleSrcOutputFileProviderModuleFactory)
+			ctx.RegisterModuleType("filegroup", FileGroupFactory)
+
+			ctx.Register()
 			_, errs := ctx.ParseFileList(".", []string{"fg/Android.bp", "foo/Android.bp", "ofp/Android.bp"})
 			FailIfErrored(t, errs)
 			_, errs = ctx.PrepareBuildActions(config)
@@ -1224,12 +1224,12 @@
 	config := TestConfig(buildDir, nil, bp, nil)
 	config.TestProductVariables.Allow_missing_dependencies = proptools.BoolPtr(true)
 
-	ctx := NewTestContext()
+	ctx := NewTestContext(config)
 	ctx.SetAllowMissingDependencies(true)
 
 	ctx.RegisterModuleType("test", pathForModuleSrcTestModuleFactory)
 
-	ctx.Register(config)
+	ctx.Register()
 
 	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
 	FailIfErrored(t, errs)
diff --git a/android/prebuilt_test.go b/android/prebuilt_test.go
index 854395e..9ac3875 100644
--- a/android/prebuilt_test.go
+++ b/android/prebuilt_test.go
@@ -288,10 +288,10 @@
 				{Windows, Arch{ArchType: X86_64}, NativeBridgeDisabled, "", "", true},
 			}
 
-			ctx := NewTestArchContext()
+			ctx := NewTestArchContext(config)
 			registerTestPrebuiltBuildComponents(ctx)
 			ctx.RegisterModuleType("filegroup", FileGroupFactory)
-			ctx.Register(config)
+			ctx.Register()
 
 			_, errs := ctx.ParseBlueprintsFiles("Android.bp")
 			FailIfErrored(t, errs)
diff --git a/android/register.go b/android/register.go
index ad3df7e..bd824c9 100644
--- a/android/register.go
+++ b/android/register.go
@@ -81,10 +81,11 @@
 
 type Context struct {
 	*blueprint.Context
+	config Config
 }
 
-func NewContext() *Context {
-	ctx := &Context{blueprint.NewContext()}
+func NewContext(config Config) *Context {
+	ctx := &Context{blueprint.NewContext(), config}
 	ctx.SetSrcDir(absSrcDir)
 	return ctx
 }
@@ -157,7 +158,7 @@
 // Extracting the actual registration into a separate RegisterBuildComponents(ctx) function
 // allows it to be used to initialize test context, e.g.
 //
-//   ctx := android.NewTestContext()
+//   ctx := android.NewTestContext(config)
 //   RegisterBuildComponents(ctx)
 var InitRegistrationContext RegistrationContext = &initRegistrationContext{
 	moduleTypes:    make(map[string]ModuleFactory),
diff --git a/android/rule_builder_test.go b/android/rule_builder_test.go
index 0d1070d..ca6359d 100644
--- a/android/rule_builder_test.go
+++ b/android/rule_builder_test.go
@@ -507,10 +507,10 @@
 	`
 
 	config := TestConfig(buildDir, nil, bp, fs)
-	ctx := NewTestContext()
+	ctx := NewTestContext(config)
 	ctx.RegisterModuleType("rule_builder_test", testRuleBuilderFactory)
 	ctx.RegisterSingletonType("rule_builder_test", testRuleBuilderSingletonFactory)
-	ctx.Register(config)
+	ctx.Register()
 
 	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
 	FailIfErrored(t, errs)
diff --git a/android/soong_config_modules_test.go b/android/soong_config_modules_test.go
index 9677f34..b1810b3 100644
--- a/android/soong_config_modules_test.go
+++ b/android/soong_config_modules_test.go
@@ -175,7 +175,7 @@
 			},
 		}
 
-		ctx := NewTestContext()
+		ctx := NewTestContext(config)
 		ctx.RegisterModuleType("soong_config_module_type_import", soongConfigModuleTypeImportFactory)
 		ctx.RegisterModuleType("soong_config_module_type", soongConfigModuleTypeFactory)
 		ctx.RegisterModuleType("soong_config_string_variable", soongConfigStringVariableDummyFactory)
@@ -183,7 +183,7 @@
 		ctx.RegisterModuleType("test_defaults", soongConfigTestDefaultsModuleFactory)
 		ctx.RegisterModuleType("test", soongConfigTestModuleFactory)
 		ctx.PreArchMutators(RegisterDefaultsPreArchMutators)
-		ctx.Register(config)
+		ctx.Register()
 
 		_, errs := ctx.ParseBlueprintsFiles("Android.bp")
 		FailIfErrored(t, errs)
diff --git a/android/testing.go b/android/testing.go
index 8ea4168..d83cecc 100644
--- a/android/testing.go
+++ b/android/testing.go
@@ -25,14 +25,14 @@
 	"github.com/google/blueprint"
 )
 
-func NewTestContext() *TestContext {
+func NewTestContext(config Config) *TestContext {
 	namespaceExportFilter := func(namespace *Namespace) bool {
 		return true
 	}
 
 	nameResolver := NewNameResolver(namespaceExportFilter)
 	ctx := &TestContext{
-		Context:      &Context{blueprint.NewContext()},
+		Context:      &Context{blueprint.NewContext(), config},
 		NameResolver: nameResolver,
 	}
 
@@ -40,11 +40,16 @@
 
 	ctx.postDeps = append(ctx.postDeps, registerPathDepsMutator)
 
+	ctx.SetFs(ctx.config.fs)
+	if ctx.config.mockBpList != "" {
+		ctx.SetModuleListFile(ctx.config.mockBpList)
+	}
+
 	return ctx
 }
 
-func NewTestArchContext() *TestContext {
-	ctx := NewTestContext()
+func NewTestArchContext(config Config) *TestContext {
+	ctx := NewTestContext(config)
 	ctx.preDeps = append(ctx.preDeps, registerArchMutator)
 	return ctx
 }
@@ -53,7 +58,6 @@
 	*Context
 	preArch, preDeps, postDeps, finalDeps []RegisterMutatorFunc
 	NameResolver                          *NameResolver
-	config                                Config
 }
 
 func (ctx *TestContext) PreArchMutators(f RegisterMutatorFunc) {
@@ -77,16 +81,10 @@
 	ctx.finalDeps = append(ctx.finalDeps, f)
 }
 
-func (ctx *TestContext) Register(config Config) {
-	ctx.SetFs(config.fs)
-	if config.mockBpList != "" {
-		ctx.SetModuleListFile(config.mockBpList)
-	}
+func (ctx *TestContext) Register() {
 	registerMutators(ctx.Context.Context, ctx.preArch, ctx.preDeps, ctx.postDeps, ctx.finalDeps)
 
 	ctx.RegisterSingletonType("env", EnvSingleton)
-
-	ctx.config = config
 }
 
 func (ctx *TestContext) ParseFileList(rootDir string, filePaths []string) (deps []string, errs []error) {
diff --git a/android/variable_test.go b/android/variable_test.go
index 9cafedd..393fe01 100644
--- a/android/variable_test.go
+++ b/android/variable_test.go
@@ -157,23 +157,6 @@
 }
 
 func TestProductVariables(t *testing.T) {
-	ctx := NewTestContext()
-	// A module type that has a srcs property but not a cflags property.
-	ctx.RegisterModuleType("module1", testProductVariableModuleFactoryFactory(&struct {
-		Srcs []string
-	}{}))
-	// A module type that has a cflags property but not a srcs property.
-	ctx.RegisterModuleType("module2", testProductVariableModuleFactoryFactory(&struct {
-		Cflags []string
-	}{}))
-	// A module type that does not have any properties that match product_variables.
-	ctx.RegisterModuleType("module3", testProductVariableModuleFactoryFactory(&struct {
-		Foo []string
-	}{}))
-	ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
-		ctx.BottomUp("variable", VariableMutator).Parallel()
-	})
-
 	// Test that a module can use one product variable even if it doesn't have all the properties
 	// supported by that product variable.
 	bp := `
@@ -201,7 +184,24 @@
 	config := TestConfig(buildDir, nil, bp, nil)
 	config.TestProductVariables.Eng = proptools.BoolPtr(true)
 
-	ctx.Register(config)
+	ctx := NewTestContext(config)
+	// A module type that has a srcs property but not a cflags property.
+	ctx.RegisterModuleType("module1", testProductVariableModuleFactoryFactory(&struct {
+		Srcs []string
+	}{}))
+	// A module type that has a cflags property but not a srcs property.
+	ctx.RegisterModuleType("module2", testProductVariableModuleFactoryFactory(&struct {
+		Cflags []string
+	}{}))
+	// A module type that does not have any properties that match product_variables.
+	ctx.RegisterModuleType("module3", testProductVariableModuleFactoryFactory(&struct {
+		Foo []string
+	}{}))
+	ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
+		ctx.BottomUp("variable", VariableMutator).Parallel()
+	})
+
+	ctx.Register()
 
 	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
 	FailIfErrored(t, errs)
@@ -293,7 +293,7 @@
 	config := TestConfig(buildDir, nil, bp, nil)
 	config.TestProductVariables.Eng = boolPtr(true)
 
-	ctx := NewTestContext()
+	ctx := NewTestContext(config)
 
 	ctx.RegisterModuleType("test", productVariablesDefaultsTestModuleFactory)
 	ctx.RegisterModuleType("defaults", productVariablesDefaultsTestDefaultsFactory)
@@ -303,7 +303,7 @@
 		ctx.BottomUp("variable", VariableMutator).Parallel()
 	})
 
-	ctx.Register(config)
+	ctx.Register()
 
 	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
 	FailIfErrored(t, errs)
diff --git a/android/visibility_test.go b/android/visibility_test.go
index cb5ef35..87a295e 100644
--- a/android/visibility_test.go
+++ b/android/visibility_test.go
@@ -1168,7 +1168,7 @@
 	// Create a new config per test as visibility information is stored in the config.
 	config := TestArchConfig(buildDir, nil, "", fs)
 
-	ctx := NewTestArchContext()
+	ctx := NewTestArchContext(config)
 	ctx.RegisterModuleType("mock_library", newMockLibraryModule)
 	ctx.RegisterModuleType("mock_parent", newMockParentFactory)
 	ctx.RegisterModuleType("mock_defaults", defaultsFactory)
@@ -1180,7 +1180,7 @@
 	ctx.PreArchMutators(RegisterDefaultsPreArchMutators)
 	ctx.PreArchMutators(RegisterVisibilityRuleGatherer)
 	ctx.PostDepsMutators(RegisterVisibilityRuleEnforcer)
-	ctx.Register(config)
+	ctx.Register()
 
 	_, errs := ctx.ParseBlueprintsFiles(".")
 	if len(errs) > 0 {
diff --git a/apex/apex_test.go b/apex/apex_test.go
index 09d9c44..532a7aa 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -216,7 +216,7 @@
 		handler(tempFS, config)
 	}
 
-	ctx := android.NewTestArchContext()
+	ctx := android.NewTestArchContext(config)
 
 	// from android package
 	android.RegisterPackageBuildComponents(ctx)
@@ -261,7 +261,7 @@
 	ctx.PreDepsMutators(RegisterPreDepsMutators)
 	ctx.PostDepsMutators(RegisterPostDepsMutators)
 
-	ctx.Register(config)
+	ctx.Register()
 
 	return ctx, config
 }
@@ -5746,7 +5746,9 @@
 	}
 	cc.GatherRequiredFilesForTest(fs)
 
-	ctx := android.NewTestArchContext()
+	config := android.TestArchConfig(buildDir, nil, bp, fs)
+
+	ctx := android.NewTestArchContext(config)
 	ctx.RegisterModuleType("apex", BundleFactory)
 	ctx.RegisterModuleType("apex_key", ApexKeyFactory)
 	ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
@@ -5761,8 +5763,7 @@
 	ctx.PreDepsMutators(RegisterPreDepsMutators)
 	ctx.PostDepsMutators(RegisterPostDepsMutators)
 
-	config := android.TestArchConfig(buildDir, nil, bp, fs)
-	ctx.Register(config)
+	ctx.Register()
 
 	_ = dexpreopt.GlobalSoongConfigForTests(config)
 	dexpreopt.RegisterToolModulesForTest(ctx)
@@ -5897,7 +5898,15 @@
 		"system/sepolicy/apex/myapex-file_contexts": nil,
 	}
 
-	ctx := android.NewTestArchContext()
+	config := android.TestArchConfig(buildDir, nil, bp, fs)
+	android.SetTestNeverallowRules(config, rules)
+	updatableBootJars := make([]string, 0, len(apexBootJars))
+	for _, apexBootJar := range apexBootJars {
+		updatableBootJars = append(updatableBootJars, "myapex:"+apexBootJar)
+	}
+	config.TestProductVariables.UpdatableBootJars = android.CreateTestConfiguredJarList(updatableBootJars)
+
+	ctx := android.NewTestArchContext(config)
 	ctx.RegisterModuleType("apex", BundleFactory)
 	ctx.RegisterModuleType("apex_key", ApexKeyFactory)
 	ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
@@ -5910,15 +5919,7 @@
 	ctx.PostDepsMutators(RegisterPostDepsMutators)
 	ctx.PostDepsMutators(android.RegisterNeverallowMutator)
 
-	config := android.TestArchConfig(buildDir, nil, bp, fs)
-	android.SetTestNeverallowRules(config, rules)
-	updatableBootJars := make([]string, 0, len(apexBootJars))
-	for _, apexBootJar := range apexBootJars {
-		updatableBootJars = append(updatableBootJars, "myapex:"+apexBootJar)
-	}
-	config.TestProductVariables.UpdatableBootJars = android.CreateTestConfiguredJarList(updatableBootJars)
-
-	ctx.Register(config)
+	ctx.Register()
 
 	_, errs := ctx.ParseBlueprintsFiles("Android.bp")
 	android.FailIfErrored(t, errs)
diff --git a/bpf/bpf_test.go b/bpf/bpf_test.go
index d06d7d1..be9e36e 100644
--- a/bpf/bpf_test.go
+++ b/bpf/bpf_test.go
@@ -58,9 +58,9 @@
 }
 
 func testContext(config android.Config) *android.TestContext {
-	ctx := cc.CreateTestContext()
+	ctx := cc.CreateTestContext(config)
 	ctx.RegisterModuleType("bpf", BpfFactory)
-	ctx.Register(config)
+	ctx.Register()
 
 	return ctx
 }
diff --git a/cc/cc_test.go b/cc/cc_test.go
index b3bb282..b803cba 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -53,8 +53,8 @@
 
 func testCcWithConfig(t *testing.T, config android.Config) *android.TestContext {
 	t.Helper()
-	ctx := CreateTestContext()
-	ctx.Register(config)
+	ctx := CreateTestContext(config)
+	ctx.Register()
 
 	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
 	android.FailIfErrored(t, errs)
@@ -84,8 +84,8 @@
 func testCcErrorWithConfig(t *testing.T, pattern string, config android.Config) {
 	t.Helper()
 
-	ctx := CreateTestContext()
-	ctx.Register(config)
+	ctx := CreateTestContext(config)
+	ctx.Register()
 
 	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
 	if len(errs) > 0 {
@@ -1293,8 +1293,8 @@
 	config := TestConfig(buildDir, android.Android, nil, "", mockFS)
 	config.TestProductVariables.DeviceVndkVersion = StringPtr("BOARD")
 	config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
-	ctx := CreateTestContext()
-	ctx.Register(config)
+	ctx := CreateTestContext(config)
+	ctx.Register()
 
 	_, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "vendor/Android.bp", "vndk/Android.bp"})
 	android.FailIfErrored(t, errs)
@@ -1451,8 +1451,8 @@
 	config := TestConfig(buildDir, android.Android, nil, "", mockFS)
 	config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
 	config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
-	ctx := CreateTestContext()
-	ctx.Register(config)
+	ctx := CreateTestContext(config)
+	ctx.Register()
 
 	_, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
 	android.FailIfErrored(t, errs)
@@ -1541,8 +1541,8 @@
 	config := TestConfig(buildDir, android.Android, nil, "", mockFS)
 	config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
 	config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
-	ctx := CreateTestContext()
-	ctx.Register(config)
+	ctx := CreateTestContext(config)
+	ctx.Register()
 
 	_, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "device/Android.bp"})
 	android.FailIfErrored(t, errs)
@@ -1582,8 +1582,8 @@
 	config := TestConfig(buildDir, android.Android, nil, "", mockFS)
 	config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
 	config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
-	ctx := CreateTestContext()
-	ctx.Register(config)
+	ctx := CreateTestContext(config)
+	ctx.Register()
 
 	_, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp"})
 	android.FailIfErrored(t, errs)
@@ -3882,11 +3882,11 @@
 	config := TestConfig(buildDir, android.Android, nil, bp, nil)
 	config.TestProductVariables.Debuggable = BoolPtr(true)
 
-	ctx := CreateTestContext()
+	ctx := CreateTestContext(config)
 	ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
 		ctx.BottomUp("variable", android.VariableMutator).Parallel()
 	})
-	ctx.Register(config)
+	ctx.Register()
 
 	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
 	android.FailIfErrored(t, errs)
@@ -3917,9 +3917,9 @@
 	config := TestConfig(buildDir, android.Android, nil, bp, nil)
 	config.TestProductVariables.Allow_missing_dependencies = BoolPtr(true)
 
-	ctx := CreateTestContext()
+	ctx := CreateTestContext(config)
 	ctx.SetAllowMissingDependencies(true)
-	ctx.Register(config)
+	ctx.Register()
 
 	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
 	android.FailIfErrored(t, errs)
diff --git a/cc/genrule_test.go b/cc/genrule_test.go
index a366f76..0c7952b 100644
--- a/cc/genrule_test.go
+++ b/cc/genrule_test.go
@@ -22,9 +22,9 @@
 )
 
 func testGenruleContext(config android.Config) *android.TestContext {
-	ctx := android.NewTestArchContext()
+	ctx := android.NewTestArchContext(config)
 	ctx.RegisterModuleType("cc_genrule", genRuleFactory)
-	ctx.Register(config)
+	ctx.Register()
 
 	return ctx
 }
diff --git a/cc/prebuilt_test.go b/cc/prebuilt_test.go
index 1f070a5..5bf334e 100644
--- a/cc/prebuilt_test.go
+++ b/cc/prebuilt_test.go
@@ -25,7 +25,7 @@
 
 func testPrebuilt(t *testing.T, bp string, fs map[string][]byte, handlers ...configCustomizer) *android.TestContext {
 	config := TestConfig(buildDir, android.Android, nil, bp, fs)
-	ctx := CreateTestContext()
+	ctx := CreateTestContext(config)
 
 	// Enable androidmk support.
 	// * Register the singleton
@@ -38,7 +38,7 @@
 		handler(config)
 	}
 
-	ctx.Register(config)
+	ctx.Register()
 	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
 	android.FailIfErrored(t, errs)
 	_, errs = ctx.PrepareBuildActions(config)
diff --git a/cc/test_data_test.go b/cc/test_data_test.go
index ae59e2f..426dfc5 100644
--- a/cc/test_data_test.go
+++ b/cc/test_data_test.go
@@ -122,10 +122,10 @@
 				"dir/baz":        nil,
 				"dir/bar/baz":    nil,
 			})
-			ctx := android.NewTestContext()
+			ctx := android.NewTestContext(config)
 			ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
 			ctx.RegisterModuleType("test", newTest)
-			ctx.Register(config)
+			ctx.Register()
 
 			_, errs := ctx.ParseBlueprintsFiles("Blueprints")
 			android.FailIfErrored(t, errs)
diff --git a/cc/testing.go b/cc/testing.go
index 388a9ce..5a311f4 100644
--- a/cc/testing.go
+++ b/cc/testing.go
@@ -545,8 +545,8 @@
 	return config
 }
 
-func CreateTestContext() *android.TestContext {
-	ctx := android.NewTestArchContext()
+func CreateTestContext(config android.Config) *android.TestContext {
+	ctx := android.NewTestArchContext(config)
 	ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
 	ctx.RegisterModuleType("cc_test", TestFactory)
 	ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
diff --git a/cmd/soong_build/main.go b/cmd/soong_build/main.go
index 9d7dddd..7c12c68 100644
--- a/cmd/soong_build/main.go
+++ b/cmd/soong_build/main.go
@@ -52,7 +52,7 @@
 }
 
 func newContext(srcDir string, configuration android.Config) *android.Context {
-	ctx := android.NewContext()
+	ctx := android.NewContext(configuration)
 	ctx.Register()
 	if !shouldPrepareBuildActions() {
 		configuration.SetStopBefore(bootstrap.StopBeforePrepareBuildActions)
diff --git a/cmd/soong_build/queryview_test.go b/cmd/soong_build/queryview_test.go
index 675b532..525802a 100644
--- a/cmd/soong_build/queryview_test.go
+++ b/cmd/soong_build/queryview_test.go
@@ -234,9 +234,9 @@
 
 	for _, testCase := range testCases {
 		config := android.TestConfig(buildDir, nil, testCase.bp, nil)
-		ctx := android.NewTestContext()
+		ctx := android.NewTestContext(config)
 		ctx.RegisterModuleType("custom", customModuleFactory)
-		ctx.Register(config)
+		ctx.Register()
 
 		_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
 		android.FailIfErrored(t, errs)
diff --git a/etc/prebuilt_etc_test.go b/etc/prebuilt_etc_test.go
index 8fc36c2..6c4c0b6 100644
--- a/etc/prebuilt_etc_test.go
+++ b/etc/prebuilt_etc_test.go
@@ -58,7 +58,7 @@
 
 	config := android.TestArchConfig(buildDir, nil, bp, fs)
 
-	ctx := android.NewTestArchContext()
+	ctx := android.NewTestArchContext(config)
 	ctx.RegisterModuleType("prebuilt_etc", PrebuiltEtcFactory)
 	ctx.RegisterModuleType("prebuilt_etc_host", PrebuiltEtcHostFactory)
 	ctx.RegisterModuleType("prebuilt_usr_share", PrebuiltUserShareFactory)
@@ -66,7 +66,7 @@
 	ctx.RegisterModuleType("prebuilt_font", PrebuiltFontFactory)
 	ctx.RegisterModuleType("prebuilt_firmware", PrebuiltFirmwareFactory)
 	ctx.RegisterModuleType("prebuilt_dsp", PrebuiltDSPFactory)
-	ctx.Register(config)
+	ctx.Register()
 
 	return ctx, config
 }
diff --git a/genrule/genrule_test.go b/genrule/genrule_test.go
index fdbb9d9..c19078f 100644
--- a/genrule/genrule_test.go
+++ b/genrule/genrule_test.go
@@ -53,14 +53,14 @@
 
 func testContext(config android.Config) *android.TestContext {
 
-	ctx := android.NewTestArchContext()
+	ctx := android.NewTestArchContext(config)
 	ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
 	ctx.RegisterModuleType("tool", toolFactory)
 
 	registerGenruleBuildComponents(ctx)
 
 	ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
-	ctx.Register(config)
+	ctx.Register()
 
 	return ctx
 }
diff --git a/java/android_resources.go b/java/android_resources.go
index 97f7679..720d3a5 100644
--- a/java/android_resources.go
+++ b/java/android_resources.go
@@ -23,6 +23,7 @@
 
 func init() {
 	android.RegisterPreSingletonType("overlay", OverlaySingletonFactory)
+
 }
 
 var androidResourceIgnoreFilenames = []string{
diff --git a/java/app_test.go b/java/app_test.go
index 82577e3..446050d 100644
--- a/java/app_test.go
+++ b/java/app_test.go
@@ -59,7 +59,7 @@
 func testApp(t *testing.T, bp string) *android.TestContext {
 	config := testAppConfig(nil, bp, nil)
 
-	ctx := testContext()
+	ctx := testContext(config)
 
 	run(t, ctx, config)
 
@@ -220,7 +220,7 @@
 		config.TestProductVariables.AAPTPrebuiltDPI = test.aaptPrebuiltDPI
 		config.TestProductVariables.Platform_sdk_version = &test.sdkVersion
 		config.Targets[android.Android] = test.targets
-		ctx := testContext()
+		ctx := testContext(config)
 		run(t, ctx, config)
 		module := ctx.ModuleForTests("foo", "android_common")
 		const packedSplitApks = "foo.zip"
@@ -657,7 +657,7 @@
 	for _, testCase := range testCases {
 		t.Run(testCase.name, func(t *testing.T) {
 			config := testConfig(nil, fmt.Sprintf(bp, testCase.prop), fs)
-			ctx := testContext()
+			ctx := testContext(config)
 			run(t, ctx, config)
 
 			module := ctx.ModuleForTests("foo", "android_common")
@@ -973,7 +973,7 @@
 				config.TestProductVariables.EnforceRROExcludedOverlays = testCase.enforceRROExcludedOverlays
 			}
 
-			ctx := testContext()
+			ctx := testContext(config)
 			run(t, ctx, config)
 
 			resourceListToFiles := func(module android.TestingModule, list []string) (files []string) {
@@ -1039,7 +1039,7 @@
 }
 
 func checkSdkVersion(t *testing.T, config android.Config, expectedSdkVersion string) {
-	ctx := testContext()
+	ctx := testContext(config)
 
 	run(t, ctx, config)
 
@@ -1633,7 +1633,7 @@
 			if test.certificateOverride != "" {
 				config.TestProductVariables.CertificateOverrides = []string{test.certificateOverride}
 			}
-			ctx := testContext()
+			ctx := testContext(config)
 
 			run(t, ctx, config)
 			foo := ctx.ModuleForTests("foo", "android_common")
@@ -1698,7 +1698,7 @@
 	for _, test := range testCases {
 		t.Run(test.name, func(t *testing.T) {
 			config := testAppConfig(nil, test.bp, nil)
-			ctx := testContext()
+			ctx := testContext(config)
 
 			run(t, ctx, config)
 			foo := ctx.ModuleForTests("foo", "android_common")
@@ -1758,7 +1758,7 @@
 			if test.packageNameOverride != "" {
 				config.TestProductVariables.PackageNameOverrides = []string{test.packageNameOverride}
 			}
-			ctx := testContext()
+			ctx := testContext(config)
 
 			run(t, ctx, config)
 			foo := ctx.ModuleForTests("foo", "android_common")
@@ -1793,7 +1793,7 @@
 		`
 	config := testAppConfig(nil, bp, nil)
 	config.TestProductVariables.ManifestPackageNameOverrides = []string{"foo:org.dandroid.bp"}
-	ctx := testContext()
+	ctx := testContext(config)
 
 	run(t, ctx, config)
 
@@ -2416,7 +2416,7 @@
 		config := testAppConfig(nil, bp, nil)
 		config.TestProductVariables.AAPTPreferredConfig = test.aaptPreferredConfig
 		config.TestProductVariables.AAPTPrebuiltDPI = test.aaptPrebuiltDPI
-		ctx := testContext()
+		ctx := testContext(config)
 
 		run(t, ctx, config)
 
@@ -2777,7 +2777,7 @@
 	config := testAppConfig(nil, bp, nil)
 	config.TestProductVariables.MissingUsesLibraries = []string{"baz"}
 
-	ctx := testContext()
+	ctx := testContext(config)
 
 	run(t, ctx, config)
 
@@ -3129,7 +3129,7 @@
 			config.TestProductVariables.Always_use_prebuilt_sdks = proptools.BoolPtr(true)
 		}
 
-		ctx := testContext()
+		ctx := testContext(config)
 
 		run(t, ctx, config)
 
@@ -3209,7 +3209,7 @@
 		}
 		`
 	config := testAppConfig(nil, bp, fs)
-	ctx := testContext()
+	ctx := testContext(config)
 	run(t, ctx, config)
 
 	m := ctx.ModuleForTests("foo", "android_common")
@@ -3506,7 +3506,7 @@
 				config.TestProductVariables.EnforceRROExemptedTargets = testCase.enforceRROExemptTargets
 			}
 
-			ctx := testContext()
+			ctx := testContext(config)
 			run(t, ctx, config)
 
 			modules := []string{"foo", "bar"}
diff --git a/java/dexpreopt_bootjars_test.go b/java/dexpreopt_bootjars_test.go
index ab31958..95fe5e1 100644
--- a/java/dexpreopt_bootjars_test.go
+++ b/java/dexpreopt_bootjars_test.go
@@ -51,7 +51,7 @@
 	dexpreoptConfig.BootJars = android.CreateTestConfiguredJarList([]string{"platform:foo", "platform:bar", "platform:baz"})
 	dexpreopt.SetTestGlobalConfig(config, dexpreoptConfig)
 
-	ctx := testContext()
+	ctx := testContext(config)
 	RegisterDexpreoptBootJarsComponents(ctx)
 	run(t, ctx, config)
 
diff --git a/java/hiddenapi_singleton_test.go b/java/hiddenapi_singleton_test.go
index 7acaae7..34a4856 100644
--- a/java/hiddenapi_singleton_test.go
+++ b/java/hiddenapi_singleton_test.go
@@ -29,8 +29,8 @@
 	return config
 }
 
-func testContextWithHiddenAPI() *android.TestContext {
-	ctx := testContext()
+func testContextWithHiddenAPI(config android.Config) *android.TestContext {
+	ctx := testContext(config)
 	ctx.RegisterSingletonType("hiddenapi", hiddenAPISingletonFactory)
 	return ctx
 }
@@ -38,7 +38,7 @@
 func testHiddenAPIWithConfig(t *testing.T, config android.Config) *android.TestContext {
 	t.Helper()
 
-	ctx := testContextWithHiddenAPI()
+	ctx := testContextWithHiddenAPI(config)
 
 	run(t, ctx, config)
 	return ctx
diff --git a/java/java_test.go b/java/java_test.go
index 6c0a908..2a27922 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -70,9 +70,9 @@
 	return config
 }
 
-func testContext() *android.TestContext {
+func testContext(config android.Config) *android.TestContext {
 
-	ctx := android.NewTestArchContext()
+	ctx := android.NewTestArchContext(config)
 	RegisterJavaBuildComponents(ctx)
 	RegisterAppBuildComponents(ctx)
 	RegisterAARBuildComponents(ctx)
@@ -115,7 +115,7 @@
 	pathCtx := android.PathContextForTesting(config)
 	dexpreopt.SetTestGlobalConfig(config, dexpreopt.GlobalConfigForTests(pathCtx))
 
-	ctx.Register(config)
+	ctx.Register()
 	_, errs := ctx.ParseBlueprintsFiles("Android.bp")
 	android.FailIfErrored(t, errs)
 	_, errs = ctx.PrepareBuildActions(config)
@@ -129,12 +129,12 @@
 
 func testJavaErrorWithConfig(t *testing.T, pattern string, config android.Config) (*android.TestContext, android.Config) {
 	t.Helper()
-	ctx := testContext()
+	ctx := testContext(config)
 
 	pathCtx := android.PathContextForTesting(config)
 	dexpreopt.SetTestGlobalConfig(config, dexpreopt.GlobalConfigForTests(pathCtx))
 
-	ctx.Register(config)
+	ctx.Register()
 	_, errs := ctx.ParseBlueprintsFiles("Android.bp")
 	if len(errs) > 0 {
 		android.FailIfNoMatchingErrors(t, pattern, errs)
@@ -163,7 +163,7 @@
 
 func testJavaWithConfig(t *testing.T, config android.Config) (*android.TestContext, android.Config) {
 	t.Helper()
-	ctx := testContext()
+	ctx := testContext(config)
 	run(t, ctx, config)
 
 	return ctx, config
@@ -1440,7 +1440,7 @@
 				}
 `),
 	})
-	ctx := testContext()
+	ctx := testContext(config)
 	run(t, ctx, config)
 }
 
@@ -1458,7 +1458,7 @@
 				}
 `),
 	})
-	ctx := testContext()
+	ctx := testContext(config)
 	run(t, ctx, config)
 }
 
diff --git a/java/sdk_test.go b/java/sdk_test.go
index 776069d..dc90ea3 100644
--- a/java/sdk_test.go
+++ b/java/sdk_test.go
@@ -356,7 +356,7 @@
 					config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true)
 					config.TestProductVariables.Always_use_prebuilt_sdks = proptools.BoolPtr(true)
 				}
-				ctx := testContext()
+				ctx := testContext(config)
 				run(t, ctx, config)
 
 				checkClasspath(t, ctx, true /* isJava8 */)
@@ -377,7 +377,7 @@
 					config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true)
 					config.TestProductVariables.Always_use_prebuilt_sdks = proptools.BoolPtr(true)
 				}
-				ctx := testContext()
+				ctx := testContext(config)
 				run(t, ctx, config)
 
 				checkClasspath(t, ctx, false /* isJava8 */)
@@ -401,7 +401,7 @@
 					config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true)
 					config.TestProductVariables.Always_use_prebuilt_sdks = proptools.BoolPtr(true)
 				}
-				ctx := testContext()
+				ctx := testContext(config)
 				run(t, ctx, config)
 
 				checkClasspath(t, ctx, true /* isJava8 */)
@@ -417,7 +417,7 @@
 					config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true)
 					config.TestProductVariables.Always_use_prebuilt_sdks = proptools.BoolPtr(true)
 				}
-				ctx := testContext()
+				ctx := testContext(config)
 				run(t, ctx, config)
 
 				checkClasspath(t, ctx, false /* isJava8 */)
diff --git a/linkerconfig/linkerconfig_test.go b/linkerconfig/linkerconfig_test.go
index 13c276a..01f4657 100644
--- a/linkerconfig/linkerconfig_test.go
+++ b/linkerconfig/linkerconfig_test.go
@@ -56,9 +56,9 @@
 
 	config := android.TestArchConfig(buildDir, nil, bp, fs)
 
-	ctx := android.NewTestArchContext()
+	ctx := android.NewTestArchContext(config)
 	ctx.RegisterModuleType("linker_config", linkerConfigFactory)
-	ctx.Register(config)
+	ctx.Register()
 
 	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
 	android.FailIfErrored(t, errs)
diff --git a/python/python_test.go b/python/python_test.go
index 10b565a..64bc4f6 100644
--- a/python/python_test.go
+++ b/python/python_test.go
@@ -329,13 +329,13 @@
 	for _, d := range data {
 		t.Run(d.desc, func(t *testing.T) {
 			config := android.TestConfig(buildDir, nil, "", d.mockFiles)
-			ctx := android.NewTestContext()
+			ctx := android.NewTestContext(config)
 			ctx.PreDepsMutators(RegisterPythonPreDepsMutators)
 			ctx.RegisterModuleType("python_library_host", PythonLibraryHostFactory)
 			ctx.RegisterModuleType("python_binary_host", PythonBinaryHostFactory)
 			ctx.RegisterModuleType("python_defaults", defaultsFactory)
 			ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
-			ctx.Register(config)
+			ctx.Register()
 			_, testErrs := ctx.ParseBlueprintsFiles(bpFile)
 			android.FailIfErrored(t, testErrs)
 			_, actErrs := ctx.PrepareBuildActions(config)
diff --git a/rust/clippy_test.go b/rust/clippy_test.go
index 7815aab..132b7b8 100644
--- a/rust/clippy_test.go
+++ b/rust/clippy_test.go
@@ -65,8 +65,8 @@
 		t.Run("path="+tc.modulePath, func(t *testing.T) {
 
 			config := android.TestArchConfig(buildDir, nil, bp, fs)
-			ctx := CreateTestContext()
-			ctx.Register(config)
+			ctx := CreateTestContext(config)
+			ctx.Register()
 			_, errs := ctx.ParseFileList(".", []string{tc.modulePath + "Android.bp"})
 			android.FailIfErrored(t, errs)
 			_, errs = ctx.PrepareBuildActions(config)
diff --git a/rust/compiler_test.go b/rust/compiler_test.go
index a25523c..a6dba9e 100644
--- a/rust/compiler_test.go
+++ b/rust/compiler_test.go
@@ -152,8 +152,8 @@
 		t.Run("path="+tc.modulePath, func(t *testing.T) {
 
 			config := android.TestArchConfig(buildDir, nil, bp, fs)
-			ctx := CreateTestContext()
-			ctx.Register(config)
+			ctx := CreateTestContext(config)
+			ctx.Register()
 			_, errs := ctx.ParseFileList(".", []string{tc.modulePath + "Android.bp"})
 			android.FailIfErrored(t, errs)
 			_, errs = ctx.PrepareBuildActions(config)
diff --git a/rust/rust_test.go b/rust/rust_test.go
index 9b2f023..14bbd0b 100644
--- a/rust/rust_test.go
+++ b/rust/rust_test.go
@@ -142,8 +142,8 @@
 	if tctx.config == nil {
 		t.Fatalf("tctx.config not been generated yet. Please call generateConfig first.")
 	}
-	ctx := CreateTestContext()
-	ctx.Register(*tctx.config)
+	ctx := CreateTestContext(*tctx.config)
+	ctx.Register()
 	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
 	android.FailIfErrored(t, errs)
 	_, errs = ctx.PrepareBuildActions(*tctx.config)
@@ -157,8 +157,8 @@
 	if tctx.config == nil {
 		t.Fatalf("tctx.config not been generated yet. Please call generateConfig first.")
 	}
-	ctx := CreateTestContext()
-	ctx.Register(*tctx.config)
+	ctx := CreateTestContext(*tctx.config)
+	ctx.Register()
 
 	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
 	if len(errs) > 0 {
diff --git a/rust/testing.go b/rust/testing.go
index 4001566..66877a9 100644
--- a/rust/testing.go
+++ b/rust/testing.go
@@ -127,8 +127,8 @@
 	return bp
 }
 
-func CreateTestContext() *android.TestContext {
-	ctx := android.NewTestArchContext()
+func CreateTestContext(config android.Config) *android.TestContext {
+	ctx := android.NewTestArchContext(config)
 	android.RegisterPrebuiltMutators(ctx)
 	ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
 	cc.RegisterRequiredBuildComponentsForTest(ctx)
diff --git a/sdk/testing.go b/sdk/testing.go
index 0b280ef..5f520e5 100644
--- a/sdk/testing.go
+++ b/sdk/testing.go
@@ -80,7 +80,7 @@
 		}
 	}
 
-	ctx := android.NewTestArchContext()
+	ctx := android.NewTestArchContext(config)
 
 	// Enable androidmk support.
 	// * Register the singleton
@@ -129,7 +129,7 @@
 	ctx.PreDepsMutators(RegisterPreDepsMutators)
 	ctx.PostDepsMutators(RegisterPostDepsMutators)
 
-	ctx.Register(config)
+	ctx.Register()
 
 	return ctx, config
 }
diff --git a/sh/sh_binary_test.go b/sh/sh_binary_test.go
index 0aa607b..c664461 100644
--- a/sh/sh_binary_test.go
+++ b/sh/sh_binary_test.go
@@ -45,13 +45,13 @@
 
 	config := android.TestArchConfig(buildDir, nil, bp, fs)
 
-	ctx := android.NewTestArchContext()
+	ctx := android.NewTestArchContext(config)
 	ctx.RegisterModuleType("sh_test", ShTestFactory)
 	ctx.RegisterModuleType("sh_test_host", ShTestHostFactory)
 
 	cc.RegisterRequiredBuildComponentsForTest(ctx)
 
-	ctx.Register(config)
+	ctx.Register()
 	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
 	android.FailIfErrored(t, errs)
 	_, errs = ctx.PrepareBuildActions(config)
diff --git a/sysprop/sysprop_test.go b/sysprop/sysprop_test.go
index 7a79a1b..b8b93f6 100644
--- a/sysprop/sysprop_test.go
+++ b/sysprop/sysprop_test.go
@@ -57,7 +57,7 @@
 
 func testContext(config android.Config) *android.TestContext {
 
-	ctx := android.NewTestArchContext()
+	ctx := android.NewTestArchContext(config)
 	java.RegisterJavaBuildComponents(ctx)
 	java.RegisterAppBuildComponents(ctx)
 	java.RegisterSystemModulesBuildComponents(ctx)
@@ -76,7 +76,7 @@
 
 	ctx.RegisterModuleType("sysprop_library", syspropLibraryFactory)
 
-	ctx.Register(config)
+	ctx.Register()
 
 	return ctx
 }
diff --git a/xml/xml_test.go b/xml/xml_test.go
index abcb108..138503c 100644
--- a/xml/xml_test.go
+++ b/xml/xml_test.go
@@ -57,10 +57,10 @@
 		"baz.xml": nil,
 	}
 	config := android.TestArchConfig(buildDir, nil, bp, fs)
-	ctx := android.NewTestArchContext()
+	ctx := android.NewTestArchContext(config)
 	ctx.RegisterModuleType("prebuilt_etc", etc.PrebuiltEtcFactory)
 	ctx.RegisterModuleType("prebuilt_etc_xml", PrebuiltEtcXmlFactory)
-	ctx.Register(config)
+	ctx.Register()
 	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
 	android.FailIfErrored(t, errs)
 	_, errs = ctx.PrepareBuildActions(config)