summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Paul Duffin <paulduffin@google.com> 2023-01-09 14:02:06 +0000
committer Paul Duffin <paulduffin@google.com> 2023-01-09 16:48:46 +0000
commit3229998d374a3e0c039800d250e645540acd8bb4 (patch)
tree8f5fb1615f27f532bacfc855e7e1f75774952727
parent939673bf6b81ae1af7f1e6985a72e24b06aa46ab (diff)
Dedup registration of Soong config module types
Bug: 264876909 Test: m nothing Change-Id: I467a2090b32438cbbf88bbb453bb4960757ec37a
-rw-r--r--android/soong_config_modules.go14
-rw-r--r--android/soong_config_modules_test.go35
-rw-r--r--bp2build/soong_config_module_type_conversion_test.go5
3 files changed, 22 insertions, 32 deletions
diff --git a/android/soong_config_modules.go b/android/soong_config_modules.go
index c1e92b8b8..7434c8912 100644
--- a/android/soong_config_modules.go
+++ b/android/soong_config_modules.go
@@ -31,12 +31,18 @@ import (
)
func init() {
- RegisterModuleType("soong_config_module_type_import", SoongConfigModuleTypeImportFactory)
- RegisterModuleType("soong_config_module_type", SoongConfigModuleTypeFactory)
- RegisterModuleType("soong_config_string_variable", SoongConfigStringVariableDummyFactory)
- RegisterModuleType("soong_config_bool_variable", SoongConfigBoolVariableDummyFactory)
+ RegisterSoongConfigModuleBuildComponents(InitRegistrationContext)
}
+func RegisterSoongConfigModuleBuildComponents(ctx RegistrationContext) {
+ ctx.RegisterModuleType("soong_config_module_type_import", SoongConfigModuleTypeImportFactory)
+ ctx.RegisterModuleType("soong_config_module_type", SoongConfigModuleTypeFactory)
+ ctx.RegisterModuleType("soong_config_string_variable", SoongConfigStringVariableDummyFactory)
+ ctx.RegisterModuleType("soong_config_bool_variable", SoongConfigBoolVariableDummyFactory)
+}
+
+var PrepareForTestWithSoongConfigModuleBuildComponents = FixtureRegisterWithContext(RegisterSoongConfigModuleBuildComponents)
+
type soongConfigModuleTypeImport struct {
ModuleBase
properties soongConfigModuleTypeImportProperties
diff --git a/android/soong_config_modules_test.go b/android/soong_config_modules_test.go
index ceb8e45a5..32b3a1977 100644
--- a/android/soong_config_modules_test.go
+++ b/android/soong_config_modules_test.go
@@ -53,6 +53,11 @@ func soongConfigTestModuleFactory() Module {
func (t soongConfigTestModule) GenerateAndroidBuildActions(ModuleContext) {}
+var prepareForSoongConfigTestModule = FixtureRegisterWithContext(func(ctx RegistrationContext) {
+ ctx.RegisterModuleType("test_defaults", soongConfigTestDefaultsModuleFactory)
+ ctx.RegisterModuleType("test", soongConfigTestModuleFactory)
+})
+
func TestSoongConfigModule(t *testing.T) {
configBp := `
soong_config_module_type {
@@ -309,14 +314,8 @@ func TestSoongConfigModule(t *testing.T) {
result := GroupFixturePreparers(
tc.preparer,
PrepareForTestWithDefaults,
- FixtureRegisterWithContext(func(ctx RegistrationContext) {
- ctx.RegisterModuleType("soong_config_module_type_import", SoongConfigModuleTypeImportFactory)
- ctx.RegisterModuleType("soong_config_module_type", SoongConfigModuleTypeFactory)
- ctx.RegisterModuleType("soong_config_string_variable", SoongConfigStringVariableDummyFactory)
- ctx.RegisterModuleType("soong_config_bool_variable", SoongConfigBoolVariableDummyFactory)
- ctx.RegisterModuleType("test_defaults", soongConfigTestDefaultsModuleFactory)
- ctx.RegisterModuleType("test", soongConfigTestModuleFactory)
- }),
+ PrepareForTestWithSoongConfigModuleBuildComponents,
+ prepareForSoongConfigTestModule,
fs.AddToFixture(),
FixtureWithRootAndroidBp(bp),
).RunTest(t)
@@ -371,14 +370,8 @@ func TestNonExistentPropertyInSoongConfigModule(t *testing.T) {
GroupFixturePreparers(
fixtureForVendorVars(map[string]map[string]string{"acme": {"feature1": "1"}}),
PrepareForTestWithDefaults,
- FixtureRegisterWithContext(func(ctx RegistrationContext) {
- ctx.RegisterModuleType("soong_config_module_type_import", SoongConfigModuleTypeImportFactory)
- ctx.RegisterModuleType("soong_config_module_type", SoongConfigModuleTypeFactory)
- ctx.RegisterModuleType("soong_config_string_variable", SoongConfigStringVariableDummyFactory)
- ctx.RegisterModuleType("soong_config_bool_variable", SoongConfigBoolVariableDummyFactory)
- ctx.RegisterModuleType("test_defaults", soongConfigTestDefaultsModuleFactory)
- ctx.RegisterModuleType("test", soongConfigTestModuleFactory)
- }),
+ PrepareForTestWithSoongConfigModuleBuildComponents,
+ prepareForSoongConfigTestModule,
FixtureWithRootAndroidBp(bp),
).ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern([]string{
// TODO(b/171232169): improve the error message for non-existent properties
@@ -411,14 +404,8 @@ func TestDuplicateStringValueInSoongConfigStringVariable(t *testing.T) {
GroupFixturePreparers(
fixtureForVendorVars(map[string]map[string]string{"acme": {"feature1": "1"}}),
PrepareForTestWithDefaults,
- FixtureRegisterWithContext(func(ctx RegistrationContext) {
- ctx.RegisterModuleType("soong_config_module_type_import", SoongConfigModuleTypeImportFactory)
- ctx.RegisterModuleType("soong_config_module_type", SoongConfigModuleTypeFactory)
- ctx.RegisterModuleType("soong_config_string_variable", SoongConfigStringVariableDummyFactory)
- ctx.RegisterModuleType("soong_config_bool_variable", SoongConfigBoolVariableDummyFactory)
- ctx.RegisterModuleType("test_defaults", soongConfigTestDefaultsModuleFactory)
- ctx.RegisterModuleType("test", soongConfigTestModuleFactory)
- }),
+ PrepareForTestWithSoongConfigModuleBuildComponents,
+ prepareForSoongConfigTestModule,
FixtureWithRootAndroidBp(bp),
).ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern([]string{
// TODO(b/171232169): improve the error message for non-existent properties
diff --git a/bp2build/soong_config_module_type_conversion_test.go b/bp2build/soong_config_module_type_conversion_test.go
index 7029b93c7..dcd1f856c 100644
--- a/bp2build/soong_config_module_type_conversion_test.go
+++ b/bp2build/soong_config_module_type_conversion_test.go
@@ -29,10 +29,7 @@ func runSoongConfigModuleTypeTest(t *testing.T, tc Bp2buildTestCase) {
func registerSoongConfigModuleTypes(ctx android.RegistrationContext) {
cc.RegisterCCBuildComponents(ctx)
- ctx.RegisterModuleType("soong_config_module_type_import", android.SoongConfigModuleTypeImportFactory)
- ctx.RegisterModuleType("soong_config_module_type", android.SoongConfigModuleTypeFactory)
- ctx.RegisterModuleType("soong_config_string_variable", android.SoongConfigStringVariableDummyFactory)
- ctx.RegisterModuleType("soong_config_bool_variable", android.SoongConfigBoolVariableDummyFactory)
+ android.RegisterSoongConfigModuleBuildComponents(ctx)
ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
}