Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 42d0b931 authored by Paul Duffin's avatar Paul Duffin
Browse files

Separate the collation of singletons from registration

That is to allow the order in which singletons are registered at
runtime, including the ones added by default, to be used to define the
order in which singletons must be registered in tests.

Bug: 181953909
Test: m nothing
Change-Id: I22f90c90100a8d52a572d4451a1a5d256784b57a
parent d182fb39
Loading
Loading
Loading
Loading
+19 −11
Original line number Diff line number Diff line
@@ -186,23 +186,31 @@ func (ctx *Context) Register() {
		t.register(ctx)
	}

	singletons.registerAll(ctx)

	mutators := collateGloballyRegisteredMutators()
	mutators.registerAll(ctx)

	ctx.RegisterSingletonType("bazeldeps", SingletonFactoryAdaptor(ctx, BazelSingleton))
	singletons := collateGloballyRegisteredSingletons()
	singletons.registerAll(ctx)
}

func collateGloballyRegisteredSingletons() sortableComponents {
	allSingletons := append(sortableComponents(nil), singletons...)
	allSingletons = append(allSingletons,
		singleton{false, "bazeldeps", BazelSingleton},

		// Register phony just before makevars so it can write out its phony rules as Make rules
	ctx.RegisterSingletonType("phony", SingletonFactoryAdaptor(ctx, phonySingletonFactory))
		singleton{false, "phony", phonySingletonFactory},

		// Register makevars after other singletons so they can export values through makevars
	ctx.RegisterSingletonType("makevars", SingletonFactoryAdaptor(ctx, makeVarsSingletonFunc))
		singleton{false, "makevars", makeVarsSingletonFunc},

		// Register env and ninjadeps last so that they can track all used environment variables and
		// Ninja file dependencies stored in the config.
	ctx.RegisterSingletonType("env", SingletonFactoryAdaptor(ctx, EnvSingleton))
	ctx.RegisterSingletonType("ninjadeps", SingletonFactoryAdaptor(ctx, ninjaDepsSingletonFactory))
		singleton{false, "env", EnvSingleton},
		singleton{false, "ninjadeps", ninjaDepsSingletonFactory},
	)

	return allSingletons
}

func ModuleTypeFactories() map[string]ModuleFactory {