Merge changes from topic "transition-mutator-config" into main

* changes:
  Add Config() to TransitionMutator contexts
  Fix OutgoingTransitionContext to match the description of TransitionMutators
This commit is contained in:
Colin Cross 2024-01-24 20:03:46 +00:00 committed by Gerrit Code Review
commit 1b3fe6bd2c

View file

@ -690,16 +690,20 @@ type IncomingTransitionContext interface {
}
type OutgoingTransitionContext interface {
// Module returns the target of the dependency edge for which the transition
// Module returns the source of the dependency edge for which the transition
// is being computed
Module() Module
// DepTag() Returns the dependency tag through which this dependency is
// reached
DepTag() DependencyTag
// Config returns the config object that was passed to
// Context.PrepareBuildActions.
Config() interface{}
}
// Transition mutators implement a top-down mechanism where a module tells its
// TransitionMutator implements a top-down mechanism where a module tells its
// direct dependencies what variation they should be built in but the dependency
// has the final say.
//
@ -715,7 +719,7 @@ type OutgoingTransitionContext interface {
// composition the outgoing transition of module A and the incoming transition
// of module B.
//
// the outgoing transition should not take the properties of the dependency into
// The outgoing transition should not take the properties of the dependency into
// account, only those of the module that depends on it. For this reason, the
// dependency is not even passed into it as an argument. Likewise, the incoming
// transition should not take the properties of the depending module into
@ -728,7 +732,7 @@ type OutgoingTransitionContext interface {
// Soong makes sure that all modules are created in the desired variations and
// that dependency edges are set up correctly. This ensures that "missing
// variation" errors do not happen and allows for more flexible changes in the
// value of the variation among dependency edges (as oppposed to bottom-up
// value of the variation among dependency edges (as opposed to bottom-up
// mutators where if module A in variation X depends on module B and module B
// has that variation X, A must depend on variation X of B)
//
@ -757,27 +761,27 @@ type OutgoingTransitionContext interface {
// thus some way is needed to change it state whereas Bazel creates each
// configuration of a given configured target anew.
type TransitionMutator interface {
// Returns the set of variations that should be created for a module no matter
// Split returns the set of variations that should be created for a module no matter
// who depends on it. Used when Make depends on a particular variation or when
// the module knows its variations just based on information given to it in
// the Blueprint file. This method should not mutate the module it is called
// on.
Split(ctx BaseModuleContext) []string
// Called on a module to determine which variation it wants from its direct
// dependencies. The dependency itself can override this decision. This method
// should not mutate the module itself.
// OutgoingTransition is called on a module to determine which variation it wants
// from its direct dependencies. The dependency itself can override this decision.
// This method should not mutate the module itself.
OutgoingTransition(ctx OutgoingTransitionContext, sourceVariation string) string
// Called on a module to determine which variation it should be in based on
// the variation modules that depend on it want. This gives the module a final
// say about its own variations. This method should not mutate the module
// IncomingTransition is called on a module to determine which variation it should
// be in based on the variation modules that depend on it want. This gives the module
// a final say about its own variations. This method should not mutate the module
// itself.
IncomingTransition(ctx IncomingTransitionContext, incomingVariation string) string
// Called after a module was split into multiple variations on each variation.
// It should not split the module any further but adding new dependencies is
// fine. Unlike all the other methods on TransitionMutator, this method is
// Mutate is called after a module was split into multiple variations on each
// variation. It should not split the module any further but adding new dependencies
// is fine. Unlike all the other methods on TransitionMutator, this method is
// allowed to mutate the module.
Mutate(ctx BottomUpMutatorContext, variation string)
}
@ -841,15 +845,12 @@ func (t *transitionMutatorImpl) topDownMutator(mctx TopDownMutatorContext) {
}
type transitionContextImpl struct {
module Module
source Module
dep Module
depTag DependencyTag
config interface{}
}
func (c *transitionContextImpl) Module() Module {
return c.module
}
func (c *transitionContextImpl) DepTag() DependencyTag {
return c.depTag
}
@ -858,11 +859,27 @@ func (c *transitionContextImpl) Config() interface{} {
return c.config
}
type outgoingTransitionContextImpl struct {
transitionContextImpl
}
func (c *outgoingTransitionContextImpl) Module() Module {
return c.source
}
type incomingTransitionContextImpl struct {
transitionContextImpl
}
func (c *incomingTransitionContextImpl) Module() Module {
return c.dep
}
func (t *transitionMutatorImpl) transition(mctx BaseMutatorContext) Transition {
return func(source Module, sourceVariation string, dep Module, depTag DependencyTag) string {
tc := &transitionContextImpl{module: dep, depTag: depTag, config: mctx.Config()}
outgoingVariation := t.mutator.OutgoingTransition(tc, sourceVariation)
finalVariation := t.mutator.IncomingTransition(tc, outgoingVariation)
tc := transitionContextImpl{source: source, dep: dep, depTag: depTag, config: mctx.Config()}
outgoingVariation := t.mutator.OutgoingTransition(&outgoingTransitionContextImpl{tc}, sourceVariation)
finalVariation := t.mutator.IncomingTransition(&incomingTransitionContextImpl{tc}, outgoingVariation)
return finalVariation
}
}