Merge "Convert trivial TopDown mutators to BottomUp" into main
This commit is contained in:
@@ -69,7 +69,7 @@ type Defaultable interface {
|
||||
|
||||
// Apply defaults from the supplied Defaults to the property structures supplied to
|
||||
// setProperties(...).
|
||||
applyDefaults(TopDownMutatorContext, []Defaults)
|
||||
applyDefaults(BottomUpMutatorContext, []Defaults)
|
||||
|
||||
// Set the hook to be called after any defaults have been applied.
|
||||
//
|
||||
@@ -210,7 +210,7 @@ func InitDefaultsModule(module DefaultsModule) {
|
||||
|
||||
var _ Defaults = (*DefaultsModuleBase)(nil)
|
||||
|
||||
func (defaultable *DefaultableModuleBase) applyDefaults(ctx TopDownMutatorContext,
|
||||
func (defaultable *DefaultableModuleBase) applyDefaults(ctx BottomUpMutatorContext,
|
||||
defaultsList []Defaults) {
|
||||
|
||||
for _, defaults := range defaultsList {
|
||||
@@ -227,7 +227,7 @@ func (defaultable *DefaultableModuleBase) applyDefaults(ctx TopDownMutatorContex
|
||||
// Product variable properties need special handling, the type of the filtered product variable
|
||||
// property struct may not be identical between the defaults module and the defaultable module.
|
||||
// Use PrependMatchingProperties to apply whichever properties match.
|
||||
func (defaultable *DefaultableModuleBase) applyDefaultVariableProperties(ctx TopDownMutatorContext,
|
||||
func (defaultable *DefaultableModuleBase) applyDefaultVariableProperties(ctx BottomUpMutatorContext,
|
||||
defaults Defaults, defaultableProp interface{}) {
|
||||
if defaultableProp == nil {
|
||||
return
|
||||
@@ -255,7 +255,7 @@ func (defaultable *DefaultableModuleBase) applyDefaultVariableProperties(ctx Top
|
||||
}
|
||||
}
|
||||
|
||||
func (defaultable *DefaultableModuleBase) applyDefaultProperties(ctx TopDownMutatorContext,
|
||||
func (defaultable *DefaultableModuleBase) applyDefaultProperties(ctx BottomUpMutatorContext,
|
||||
defaults Defaults, defaultableProp interface{}) {
|
||||
|
||||
for _, def := range defaults.properties() {
|
||||
@@ -274,7 +274,7 @@ func (defaultable *DefaultableModuleBase) applyDefaultProperties(ctx TopDownMuta
|
||||
|
||||
func RegisterDefaultsPreArchMutators(ctx RegisterMutatorsContext) {
|
||||
ctx.BottomUp("defaults_deps", defaultsDepsMutator).Parallel()
|
||||
ctx.TopDown("defaults", defaultsMutator).Parallel()
|
||||
ctx.BottomUp("defaults", defaultsMutator).Parallel()
|
||||
}
|
||||
|
||||
func defaultsDepsMutator(ctx BottomUpMutatorContext) {
|
||||
@@ -283,8 +283,12 @@ func defaultsDepsMutator(ctx BottomUpMutatorContext) {
|
||||
}
|
||||
}
|
||||
|
||||
func defaultsMutator(ctx TopDownMutatorContext) {
|
||||
func defaultsMutator(ctx BottomUpMutatorContext) {
|
||||
if defaultable, ok := ctx.Module().(Defaultable); ok {
|
||||
if _, isDefaultsModule := ctx.Module().(Defaults); isDefaultsModule {
|
||||
// Don't squash transitive defaults into defaults modules
|
||||
return
|
||||
}
|
||||
defaults := defaultable.defaults().Defaults
|
||||
if len(defaults) > 0 {
|
||||
var defaultsList []Defaults
|
||||
|
@@ -193,16 +193,16 @@ type BaseMutatorContext interface {
|
||||
// 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.
|
||||
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.
|
||||
CreateModule(ModuleFactory, ...interface{}) Module
|
||||
}
|
||||
|
||||
type TopDownMutator func(TopDownMutatorContext)
|
||||
|
||||
type TopDownMutatorContext interface {
|
||||
BaseMutatorContext
|
||||
|
||||
// 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.
|
||||
CreateModule(ModuleFactory, ...interface{}) Module
|
||||
}
|
||||
|
||||
type topDownMutatorContext struct {
|
||||
@@ -742,6 +742,14 @@ func (b *bottomUpMutatorContext) Rename(name string) {
|
||||
b.Module().base().commonProperties.DebugName = name
|
||||
}
|
||||
|
||||
func (b *bottomUpMutatorContext) createModule(factory blueprint.ModuleFactory, name string, props ...interface{}) blueprint.Module {
|
||||
return b.bp.CreateModule(factory, name, props...)
|
||||
}
|
||||
|
||||
func (b *bottomUpMutatorContext) CreateModule(factory ModuleFactory, props ...interface{}) Module {
|
||||
return createModule(b, factory, "_bottomUpMutatorModule", props...)
|
||||
}
|
||||
|
||||
func (b *bottomUpMutatorContext) AddDependency(module blueprint.Module, tag blueprint.DependencyTag, name ...string) []blueprint.Module {
|
||||
if b.baseModuleContext.checkedMissingDeps() {
|
||||
panic("Adding deps not allowed after checking for missing deps")
|
||||
|
@@ -283,7 +283,7 @@ func RegisterVisibilityRuleGatherer(ctx RegisterMutatorsContext) {
|
||||
|
||||
// This must be registered after the deps have been resolved.
|
||||
func RegisterVisibilityRuleEnforcer(ctx RegisterMutatorsContext) {
|
||||
ctx.TopDown("visibilityRuleEnforcer", visibilityRuleEnforcer).Parallel()
|
||||
ctx.BottomUp("visibilityRuleEnforcer", visibilityRuleEnforcer).Parallel()
|
||||
}
|
||||
|
||||
// Checks the per-module visibility rule lists before defaults expansion.
|
||||
@@ -507,7 +507,7 @@ func splitRule(ctx BaseModuleContext, ruleExpression string, currentPkg, propert
|
||||
return true, pkg, name
|
||||
}
|
||||
|
||||
func visibilityRuleEnforcer(ctx TopDownMutatorContext) {
|
||||
func visibilityRuleEnforcer(ctx BottomUpMutatorContext) {
|
||||
qualified := createVisibilityModuleReference(ctx.ModuleName(), ctx.ModuleDir(), ctx.Module())
|
||||
|
||||
// Visit all the dependencies making sure that this module has access to them all.
|
||||
|
Reference in New Issue
Block a user