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
diff --git a/android/module.go b/android/module.go
index 4a6f5d1..f7061db 100644
--- a/android/module.go
+++ b/android/module.go
@@ -1746,7 +1746,11 @@
}
}
-func (m *ModuleBase) archModuleContextFactory(ctx blueprint.IncomingTransitionContext) archModuleContext {
+type archModuleContextFactoryContext interface {
+ Config() interface{}
+}
+
+func (m *ModuleBase) archModuleContextFactory(ctx archModuleContextFactoryContext) archModuleContext {
config := ctx.Config().(Config)
target := m.Target()
primaryArch := false
diff --git a/android/mutator.go b/android/mutator.go
index 440b906..b81dd12 100644
--- a/android/mutator.go
+++ b/android/mutator.go
@@ -400,6 +400,12 @@
Config() Config
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 {
@@ -574,6 +580,10 @@
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) {
return c.bp.Provider(provider)
}
diff --git a/apex/apex.go b/apex/apex.go
index ab50e85..10fe372 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -1363,7 +1363,7 @@
var _ cc.Coverage = (*apexBundle)(nil)
// Implements cc.Coverage
-func (a *apexBundle) IsNativeCoverageNeeded(ctx android.IncomingTransitionContext) bool {
+func (a *apexBundle) IsNativeCoverageNeeded(ctx cc.IsNativeCoverageNeededContext) bool {
return ctx.DeviceConfig().NativeCoverageEnabled()
}
diff --git a/cc/coverage.go b/cc/coverage.go
index f6092e4..a7618dd 100644
--- a/cc/coverage.go
+++ b/cc/coverage.go
@@ -23,26 +23,26 @@
)
var (
- clangCoverageHostLdFlags = []string{
- "-Wl,--no-as-needed",
- "-Wl,--wrap,open",
- }
- clangContinuousCoverageFlags = []string{
- "-mllvm",
- "-runtime-counter-relocation",
- }
- clangCoverageCFlags = []string{
- "-Wno-frame-larger-than=",
- }
- clangCoverageCommonFlags = []string{
- "-fcoverage-mapping",
- "-Wno-pass-failed",
- "-D__ANDROID_CLANG_COVERAGE__",
- }
- clangCoverageHWASanFlags = []string{
- "-mllvm",
- "-hwasan-globals=0",
- }
+ clangCoverageHostLdFlags = []string{
+ "-Wl,--no-as-needed",
+ "-Wl,--wrap,open",
+ }
+ clangContinuousCoverageFlags = []string{
+ "-mllvm",
+ "-runtime-counter-relocation",
+ }
+ clangCoverageCFlags = []string{
+ "-Wno-frame-larger-than=",
+ }
+ clangCoverageCommonFlags = []string{
+ "-fcoverage-mapping",
+ "-Wno-pass-failed",
+ "-D__ANDROID_CLANG_COVERAGE__",
+ }
+ clangCoverageHWASanFlags = []string{
+ "-mllvm",
+ "-hwasan-globals=0",
+ }
)
const profileInstrFlag = "-fprofile-instr-generate=/data/misc/trace/clang-%p-%m.profraw"
@@ -247,9 +247,19 @@
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 {
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
diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go
index ffa30a0..5add954 100644
--- a/filesystem/filesystem.go
+++ b/filesystem/filesystem.go
@@ -632,7 +632,7 @@
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()
}
diff --git a/java/app.go b/java/app.go
index fc2294c..19dc8d5 100644
--- a/java/app.go
+++ b/java/app.go
@@ -1227,7 +1227,7 @@
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()
}
diff --git a/java/java.go b/java/java.go
index 5fdb4b8..88b31b5 100644
--- a/java/java.go
+++ b/java/java.go
@@ -1358,7 +1358,7 @@
return true
}
-func (j *TestHost) IsNativeCoverageNeeded(ctx android.IncomingTransitionContext) bool {
+func (j *TestHost) IsNativeCoverageNeeded(ctx cc.IsNativeCoverageNeededContext) bool {
return ctx.DeviceConfig().NativeCoverageEnabled()
}
diff --git a/rust/rust.go b/rust/rust.go
index 3299861..9dae75e 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -501,7 +501,7 @@
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
}