Store SingletonMakeVarsProviders in the config
Store SingletonMakeVarsProviders in the config instead of a global variable to avoid races between tests running in parallel. Test: all soong tests Change-Id: I2ab64f368b5ac673fd985399d4421ed018abc562
This commit is contained in:
@@ -139,15 +139,24 @@ type SingletonMakeVarsProvider interface {
|
||||
MakeVars(ctx MakeVarsContext)
|
||||
}
|
||||
|
||||
// registerSingletonMakeVarsProvider adds a singleton that implements SingletonMakeVarsProvider to the list of
|
||||
// MakeVarsProviders to run.
|
||||
func registerSingletonMakeVarsProvider(singleton SingletonMakeVarsProvider) {
|
||||
singletonMakeVarsProviders = append(singletonMakeVarsProviders,
|
||||
makeVarsProvider{pctx, SingletonmakeVarsProviderAdapter(singleton)})
|
||||
var singletonMakeVarsProvidersKey = NewOnceKey("singletonMakeVarsProvidersKey")
|
||||
|
||||
// registerSingletonMakeVarsProvider adds a singleton that implements SingletonMakeVarsProvider to
|
||||
// the list of MakeVarsProviders to run.
|
||||
func registerSingletonMakeVarsProvider(config Config, singleton SingletonMakeVarsProvider) {
|
||||
// Singletons are registered on the Context and may be different between different Contexts,
|
||||
// for example when running multiple tests. Store the SingletonMakeVarsProviders in the
|
||||
// Config so they are attached to the Context.
|
||||
singletonMakeVarsProviders := config.Once(singletonMakeVarsProvidersKey, func() interface{} {
|
||||
return &[]makeVarsProvider{}
|
||||
}).(*[]makeVarsProvider)
|
||||
|
||||
*singletonMakeVarsProviders = append(*singletonMakeVarsProviders,
|
||||
makeVarsProvider{pctx, singletonMakeVarsProviderAdapter(singleton)})
|
||||
}
|
||||
|
||||
// SingletonmakeVarsProviderAdapter converts a SingletonMakeVarsProvider to a MakeVarsProvider.
|
||||
func SingletonmakeVarsProviderAdapter(singleton SingletonMakeVarsProvider) MakeVarsProvider {
|
||||
// singletonMakeVarsProviderAdapter converts a SingletonMakeVarsProvider to a MakeVarsProvider.
|
||||
func singletonMakeVarsProviderAdapter(singleton SingletonMakeVarsProvider) MakeVarsProvider {
|
||||
return func(ctx MakeVarsContext) { singleton.MakeVars(ctx) }
|
||||
}
|
||||
|
||||
@@ -175,9 +184,6 @@ type makeVarsProvider struct {
|
||||
// Collection of makevars providers that are registered in init() methods.
|
||||
var makeVarsInitProviders []makeVarsProvider
|
||||
|
||||
// Collection of singleton makevars providers that are not registered as part of init() methods.
|
||||
var singletonMakeVarsProviders []makeVarsProvider
|
||||
|
||||
type makeVarsContext struct {
|
||||
SingletonContext
|
||||
config Config
|
||||
@@ -224,7 +230,11 @@ func (s *makeVarsSingleton) GenerateBuildActions(ctx SingletonContext) {
|
||||
var vars []makeVarsVariable
|
||||
var dists []dist
|
||||
var phonies []phony
|
||||
for _, provider := range append(makeVarsInitProviders) {
|
||||
|
||||
providers := append([]makeVarsProvider(nil), makeVarsInitProviders...)
|
||||
providers = append(providers, *ctx.Config().Get(singletonMakeVarsProvidersKey).(*[]makeVarsProvider)...)
|
||||
|
||||
for _, provider := range providers {
|
||||
mctx := &makeVarsContext{
|
||||
SingletonContext: ctx,
|
||||
pctx: provider.pctx,
|
||||
@@ -237,25 +247,6 @@ func (s *makeVarsSingleton) GenerateBuildActions(ctx SingletonContext) {
|
||||
dists = append(dists, mctx.dists...)
|
||||
}
|
||||
|
||||
for _, provider := range append(singletonMakeVarsProviders) {
|
||||
mctx := &makeVarsContext{
|
||||
SingletonContext: ctx,
|
||||
pctx: provider.pctx,
|
||||
}
|
||||
|
||||
provider.call(mctx)
|
||||
|
||||
vars = append(vars, mctx.vars...)
|
||||
phonies = append(phonies, mctx.phonies...)
|
||||
dists = append(dists, mctx.dists...)
|
||||
}
|
||||
|
||||
// Clear singleton makevars providers after use. Since these are in-memory
|
||||
// singletons, this ensures state is reset if the build tree is processed
|
||||
// multiple times.
|
||||
// TODO(cparsons): Clean up makeVarsProviders to be part of the context.
|
||||
singletonMakeVarsProviders = nil
|
||||
|
||||
ctx.VisitAllModules(func(m Module) {
|
||||
if provider, ok := m.(ModuleMakeVarsProvider); ok && m.Enabled() {
|
||||
mctx := &makeVarsContext{
|
||||
|
Reference in New Issue
Block a user