diff options
-rw-r--r-- | android/defaults.go | 2 | ||||
-rw-r--r-- | android/mutator.go | 99 | ||||
-rw-r--r-- | android/mutator_test.go | 2 | ||||
-rw-r--r-- | android/namespace.go | 2 | ||||
-rw-r--r-- | android/namespace_test.go | 5 | ||||
-rw-r--r-- | android/override_module.go | 10 | ||||
-rw-r--r-- | android/prebuilt.go | 6 | ||||
-rw-r--r-- | android/register.go | 9 | ||||
-rw-r--r-- | apex/apex.go | 4 | ||||
-rw-r--r-- | golang/golang_test.go | 2 |
10 files changed, 116 insertions, 25 deletions
diff --git a/android/defaults.go b/android/defaults.go index 3d06c69c9..8fe28796e 100644 --- a/android/defaults.go +++ b/android/defaults.go @@ -274,7 +274,7 @@ func (defaultable *DefaultableModuleBase) applyDefaultProperties(ctx BottomUpMut func RegisterDefaultsPreArchMutators(ctx RegisterMutatorsContext) { ctx.BottomUp("defaults_deps", defaultsDepsMutator).Parallel() - ctx.BottomUp("defaults", defaultsMutator).Parallel() + ctx.BottomUp("defaults", defaultsMutator).Parallel().UsesCreateModule() } func defaultsDepsMutator(ctx BottomUpMutatorContext) { diff --git a/android/mutator.go b/android/mutator.go index ebe03a4d4..0da3ec7d0 100644 --- a/android/mutator.go +++ b/android/mutator.go @@ -221,7 +221,8 @@ type BottomUpMutatorContext interface { // Does not affect the ordering of the current mutator pass, but will be ordered // correctly for all future mutator passes. All reverse dependencies for a destination module are // collected until the end of the mutator pass, sorted by name, and then appended to the destination - // module's dependency list. + // module's dependency list. May only be called by mutators that were marked with + // UsesReverseDependencies during registration. AddReverseDependency(module blueprint.Module, tag blueprint.DependencyTag, name string) // AddVariationDependencies adds deps as dependencies of the current module, but uses the variations @@ -235,14 +236,15 @@ type BottomUpMutatorContext interface { // be ordered correctly for all future mutator passes. AddVariationDependencies(variations []blueprint.Variation, tag blueprint.DependencyTag, names ...string) []blueprint.Module - // AddReverseVariationDependencies adds a dependency from the named module to the current + // AddReverseVariationDependency adds a dependency from the named module to the current // module. The given variations will be added to the current module's varations, and then the // result will be used to find the correct variation of the depending module, which must exist. // // Does not affect the ordering of the current mutator pass, but will be ordered // correctly for all future mutator passes. All reverse dependencies for a destination module are // collected until the end of the mutator pass, sorted by name, and then appended to the destination - // module's dependency list. + // module's dependency list. May only be called by mutators that were marked with + // UsesReverseDependencies during registration. AddReverseVariationDependency([]blueprint.Variation, blueprint.DependencyTag, string) // AddFarVariationDependencies adds deps as dependencies of the current module, but uses the @@ -262,21 +264,25 @@ type BottomUpMutatorContext interface { // ReplaceDependencies finds all the variants of the module with the specified name, then // replaces all dependencies onto those variants with the current variant of this module. - // Replacements don't take effect until after the mutator pass is finished. + // Replacements don't take effect until after the mutator pass is finished. May only + // be called by mutators that were marked with UsesReplaceDependencies during registration. ReplaceDependencies(string) // ReplaceDependenciesIf finds all the variants of the module with the specified name, then // replaces all dependencies onto those variants with the current variant of this module // as long as the supplied predicate returns true. - // Replacements don't take effect until after the mutator pass is finished. + // Replacements don't take effect until after the mutator pass is finished. May only + // be called by mutators that were marked with UsesReplaceDependencies during registration. ReplaceDependenciesIf(string, blueprint.ReplaceDependencyPredicate) // Rename all variants of a module. The new name is not visible to calls to ModuleName, - // AddDependency or OtherModuleName until after this mutator pass is complete. + // AddDependency or OtherModuleName until after this mutator pass is complete. May only be called + // by mutators that were marked with UsesRename during registration. Rename(name string) // CreateModule creates a new module by calling the factory method for the specified moduleType, and applies - // the specified property structs to it as if the properties were set in a blueprint file. + // the specified property structs to it as if the properties were set in a blueprint file. May only + // be called by mutators that were marked with UsesCreateModule during registration. CreateModule(ModuleFactory, ...interface{}) Module } @@ -620,13 +626,60 @@ func (mutator *mutator) register(ctx *Context) { } else if mutator.transitionMutator != nil { blueprintCtx.RegisterTransitionMutator(mutator.name, mutator.transitionMutator) } + + // Forward booleans set on the MutatorHandle to the blueprint.MutatorHandle. if mutator.parallel { handle.Parallel() } + if mutator.usesRename { + handle.UsesRename() + } + if mutator.usesReverseDependencies { + handle.UsesReverseDependencies() + } + if mutator.usesReplaceDependencies { + handle.UsesReplaceDependencies() + } + if mutator.usesCreateModule { + handle.UsesCreateModule() + } + if mutator.mutatesDependencies { + handle.MutatesDependencies() + } + if mutator.mutatesGlobalState { + handle.MutatesGlobalState() + } } type MutatorHandle interface { + // Parallel sets the mutator to visit modules in parallel while maintaining ordering. Calling any + // method on the mutator context is thread-safe, but the mutator must handle synchronization + // for any modifications to global state or any modules outside the one it was invoked on. Parallel() MutatorHandle + + // UsesRename marks the mutator as using the BottomUpMutatorContext.Rename method, which prevents + // coalescing adjacent mutators into a single mutator pass. + UsesRename() MutatorHandle + + // UsesReverseDependencies marks the mutator as using the BottomUpMutatorContext.AddReverseDependency + // method, which prevents coalescing adjacent mutators into a single mutator pass. + UsesReverseDependencies() MutatorHandle + + // UsesReplaceDependencies marks the mutator as using the BottomUpMutatorContext.ReplaceDependencies + // method, which prevents coalescing adjacent mutators into a single mutator pass. + UsesReplaceDependencies() MutatorHandle + + // UsesCreateModule marks the mutator as using the BottomUpMutatorContext.CreateModule method, + // which prevents coalescing adjacent mutators into a single mutator pass. + UsesCreateModule() MutatorHandle + + // MutatesDependencies marks the mutator as modifying properties in dependencies, which prevents + // coalescing adjacent mutators into a single mutator pass. + MutatesDependencies() MutatorHandle + + // MutatesGlobalState marks the mutator as modifying global state, which prevents coalescing + // adjacent mutators into a single mutator pass. + MutatesGlobalState() MutatorHandle } func (mutator *mutator) Parallel() MutatorHandle { @@ -634,6 +687,36 @@ func (mutator *mutator) Parallel() MutatorHandle { return mutator } +func (mutator *mutator) UsesRename() MutatorHandle { + mutator.usesRename = true + return mutator +} + +func (mutator *mutator) UsesReverseDependencies() MutatorHandle { + mutator.usesReverseDependencies = true + return mutator +} + +func (mutator *mutator) UsesReplaceDependencies() MutatorHandle { + mutator.usesReplaceDependencies = true + return mutator +} + +func (mutator *mutator) UsesCreateModule() MutatorHandle { + mutator.usesCreateModule = true + return mutator +} + +func (mutator *mutator) MutatesDependencies() MutatorHandle { + mutator.mutatesDependencies = true + return mutator +} + +func (mutator *mutator) MutatesGlobalState() MutatorHandle { + mutator.mutatesGlobalState = true + return mutator +} + func RegisterComponentsMutator(ctx RegisterMutatorsContext) { ctx.BottomUp("component-deps", componentDepsMutator).Parallel() } @@ -653,7 +736,7 @@ func depsMutator(ctx BottomUpMutatorContext) { } func registerDepsMutator(ctx RegisterMutatorsContext) { - ctx.BottomUp("deps", depsMutator).Parallel() + ctx.BottomUp("deps", depsMutator).Parallel().UsesReverseDependencies() } // android.topDownMutatorContext either has to embed blueprint.TopDownMutatorContext, in which case every method that diff --git a/android/mutator_test.go b/android/mutator_test.go index 88bf1d2ea..33fca9e8b 100644 --- a/android/mutator_test.go +++ b/android/mutator_test.go @@ -158,7 +158,7 @@ func TestModuleString(t *testing.T) { ctx.BottomUp("rename_bottom_up", func(ctx BottomUpMutatorContext) { moduleStrings = append(moduleStrings, ctx.Module().String()) ctx.Rename(ctx.Module().base().Name() + "_renamed1") - }) + }).UsesRename() ctx.BottomUp("final", func(ctx BottomUpMutatorContext) { moduleStrings = append(moduleStrings, ctx.Module().String()) }) diff --git a/android/namespace.go b/android/namespace.go index ebf85a1fd..866d12594 100644 --- a/android/namespace.go +++ b/android/namespace.go @@ -457,7 +457,7 @@ func NamespaceFactory() Module { } func RegisterNamespaceMutator(ctx RegisterMutatorsContext) { - ctx.BottomUp("namespace_deps", namespaceMutator).Parallel() + ctx.BottomUp("namespace_deps", namespaceMutator).Parallel().MutatesGlobalState() } func namespaceMutator(ctx BottomUpMutatorContext) { diff --git a/android/namespace_test.go b/android/namespace_test.go index ea51c6eae..0327e7824 100644 --- a/android/namespace_test.go +++ b/android/namespace_test.go @@ -646,7 +646,7 @@ var prepareForTestWithNamespace = GroupFixturePreparers( ctx.RegisterModuleType("test_module", newTestModule) ctx.Context.RegisterModuleType("blueprint_test_module", newBlueprintTestModule) ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) { - ctx.BottomUp("rename", renameMutator) + ctx.BottomUp("rename", renameMutator).UsesRename() }) }), ) @@ -709,9 +709,6 @@ type testModule struct { } func (m *testModule) DepsMutator(ctx BottomUpMutatorContext) { - if m.properties.Rename != "" { - ctx.Rename(m.properties.Rename) - } for _, d := range m.properties.Deps { ctx.AddDependency(ctx.Module(), nil, d) } diff --git a/android/override_module.go b/android/override_module.go index f69f96309..d844da616 100644 --- a/android/override_module.go +++ b/android/override_module.go @@ -234,8 +234,9 @@ func (b *OverridableModuleBase) OverridablePropertiesDepsMutator(ctx BottomUpMut // Mutators for override/overridable modules. All the fun happens in these functions. It is critical // to keep them in this order and not put any order mutators between them. func RegisterOverridePostDepsMutators(ctx RegisterMutatorsContext) { - ctx.BottomUp("override_deps", overrideModuleDepsMutator).Parallel() + ctx.BottomUp("override_deps", overrideModuleDepsMutator).Parallel().MutatesDependencies() // modifies deps via addOverride ctx.Transition("override", &overrideTransitionMutator{}) + ctx.BottomUp("override_apply", overrideApplyMutator).Parallel().MutatesDependencies() // overridableModuleDepsMutator calls OverridablePropertiesDepsMutator so that overridable modules can // add deps from overridable properties. ctx.BottomUp("overridable_deps", overridableModuleDepsMutator).Parallel() @@ -243,8 +244,8 @@ func RegisterOverridePostDepsMutators(ctx RegisterMutatorsContext) { // prebuilt's ReplaceDependencies doesn't affect to those deps added by overridable properties. // By running PrebuiltPostDepsMutator again after overridableModuleDepsMutator, deps via overridable properties // can be replaced with prebuilts. - ctx.BottomUp("replace_deps_on_prebuilts_for_overridable_deps_again", PrebuiltPostDepsMutator).Parallel() - ctx.BottomUp("replace_deps_on_override", replaceDepsOnOverridingModuleMutator).Parallel() + ctx.BottomUp("replace_deps_on_prebuilts_for_overridable_deps_again", PrebuiltPostDepsMutator).Parallel().UsesReplaceDependencies() + ctx.BottomUp("replace_deps_on_override", replaceDepsOnOverridingModuleMutator).Parallel().UsesReplaceDependencies() } type overrideBaseDependencyTag struct { @@ -330,6 +331,9 @@ func (overrideTransitionMutator) IncomingTransition(ctx IncomingTransitionContex } func (overrideTransitionMutator) Mutate(ctx BottomUpMutatorContext, variation string) { +} + +func overrideApplyMutator(ctx BottomUpMutatorContext) { if o, ok := ctx.Module().(OverrideModule); ok { overridableDeps := ctx.GetDirectDepsWithTag(overrideBaseDepTag) if len(overridableDeps) > 1 { diff --git a/android/prebuilt.go b/android/prebuilt.go index e5d06dded..017ba76c3 100644 --- a/android/prebuilt.go +++ b/android/prebuilt.go @@ -400,13 +400,13 @@ func PrebuiltGetPreferred(ctx BaseModuleContext, module Module) Module { } func RegisterPrebuiltsPreArchMutators(ctx RegisterMutatorsContext) { - ctx.BottomUp("prebuilt_rename", PrebuiltRenameMutator).Parallel() + ctx.BottomUp("prebuilt_rename", PrebuiltRenameMutator).Parallel().UsesRename() } func RegisterPrebuiltsPostDepsMutators(ctx RegisterMutatorsContext) { - ctx.BottomUp("prebuilt_source", PrebuiltSourceDepsMutator).Parallel() + ctx.BottomUp("prebuilt_source", PrebuiltSourceDepsMutator).Parallel().UsesReverseDependencies() ctx.BottomUp("prebuilt_select", PrebuiltSelectModuleMutator).Parallel() - ctx.BottomUp("prebuilt_postdeps", PrebuiltPostDepsMutator).Parallel() + ctx.BottomUp("prebuilt_postdeps", PrebuiltPostDepsMutator).Parallel().UsesReplaceDependencies() } // Returns the name of the source module corresponding to a prebuilt module diff --git a/android/register.go b/android/register.go index 2ce602580..94d875d19 100644 --- a/android/register.go +++ b/android/register.go @@ -91,7 +91,14 @@ type mutator struct { bottomUpMutator blueprint.BottomUpMutator topDownMutator blueprint.TopDownMutator transitionMutator blueprint.TransitionMutator - parallel bool + + parallel bool + usesRename bool + usesReverseDependencies bool + usesReplaceDependencies bool + usesCreateModule bool + mutatesDependencies bool + mutatesGlobalState bool } var _ sortableComponent = &mutator{} diff --git a/apex/apex.go b/apex/apex.go index b53cb0f9f..6bb2a1a5b 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -55,7 +55,7 @@ func registerApexBuildComponents(ctx android.RegistrationContext) { } func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) { - ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel() + ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel().UsesReverseDependencies() } func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) { @@ -67,7 +67,7 @@ func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) { // it should create a platform variant. ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel() ctx.Transition("apex", &apexTransitionMutator{}) - ctx.BottomUp("apex_directly_in_any", apexDirectlyInAnyMutator).Parallel() + ctx.BottomUp("apex_directly_in_any", apexDirectlyInAnyMutator).Parallel().MutatesDependencies() ctx.BottomUp("apex_dcla_deps", apexDCLADepsMutator).Parallel() } diff --git a/golang/golang_test.go b/golang/golang_test.go index b51214402..b909f5948 100644 --- a/golang/golang_test.go +++ b/golang/golang_test.go @@ -39,7 +39,7 @@ func TestGolang(t *testing.T) { android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) { RegisterGoModuleTypes(ctx) ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { - ctx.BottomUpBlueprint("bootstrap_deps", bootstrap.BootstrapDeps) + ctx.BottomUpBlueprint("bootstrap_deps", bootstrap.BootstrapDeps).UsesReverseDependencies() }) }), ).RunTestWithBp(t, bp) |