diff options
| author | 2024-01-18 17:22:58 -0800 | |
|---|---|---|
| committer | 2024-01-24 10:17:10 -0800 | |
| commit | 4aa3e0ab81bc7d8db74e9991d6876d19770179ae (patch) | |
| tree | 666176e06471a741b5d2f97870daa84460b41d07 | |
| parent | 1d3d9f13b848118cc4449a8af8b122ee09419d49 (diff) | |
Add ArchModuleContext to TransitionMutator contexts
Converting coverageMutator to a TransitionMutator requires adding
the ctx.Device() and ctx.DeviceConfig() methods.
Bug: 319288033
Test: builds
Change-Id: I697b48eb89bc23800d2d3c62d68358769f0d1075
| -rw-r--r-- | android/module.go | 2 | ||||
| -rw-r--r-- | android/mutator.go | 61 |
2 files changed, 48 insertions, 15 deletions
diff --git a/android/module.go b/android/module.go index 02238e5c7..c3e873e32 100644 --- a/android/module.go +++ b/android/module.go @@ -1627,7 +1627,7 @@ func (m *ModuleBase) baseModuleContextFactory(ctx blueprint.BaseModuleContext) b } } -func (m *ModuleBase) archModuleContextFactory(ctx blueprint.EarlyModuleContext) archModuleContext { +func (m *ModuleBase) archModuleContextFactory(ctx blueprint.IncomingTransitionContext) archModuleContext { config := ctx.Config().(Config) target := m.Target() primaryArch := false diff --git a/android/mutator.go b/android/mutator.go index 93c519d27..e56969829 100644 --- a/android/mutator.go +++ b/android/mutator.go @@ -365,15 +365,21 @@ func (x *registerMutatorsContext) BottomUpBlueprint(name string, m blueprint.Bot } type IncomingTransitionContext interface { + ArchModuleContext + // Module returns the target of the dependency edge for which the transition // is being computed Module() Module // Config returns the configuration for the build. Config() Config + + DeviceConfig() DeviceConfig } type OutgoingTransitionContext interface { + ArchModuleContext + // Module returns the target of the dependency edge for which the transition // is being computed Module() Module @@ -381,9 +387,14 @@ type OutgoingTransitionContext interface { // DepTag() Returns the dependency tag through which this dependency is // reached DepTag() blueprint.DependencyTag + + // Config returns the configuration for the build. + Config() Config + + DeviceConfig() DeviceConfig } -// 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. // @@ -448,18 +459,18 @@ type TransitionMutator interface { // 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. + // 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. @@ -481,6 +492,7 @@ func (a *androidTransitionMutator) Split(ctx blueprint.BaseModuleContext) []stri } type outgoingTransitionContextImpl struct { + archModuleContext bp blueprint.OutgoingTransitionContext } @@ -492,15 +504,28 @@ func (c *outgoingTransitionContextImpl) DepTag() blueprint.DependencyTag { return c.bp.DepTag() } -func (a *androidTransitionMutator) OutgoingTransition(ctx blueprint.OutgoingTransitionContext, sourceVariation string) string { - if _, ok := ctx.Module().(Module); ok { - return a.mutator.OutgoingTransition(&outgoingTransitionContextImpl{bp: ctx}, sourceVariation) +func (c *outgoingTransitionContextImpl) Config() Config { + return c.bp.Config().(Config) +} + +func (c *outgoingTransitionContextImpl) DeviceConfig() DeviceConfig { + return DeviceConfig{c.bp.Config().(Config).deviceConfig} +} + +func (a *androidTransitionMutator) OutgoingTransition(bpctx blueprint.OutgoingTransitionContext, sourceVariation string) string { + if m, ok := bpctx.Module().(Module); ok { + ctx := &outgoingTransitionContextImpl{ + archModuleContext: m.base().archModuleContextFactory(bpctx), + bp: bpctx, + } + return a.mutator.OutgoingTransition(ctx, sourceVariation) } else { return "" } } type incomingTransitionContextImpl struct { + archModuleContext bp blueprint.IncomingTransitionContext } @@ -512,9 +537,17 @@ func (c *incomingTransitionContextImpl) Config() Config { return c.bp.Config().(Config) } -func (a *androidTransitionMutator) IncomingTransition(ctx blueprint.IncomingTransitionContext, incomingVariation string) string { - if _, ok := ctx.Module().(Module); ok { - return a.mutator.IncomingTransition(&incomingTransitionContextImpl{bp: ctx}, incomingVariation) +func (c *incomingTransitionContextImpl) DeviceConfig() DeviceConfig { + return DeviceConfig{c.bp.Config().(Config).deviceConfig} +} + +func (a *androidTransitionMutator) IncomingTransition(bpctx blueprint.IncomingTransitionContext, incomingVariation string) string { + if m, ok := bpctx.Module().(Module); ok { + ctx := &incomingTransitionContextImpl{ + archModuleContext: m.base().archModuleContextFactory(bpctx), + bp: bpctx, + } + return a.mutator.IncomingTransition(ctx, incomingVariation) } else { return "" } |