Merge "Ensure test/runtime order of singletons/pre-singletons is consistent" am: 062d9338d1

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1622504

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ib44998a6b729b73c5eb03b07eb58aafa5db935bc
This commit is contained in:
Paul Duffin 2021-03-09 01:57:41 +00:00 committed by Automerger Merge Worker
commit 9f9233eec6
1 changed files with 24 additions and 3 deletions

View File

@ -101,8 +101,9 @@ type TestContext struct {
// The list of pre-singletons and singletons registered for the test.
preSingletons, singletons sortableComponents
// The order in which the mutators will be run in this test context; for debugging.
mutatorOrder []string
// The order in which the pre-singletons, mutators and singletons will be run in this test
// context; for debugging.
preSingletonOrder, mutatorOrder, singletonOrder []string
}
func (ctx *TestContext) PreArchMutators(f RegisterMutatorFunc) {
@ -315,8 +316,14 @@ type registrationSorter struct {
// Used to ensure that this is only created once.
once sync.Once
// The order of pre-singletons
preSingletonOrder registeredComponentOrder
// The order of mutators
mutatorOrder registeredComponentOrder
// The order of singletons
singletonOrder registeredComponentOrder
}
// populate initializes this structure from globally registered build components.
@ -324,9 +331,16 @@ type registrationSorter struct {
// Only the first call has any effect.
func (s *registrationSorter) populate() {
s.once.Do(func() {
// Create an ordering from the globally registered pre-singletons.
s.preSingletonOrder = registeredComponentOrderFromExistingOrder("pre-singleton", preSingletons)
// Created an ordering from the globally registered mutators.
globallyRegisteredMutators := collateGloballyRegisteredMutators()
s.mutatorOrder = registeredComponentOrderFromExistingOrder("mutator", globallyRegisteredMutators)
// Create an ordering from the globally registered singletons.
globallyRegisteredSingletons := collateGloballyRegisteredSingletons()
s.singletonOrder = registeredComponentOrderFromExistingOrder("singleton", globallyRegisteredSingletons)
})
}
@ -346,6 +360,9 @@ func globallyRegisteredComponentsOrder() *registrationSorter {
func (ctx *TestContext) Register() {
globalOrder := globallyRegisteredComponentsOrder()
// Ensure that the pre-singletons used in the test are in the same order as they are used at
// runtime.
globalOrder.preSingletonOrder.enforceOrdering(ctx.preSingletons)
ctx.preSingletons.registerAll(ctx.Context)
mutators := collateRegisteredMutators(ctx.preArch, ctx.preDeps, ctx.postDeps, ctx.finalDeps)
@ -356,10 +373,14 @@ func (ctx *TestContext) Register() {
// Register the env singleton with this context before sorting.
ctx.RegisterSingletonType("env", EnvSingleton)
// Ensure that the singletons used in the test are in the same order as they are used at runtime.
globalOrder.singletonOrder.enforceOrdering(ctx.singletons)
ctx.singletons.registerAll(ctx.Context)
// Save the mutator order away to make it easy to access while debugging.
// Save the sorted components order away to make them easy to access while debugging.
ctx.preSingletonOrder = globalOrder.preSingletonOrder.namesInOrder
ctx.mutatorOrder = globalOrder.mutatorOrder.namesInOrder
ctx.singletonOrder = globalOrder.singletonOrder.namesInOrder
}
// RegisterForBazelConversion prepares a test context for bp2build conversion.