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 {