From ae8600b507416192f5134dfc068cd0eea4c4dc9e Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 29 Oct 2020 17:09:13 -0700 Subject: [PATCH] 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 --- android/androidmk_test.go | 8 ++-- android/arch_test.go | 8 ++-- android/csuite_config_test.go | 4 +- android/defaults_test.go | 8 ++-- android/module_test.go | 7 ++-- android/mutator_test.go | 61 ++++++++++++++-------------- android/namespace_test.go | 4 +- android/neverallow_test.go | 4 +- android/package_test.go | 4 +- android/path_properties_test.go | 4 +- android/paths_test.go | 18 ++++---- android/prebuilt_test.go | 4 +- android/register.go | 7 ++-- android/rule_builder_test.go | 4 +- android/soong_config_modules_test.go | 4 +- android/testing.go | 22 +++++----- android/variable_test.go | 40 +++++++++--------- android/visibility_test.go | 4 +- apex/apex_test.go | 31 +++++++------- bpf/bpf_test.go | 4 +- cc/cc_test.go | 32 +++++++-------- cc/genrule_test.go | 4 +- cc/prebuilt_test.go | 4 +- cc/test_data_test.go | 4 +- cc/testing.go | 4 +- cmd/soong_build/main.go | 2 +- cmd/soong_build/queryview_test.go | 4 +- etc/prebuilt_etc_test.go | 4 +- genrule/genrule_test.go | 4 +- java/android_resources.go | 1 + java/app_test.go | 28 ++++++------- java/dexpreopt_bootjars_test.go | 2 +- java/hiddenapi_singleton_test.go | 6 +-- java/java_test.go | 16 ++++---- java/sdk_test.go | 8 ++-- linkerconfig/linkerconfig_test.go | 4 +- python/python_test.go | 4 +- rust/clippy_test.go | 4 +- rust/compiler_test.go | 4 +- rust/rust_test.go | 8 ++-- rust/testing.go | 4 +- sdk/testing.go | 4 +- sh/sh_binary_test.go | 4 +- sysprop/sysprop_test.go | 4 +- xml/xml_test.go | 4 +- 45 files changed, 209 insertions(+), 208 deletions(-) diff --git a/android/androidmk_test.go b/android/androidmk_test.go index a558f453f..10527b911 100644 --- a/android/androidmk_test.go +++ b/android/androidmk_test.go @@ -80,10 +80,10 @@ func TestAndroidMkSingleton_PassesUpdatedAndroidMkDataToCustomCallback(t *testin 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 @@ func TestGetDistForGoals(t *testing.T) { 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 8525b0349..4cef4c8e6 100644 --- a/android/arch_test.go +++ b/android/arch_test.go @@ -353,9 +353,9 @@ func TestArchMutator(t *testing.T) { 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 @@ func TestArchMutatorNativeBridge(t *testing.T) { 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 bf1a19a46..9ac959e18 100644 --- a/android/csuite_config_test.go +++ b/android/csuite_config_test.go @@ -21,9 +21,9 @@ import ( 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 d096b2f92..2689d864e 100644 --- a/android/defaults_test.go +++ b/android/defaults_test.go @@ -80,14 +80,14 @@ func TestDefaults(t *testing.T) { 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 @@ func TestDefaultsAllowMissingDependencies(t *testing.T) { 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 @@ func TestDefaultsAllowMissingDependencies(t *testing.T) { 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 3a039e29a..6cc18132a 100644 --- a/android/module_test.go +++ b/android/module_test.go @@ -164,9 +164,6 @@ func depsModuleFactory() Module { } func TestErrorDependsOnDisabledModule(t *testing.T) { - ctx := NewTestContext() - ctx.RegisterModuleType("deps", depsModuleFactory) - bp := ` deps { name: "foo", @@ -180,7 +177,9 @@ func TestErrorDependsOnDisabledModule(t *testing.T) { 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 191b535a3..1c395c782 100644 --- a/android/mutator_test.go +++ b/android/mutator_test.go @@ -70,7 +70,7 @@ func TestMutatorAddMissingDependencies(t *testing.T) { 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 @@ func TestMutatorAddMissingDependencies(t *testing.T) { 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 TestMutatorAddMissingDependencies(t *testing.T) { } 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 @@ func TestModuleString(t *testing.T) { 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 TestModuleString(t *testing.T) { } 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 @@ func TestFinalDepsPhase(t *testing.T) { 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 TestFinalDepsPhase(t *testing.T) { } 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 @@ func TestNoCreateVariationsInFinalDeps(t *testing.T) { }) 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 66c0d895a..45e2cdb7b 100644 --- a/android/namespace_test.go +++ b/android/namespace_test.go @@ -635,7 +635,7 @@ func mockFiles(bps map[string]string) (files map[string][]byte) { 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 @@ func setupTestFromFiles(bps map[string][]byte) (ctx *TestContext, errs []error) 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 56a07dc9d..1d454e52f 100644 --- a/android/neverallow_test.go +++ b/android/neverallow_test.go @@ -359,14 +359,14 @@ func TestNeverallow(t *testing.T) { } 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 04dfc08a9..ade95d42d 100644 --- a/android/package_test.go +++ b/android/package_test.go @@ -86,9 +86,9 @@ func testPackage(fs map[string][]byte) (*TestContext, []error) { // 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 f367b82b8..f964d9f1e 100644 --- a/android/path_properties_test.go +++ b/android/path_properties_test.go @@ -116,12 +116,12 @@ func TestPathDepsMutator(t *testing.T) { ` 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 e7fd763e4..14a477353 100644 --- a/android/paths_test.go +++ b/android/paths_test.go @@ -980,12 +980,6 @@ type pathForModuleSrcTestCase struct { 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 @@ func testPathForModuleSrc(t *testing.T, buildDir string, tests []pathForModuleSr 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 @@ func TestPathsForModuleSrc_AllowMissingDependencies(t *testing.T) { 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 854395e64..9ac38750c 100644 --- a/android/prebuilt_test.go +++ b/android/prebuilt_test.go @@ -288,10 +288,10 @@ func TestPrebuilts(t *testing.T) { {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 ad3df7ead..bd824c9c1 100644 --- a/android/register.go +++ b/android/register.go @@ -81,10 +81,11 @@ func RegisterPreSingletonType(name string, factory SingletonFactory) { 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 @@ type RegistrationContext interface { // 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 0d1070da2..ca6359d67 100644 --- a/android/rule_builder_test.go +++ b/android/rule_builder_test.go @@ -507,10 +507,10 @@ func TestRuleBuilder_Build(t *testing.T) { ` 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 9677f34cf..b1810b305 100644 --- a/android/soong_config_modules_test.go +++ b/android/soong_config_modules_test.go @@ -175,7 +175,7 @@ func TestSoongConfigModule(t *testing.T) { }, } - 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 @@ func TestSoongConfigModule(t *testing.T) { 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 8ea4168d1..d83cecc43 100644 --- a/android/testing.go +++ b/android/testing.go @@ -25,14 +25,14 @@ import ( "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 @@ func NewTestContext() *TestContext { 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 @@ type TestContext struct { *Context preArch, preDeps, postDeps, finalDeps []RegisterMutatorFunc NameResolver *NameResolver - config Config } func (ctx *TestContext) PreArchMutators(f RegisterMutatorFunc) { @@ -77,16 +81,10 @@ func (ctx *TestContext) FinalDepsMutators(f RegisterMutatorFunc) { 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 9cafedd50..393fe0172 100644 --- a/android/variable_test.go +++ b/android/variable_test.go @@ -157,23 +157,6 @@ func testProductVariableModuleFactoryFactory(props interface{}) func() Module { } 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 @@ func TestProductVariables(t *testing.T) { 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 @@ func TestProductVariablesDefaults(t *testing.T) { 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 @@ func TestProductVariablesDefaults(t *testing.T) { 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 cb5ef35b3..87a295e23 100644 --- a/android/visibility_test.go +++ b/android/visibility_test.go @@ -1168,7 +1168,7 @@ func testVisibility(buildDir string, fs map[string][]byte) (*TestContext, []erro // 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 @@ func testVisibility(buildDir string, fs map[string][]byte) (*TestContext, []erro 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 09d9c44c4..532a7aaaf 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -216,7 +216,7 @@ func testApexContext(_ *testing.T, bp string, handlers ...testCustomizer) (*andr handler(tempFS, config) } - ctx := android.NewTestArchContext() + ctx := android.NewTestArchContext(config) // from android package android.RegisterPackageBuildComponents(ctx) @@ -261,7 +261,7 @@ func testApexContext(_ *testing.T, bp string, handlers ...testCustomizer) (*andr ctx.PreDepsMutators(RegisterPreDepsMutators) ctx.PostDepsMutators(RegisterPostDepsMutators) - ctx.Register(config) + ctx.Register() return ctx, config } @@ -5746,7 +5746,9 @@ func testNoUpdatableJarsInBootImage(t *testing.T, errmsg string, transformDexpre } 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 @@ func testNoUpdatableJarsInBootImage(t *testing.T, errmsg string, transformDexpre 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 @@ func testApexPermittedPackagesRules(t *testing.T, errmsg, bp string, apexBootJar "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 @@ func testApexPermittedPackagesRules(t *testing.T, errmsg, bp string, apexBootJar 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 d06d7d1a5..be9e36ea5 100644 --- a/bpf/bpf_test.go +++ b/bpf/bpf_test.go @@ -58,9 +58,9 @@ func testConfig(buildDir string, env map[string]string, bp string) android.Confi } 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 b3bb282a6..b803cbaa0 100644 --- a/cc/cc_test.go +++ b/cc/cc_test.go @@ -53,8 +53,8 @@ func TestMain(m *testing.M) { 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 testCcNoVndk(t *testing.T, bp string) *android.TestContext { 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 @@ func TestVendorSnapshotUse(t *testing.T) { 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 @@ func TestVendorSnapshotExclude(t *testing.T) { 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 @@ func TestVendorSnapshotExcludeInVendorProprietaryPathErrors(t *testing.T) { 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 @@ func TestVendorSnapshotExcludeWithVendorAvailable(t *testing.T) { 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 @@ func TestProductVariableDefaults(t *testing.T) { 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 @@ func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) { 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 a366f765c..0c7952b70 100644 --- a/cc/genrule_test.go +++ b/cc/genrule_test.go @@ -22,9 +22,9 @@ import ( ) 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 1f070a508..5bf334e3e 100644 --- a/cc/prebuilt_test.go +++ b/cc/prebuilt_test.go @@ -25,7 +25,7 @@ import ( 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 @@ func testPrebuilt(t *testing.T, bp string, fs map[string][]byte, handlers ...con 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 ae59e2f0f..426dfc57c 100644 --- a/cc/test_data_test.go +++ b/cc/test_data_test.go @@ -122,10 +122,10 @@ func TestDataTests(t *testing.T) { "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 388a9ce54..5a311f4b9 100644 --- a/cc/testing.go +++ b/cc/testing.go @@ -545,8 +545,8 @@ func TestConfig(buildDir string, os android.OsType, env map[string]string, 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 9d7dddd84..7c12c68aa 100644 --- a/cmd/soong_build/main.go +++ b/cmd/soong_build/main.go @@ -52,7 +52,7 @@ func newNameResolver(config android.Config) *android.NameResolver { } 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 675b53280..525802a79 100644 --- a/cmd/soong_build/queryview_test.go +++ b/cmd/soong_build/queryview_test.go @@ -234,9 +234,9 @@ func TestGenerateBazelQueryViewFromBlueprint(t *testing.T) { 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 8fc36c274..6c4c0b63d 100644 --- a/etc/prebuilt_etc_test.go +++ b/etc/prebuilt_etc_test.go @@ -58,7 +58,7 @@ func testPrebuiltEtcContext(t *testing.T, bp string) (*android.TestContext, andr 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 @@ func testPrebuiltEtcContext(t *testing.T, bp string) (*android.TestContext, andr 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 fdbb9d962..c19078f0d 100644 --- a/genrule/genrule_test.go +++ b/genrule/genrule_test.go @@ -53,14 +53,14 @@ func TestMain(m *testing.M) { 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 97f76793c..720d3a5ae 100644 --- a/java/android_resources.go +++ b/java/android_resources.go @@ -23,6 +23,7 @@ import ( func init() { android.RegisterPreSingletonType("overlay", OverlaySingletonFactory) + } var androidResourceIgnoreFilenames = []string{ diff --git a/java/app_test.go b/java/app_test.go index 82577e32e..446050d7f 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -59,7 +59,7 @@ func testAppConfig(env map[string]string, bp string, fs map[string][]byte) andro 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 @@ func TestAndroidAppSet_Variants(t *testing.T) { 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 @@ func TestResourceDirs(t *testing.T) { 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 @@ func TestAndroidResources(t *testing.T) { 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 TestAndroidResources(t *testing.T) { } func checkSdkVersion(t *testing.T, config android.Config, expectedSdkVersion string) { - ctx := testContext() + ctx := testContext(config) run(t, ctx, config) @@ -1633,7 +1633,7 @@ func TestCertificates(t *testing.T) { 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 @@ func TestRequestV4SigningFlag(t *testing.T) { 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 @@ func TestPackageNameOverride(t *testing.T) { 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 @@ func TestInstrumentationTargetOverridden(t *testing.T) { ` 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 @@ func TestAndroidAppImport_DpiVariants(t *testing.T) { 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 @@ func TestUsesLibraries(t *testing.T) { config := testAppConfig(nil, bp, nil) config.TestProductVariables.MissingUsesLibraries = []string{"baz"} - ctx := testContext() + ctx := testContext(config) run(t, ctx, config) @@ -3129,7 +3129,7 @@ func TestUncompressDex(t *testing.T) { config.TestProductVariables.Always_use_prebuilt_sdks = proptools.BoolPtr(true) } - ctx := testContext() + ctx := testContext(config) run(t, ctx, config) @@ -3209,7 +3209,7 @@ func TestRuntimeResourceOverlay(t *testing.T) { } ` config := testAppConfig(nil, bp, fs) - ctx := testContext() + ctx := testContext(config) run(t, ctx, config) m := ctx.ModuleForTests("foo", "android_common") @@ -3506,7 +3506,7 @@ func TestEnforceRRO_propagatesToDependencies(t *testing.T) { 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 ab31958cf..95fe5e10e 100644 --- a/java/dexpreopt_bootjars_test.go +++ b/java/dexpreopt_bootjars_test.go @@ -51,7 +51,7 @@ func testDexpreoptBoot(t *testing.T, ruleFile string, expectedInputs, expectedOu 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 7acaae750..34a485618 100644 --- a/java/hiddenapi_singleton_test.go +++ b/java/hiddenapi_singleton_test.go @@ -29,8 +29,8 @@ func testConfigWithBootJars(bp string, bootJars []string) android.Config { 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 testContextWithHiddenAPI() *android.TestContext { 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 6c0a90856..2a27922d1 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -70,9 +70,9 @@ func testConfig(env map[string]string, bp string, fs map[string][]byte) android. 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 @@ func run(t *testing.T, ctx *android.TestContext, config android.Config) { 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 testJavaError(t *testing.T, pattern string, bp string) (*android.TestContex 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 testJava(t *testing.T, bp string) (*android.TestContext, android.Config) { 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 @@ func TestJavaLibrary(t *testing.T) { } `), }) - ctx := testContext() + ctx := testContext(config) run(t, ctx, config) } @@ -1458,7 +1458,7 @@ func TestJavaImport(t *testing.T) { } `), }) - ctx := testContext() + ctx := testContext(config) run(t, ctx, config) } diff --git a/java/sdk_test.go b/java/sdk_test.go index 776069dc9..dc90ea304 100644 --- a/java/sdk_test.go +++ b/java/sdk_test.go @@ -356,7 +356,7 @@ func TestClasspath(t *testing.T) { 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 @@ func TestClasspath(t *testing.T) { 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 @@ func TestClasspath(t *testing.T) { 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 @@ func TestClasspath(t *testing.T) { 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 13c276abf..01f465785 100644 --- a/linkerconfig/linkerconfig_test.go +++ b/linkerconfig/linkerconfig_test.go @@ -56,9 +56,9 @@ func testContext(t *testing.T, bp string) (*android.TestContext, android.Config) 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 10b565ae8..64bc4f6b8 100644 --- a/python/python_test.go +++ b/python/python_test.go @@ -329,13 +329,13 @@ func TestPythonModule(t *testing.T) { 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 7815aab9d..132b7b8fa 100644 --- a/rust/clippy_test.go +++ b/rust/clippy_test.go @@ -65,8 +65,8 @@ func TestClippy(t *testing.T) { 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 a25523c05..a6dba9eec 100644 --- a/rust/compiler_test.go +++ b/rust/compiler_test.go @@ -152,8 +152,8 @@ func TestLints(t *testing.T) { 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 9b2f023b7..14bbd0b9a 100644 --- a/rust/rust_test.go +++ b/rust/rust_test.go @@ -142,8 +142,8 @@ func (tctx testRustCtx) parse(t *testing.T) *android.TestContext { 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 @@ func (tctx testRustCtx) parseError(t *testing.T, pattern string) { 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 40015663a..66877a907 100644 --- a/rust/testing.go +++ b/rust/testing.go @@ -127,8 +127,8 @@ func GatherRequiredDepsForTest() string { 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 0b280efa3..5f520e5b0 100644 --- a/sdk/testing.go +++ b/sdk/testing.go @@ -80,7 +80,7 @@ func testSdkContext(bp string, fs map[string][]byte, extraOsTypes []android.OsTy } } - ctx := android.NewTestArchContext() + ctx := android.NewTestArchContext(config) // Enable androidmk support. // * Register the singleton @@ -129,7 +129,7 @@ func testSdkContext(bp string, fs map[string][]byte, extraOsTypes []android.OsTy 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 0aa607b6f..c664461a9 100644 --- a/sh/sh_binary_test.go +++ b/sh/sh_binary_test.go @@ -45,13 +45,13 @@ func testShBinary(t *testing.T, bp string) (*android.TestContext, android.Config 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 7a79a1b66..b8b93f631 100644 --- a/sysprop/sysprop_test.go +++ b/sysprop/sysprop_test.go @@ -57,7 +57,7 @@ func TestMain(m *testing.M) { 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 @@ func testContext(config android.Config) *android.TestContext { 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 abcb1085f..138503c6d 100644 --- a/xml/xml_test.go +++ b/xml/xml_test.go @@ -57,10 +57,10 @@ func testXml(t *testing.T, bp string) *android.TestContext { "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)