Avoid separate call to module factory to create conditional properties

Previously, the soong_config_module_type (and related module types)
would make a special call to the module factory of the module type
being customized to get the properties from which it created the
conditional properties. That caused problems when trying to customize
a singleton module. See the bug for more details.

This change avoids that special call by deferring the creation of the
conditional properties struct until just after the
soong_config_module_type's factory function calls the customized module
factory to create the module and properties. The properties are then
used to create the conditional properties struct avoiding the extra
factory call.

The conditional properties struct is only created once per module type
that soong_config_module_type (and related module types) creates.

Bug: 264876909
Test: m nothing
Change-Id: I55dc71d2553cb59d921a96c6458d0bc877512bbb
This commit is contained in:
Paul Duffin
2023-01-09 15:42:57 +00:00
parent f1e6a048d0
commit e8b4768134
3 changed files with 43 additions and 10 deletions

View File

@@ -483,7 +483,7 @@ func TestSoongConfigModuleSingletonModule(t *testing.T) {
},
} {
t.Run(fmt.Sprintf("coyote:%t", test.coyote), func(t *testing.T) {
GroupFixturePreparers(
result := GroupFixturePreparers(
PrepareForTestWithSoongConfigModuleBuildComponents,
prepareForSoongConfigTestSingletonModule,
FixtureWithRootAndroidBp(bp),
@@ -494,9 +494,12 @@ func TestSoongConfigModuleSingletonModule(t *testing.T) {
},
}
}),
).ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern([]string{
`\QDuplicate SingletonModule "test_singleton", previously used in\E`,
})).RunTest(t)
).RunTest(t)
// Make sure that the singleton was created.
result.SingletonForTests("test_singleton")
m := result.ModuleForTests("wiley", "").module.(*soongConfigTestSingletonModule)
AssertStringEquals(t, "fragments", test.expectedFragments, fmt.Sprintf("%+v", m.props.Fragments))
})
}
}