Fix OutgoingTransitionContext to match the description of TransitionMutators am: 33bec91aec

Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/2923530

Change-Id: I8f76a7cdc0694e0f8ea34fb1b17ade729a6cf412
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Colin Cross 2024-01-24 20:36:25 +00:00 committed by Automerger Merge Worker
commit 8530c625b9

View file

@ -690,7 +690,7 @@ 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
@ -699,7 +699,7 @@ type OutgoingTransitionContext interface {
DepTag() DependencyTag
}
// 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 +715,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 +728,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 +757,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 +841,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 +855,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
}
}