Convert fuzzMutatorDeps to a transition mutator
fuzzMutatorDeps was modifying dependencies, which prevents incremental
analysis. Use a transition mutator instead.
Bug: 319288033
Test: m haiku
Flag: EXEMPT refactor
Change-Id: I1a518ad633bea06c618148f05ffe1434ed8c79ea
diff --git a/cc/fuzz.go b/cc/fuzz.go
index 3f21bc6..0aa9d4b 100644
--- a/cc/fuzz.go
+++ b/cc/fuzz.go
@@ -57,38 +57,76 @@
return []interface{}{&fuzzer.Properties}
}
-func fuzzMutatorDeps(mctx android.BottomUpMutatorContext) {
- currentModule, ok := mctx.Module().(*Module)
+// fuzzTransitionMutator creates variants to propagate the FuzzFramework value down to dependencies.
+type fuzzTransitionMutator struct{}
+
+func (f *fuzzTransitionMutator) Split(ctx android.BaseModuleContext) []string {
+ return []string{""}
+}
+
+func (f *fuzzTransitionMutator) OutgoingTransition(ctx android.OutgoingTransitionContext, sourceVariation string) string {
+ m, ok := ctx.Module().(*Module)
+ if !ok {
+ return ""
+ }
+
+ if m.fuzzer == nil {
+ return ""
+ }
+
+ if m.sanitize == nil {
+ return ""
+ }
+
+ isFuzzerPointer := m.sanitize.getSanitizerBoolPtr(Fuzzer)
+ if isFuzzerPointer == nil || !*isFuzzerPointer {
+ return ""
+ }
+
+ if m.fuzzer.Properties.FuzzFramework != "" {
+ return m.fuzzer.Properties.FuzzFramework.Variant()
+ }
+
+ return sourceVariation
+}
+
+func (f *fuzzTransitionMutator) IncomingTransition(ctx android.IncomingTransitionContext, incomingVariation string) string {
+ m, ok := ctx.Module().(*Module)
+ if !ok {
+ return ""
+ }
+
+ if m.fuzzer == nil {
+ return ""
+ }
+
+ if m.sanitize == nil {
+ return ""
+ }
+
+ isFuzzerPointer := m.sanitize.getSanitizerBoolPtr(Fuzzer)
+ if isFuzzerPointer == nil || !*isFuzzerPointer {
+ return ""
+ }
+
+ return incomingVariation
+}
+
+func (f *fuzzTransitionMutator) Mutate(ctx android.BottomUpMutatorContext, variation string) {
+ m, ok := ctx.Module().(*Module)
if !ok {
return
}
- if currentModule.fuzzer == nil {
+ if m.fuzzer == nil {
return
}
- mctx.WalkDeps(func(child android.Module, parent android.Module) bool {
- c, ok := child.(*Module)
- if !ok {
- return false
- }
-
- if c.sanitize == nil {
- return false
- }
-
- isFuzzerPointer := c.sanitize.getSanitizerBoolPtr(Fuzzer)
- if isFuzzerPointer == nil || !*isFuzzerPointer {
- return false
- }
-
- if c.fuzzer == nil {
- return false
- }
-
- c.fuzzer.Properties.FuzzFramework = currentModule.fuzzer.Properties.FuzzFramework
- return true
- })
+ if variation != "" {
+ m.fuzzer.Properties.FuzzFramework = fuzz.FrameworkFromVariant(variation)
+ m.SetHideFromMake()
+ m.SetPreventInstall()
+ }
}
// cc_fuzz creates a host/device fuzzer binary. Host binaries can be found at