Add IsAddingDependency to IncomingTransitionContext

Add an IsAddingDependency method to IncomingTransitionContext that
returns true if IncomingTransition is called after the transition
has already won while adding a new dependency.  This will be used
as part of the transition mutators to support an apex use case where
incoming dependencies during the initial apex mutator need to be
rewritten onto the platform variant for modules that don't support
the apex, but a later call to OtherModuleDependencyVariantExists
must not rewrite the requested apex variation onto the platform
variant.

This should be used sparingly, all uses will have to be removed in
order to support creating variants on demand.

Bug: 319288033
Test: TestIsAddingDependency
Flag: EXEMPT refactor
Change-Id: Ib8e419d35ff8f7cbff9667c1cd40d05ccfacab8b
This commit is contained in:
Colin Cross
2024-06-14 12:17:37 -07:00
parent 694fced1e3
commit e1a8555581
8 changed files with 51 additions and 27 deletions

View File

@@ -1746,7 +1746,11 @@ func (m *ModuleBase) baseModuleContextFactory(ctx blueprint.BaseModuleContext) b
} }
} }
func (m *ModuleBase) archModuleContextFactory(ctx blueprint.IncomingTransitionContext) archModuleContext { type archModuleContextFactoryContext interface {
Config() interface{}
}
func (m *ModuleBase) archModuleContextFactory(ctx archModuleContextFactoryContext) archModuleContext {
config := ctx.Config().(Config) config := ctx.Config().(Config)
target := m.Target() target := m.Target()
primaryArch := false primaryArch := false

View File

@@ -400,6 +400,12 @@ type IncomingTransitionContext interface {
Config() Config Config() Config
DeviceConfig() DeviceConfig DeviceConfig() DeviceConfig
// IsAddingDependency returns true if the transition is being called while adding a dependency
// after the transition mutator has already run, or false if it is being called when the transition
// mutator is running. This should be used sparingly, all uses will have to be removed in order
// to support creating variants on demand.
IsAddingDependency() bool
} }
type OutgoingTransitionContext interface { type OutgoingTransitionContext interface {
@@ -574,6 +580,10 @@ func (c *incomingTransitionContextImpl) DeviceConfig() DeviceConfig {
return DeviceConfig{c.bp.Config().(Config).deviceConfig} return DeviceConfig{c.bp.Config().(Config).deviceConfig}
} }
func (c *incomingTransitionContextImpl) IsAddingDependency() bool {
return c.bp.IsAddingDependency()
}
func (c *incomingTransitionContextImpl) provider(provider blueprint.AnyProviderKey) (any, bool) { func (c *incomingTransitionContextImpl) provider(provider blueprint.AnyProviderKey) (any, bool) {
return c.bp.Provider(provider) return c.bp.Provider(provider)
} }

View File

@@ -1363,7 +1363,7 @@ func (a *apexBundle) TaggedOutputs() map[string]android.Paths {
var _ cc.Coverage = (*apexBundle)(nil) var _ cc.Coverage = (*apexBundle)(nil)
// Implements cc.Coverage // Implements cc.Coverage
func (a *apexBundle) IsNativeCoverageNeeded(ctx android.IncomingTransitionContext) bool { func (a *apexBundle) IsNativeCoverageNeeded(ctx cc.IsNativeCoverageNeededContext) bool {
return ctx.DeviceConfig().NativeCoverageEnabled() return ctx.DeviceConfig().NativeCoverageEnabled()
} }

View File

@@ -247,9 +247,19 @@ func SetCoverageProperties(ctx android.BaseModuleContext, properties CoveragePro
return properties return properties
} }
type IsNativeCoverageNeededContext interface {
Config() android.Config
DeviceConfig() android.DeviceConfig
Device() bool
}
var _ IsNativeCoverageNeededContext = android.IncomingTransitionContext(nil)
var _ IsNativeCoverageNeededContext = android.BaseModuleContext(nil)
var _ IsNativeCoverageNeededContext = android.BottomUpMutatorContext(nil)
type UseCoverage interface { type UseCoverage interface {
android.Module android.Module
IsNativeCoverageNeeded(ctx android.IncomingTransitionContext) bool IsNativeCoverageNeeded(ctx IsNativeCoverageNeededContext) bool
} }
// Coverage is an interface for non-CC modules to implement to be mutated for coverage // Coverage is an interface for non-CC modules to implement to be mutated for coverage

View File

@@ -632,7 +632,7 @@ func sha1sum(values []string) string {
var _ cc.UseCoverage = (*filesystem)(nil) var _ cc.UseCoverage = (*filesystem)(nil)
func (*filesystem) IsNativeCoverageNeeded(ctx android.IncomingTransitionContext) bool { func (*filesystem) IsNativeCoverageNeeded(ctx cc.IsNativeCoverageNeededContext) bool {
return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled() return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
} }

View File

@@ -1227,7 +1227,7 @@ func (a *AndroidApp) Privileged() bool {
return Bool(a.appProperties.Privileged) return Bool(a.appProperties.Privileged)
} }
func (a *AndroidApp) IsNativeCoverageNeeded(ctx android.IncomingTransitionContext) bool { func (a *AndroidApp) IsNativeCoverageNeeded(ctx cc.IsNativeCoverageNeededContext) bool {
return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled() return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
} }

View File

@@ -1358,7 +1358,7 @@ func (j *JavaTestImport) InstallInTestcases() bool {
return true return true
} }
func (j *TestHost) IsNativeCoverageNeeded(ctx android.IncomingTransitionContext) bool { func (j *TestHost) IsNativeCoverageNeeded(ctx cc.IsNativeCoverageNeededContext) bool {
return ctx.DeviceConfig().NativeCoverageEnabled() return ctx.DeviceConfig().NativeCoverageEnabled()
} }

View File

@@ -501,7 +501,7 @@ func (mod *Module) isCoverageVariant() bool {
var _ cc.Coverage = (*Module)(nil) var _ cc.Coverage = (*Module)(nil)
func (mod *Module) IsNativeCoverageNeeded(ctx android.IncomingTransitionContext) bool { func (mod *Module) IsNativeCoverageNeeded(ctx cc.IsNativeCoverageNeededContext) bool {
return mod.coverage != nil && mod.coverage.Properties.NeedCoverageVariant return mod.coverage != nil && mod.coverage.Properties.NeedCoverageVariant
} }