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

Commit b1ccc2f8 authored by Cole Faust's avatar Cole Faust
Browse files

Prevent adding new modules after the defaults mutator

Modules created after a mutator has run will not see the effects
of that mutator. So it's better to create modules as early as possible.

Bug: 361816274
Test: m nothing --no-skip-soong-tests
Change-Id: I21c7fae7c137ab091fd8a63f7432a6df9b474959
parent b16bd5db
Loading
Loading
Loading
Loading
+0 −8
Original line number Diff line number Diff line
@@ -220,10 +220,6 @@ type BaseModuleContext interface {
	// EvaluateConfiguration makes ModuleContext a valid proptools.ConfigurableEvaluator, so this context
	// can be used to evaluate the final value of Configurable properties.
	EvaluateConfiguration(condition proptools.ConfigurableCondition, property string) proptools.ConfigurableValue

	// HasMutatorFinished returns true if the given mutator has finished running.
	// It will panic if given an invalid mutator name.
	HasMutatorFinished(mutatorName string) bool
}

type baseModuleContext struct {
@@ -274,10 +270,6 @@ func (b *baseModuleContext) setProvider(provider blueprint.AnyProviderKey, value
	b.bp.SetProvider(provider, value)
}

func (b *baseModuleContext) HasMutatorFinished(mutatorName string) bool {
	return b.bp.HasMutatorFinished(mutatorName)
}

func (b *baseModuleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
	return b.bp.GetDirectDepWithTag(name, tag)
}
+8 −0
Original line number Diff line number Diff line
@@ -93,6 +93,10 @@ type EarlyModuleContext interface {
	// Namespace returns the Namespace object provided by the NameInterface set by Context.SetNameInterface, or the
	// default SimpleNameInterface if Context.SetNameInterface was not called.
	Namespace() *Namespace

	// HasMutatorFinished returns true if the given mutator has finished running.
	// It will panic if given an invalid mutator name.
	HasMutatorFinished(mutatorName string) bool
}

// Deprecated: use EarlyModuleContext instead
@@ -175,3 +179,7 @@ func (e *earlyModuleContext) Namespace() *Namespace {
func (e *earlyModuleContext) OtherModulePropertyErrorf(module Module, property string, fmt string, args ...interface{}) {
	e.EarlyModuleContext.OtherModulePropertyErrorf(module, property, fmt, args...)
}

func (e *earlyModuleContext) HasMutatorFinished(mutatorName string) bool {
	return e.EarlyModuleContext.HasMutatorFinished(mutatorName)
}
+7 −0
Original line number Diff line number Diff line
@@ -95,10 +95,17 @@ func (l *loadHookContext) createModule(factory blueprint.ModuleFactory, name str

type createModuleContext interface {
	Module() Module
	HasMutatorFinished(mutatorName string) bool
	createModule(blueprint.ModuleFactory, string, ...interface{}) blueprint.Module
}

func createModule(ctx createModuleContext, factory ModuleFactory, ext string, props ...interface{}) Module {
	if ctx.HasMutatorFinished("defaults") {
		// Creating modules late is oftentimes problematic, because they don't have earlier
		// mutators run on them. Prevent making modules after the defaults mutator has run.
		panic("Cannot create a module after the defaults mutator has finished")
	}

	inherited := []interface{}{&ctx.Module().base().commonProperties}

	var typeName string