aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2024-01-22 17:13:12 -0800
committerColin Cross <ccross@android.com>2024-01-22 17:18:40 -0800
commit33bec91aec54ca07ea594a96dfa9bcfbd884cb55 (patch)
tree47d381edbd476461368667d540957d267bf285c8
parente70495ba9a5d5fabe339f388a5e29bb248a66c99 (diff)
downloadblueprint-33bec91aec54ca07ea594a96dfa9bcfbd884cb55.tar.gz
Fix OutgoingTransitionContext to match the description of TransitionMutators
The description of TransitionMutators says that "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." However, OutgoingTransitionContext was returing the dependency from ctx.Module(), not the parent. This didn't matter for the only existing TransitionMutator, as it only used the module to get a constant value. Test: sanitize_test.go Change-Id: I1ce5b3144787f57be4d50e95f0c923da9b2b079f
-rw-r--r--context.go57
1 files changed, 35 insertions, 22 deletions
diff --git a/context.go b/context.go
index 6838408..63a1f04 100644
--- a/context.go
+++ b/context.go
@@ -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
}
}