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

Commit 52bb74f9 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Prevent adding new modules after the defaults mutator" into main

parents 2e8239e9 b1ccc2f8
Loading
Loading
Loading
Loading
+0 −8
Original line number Diff line number Diff line
@@ -200,10 +200,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 {
@@ -254,10 +250,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