Convert defaults to a top down mutator

BottomUpMutators are going to lose their ctx.Visit* functions in order
to allow parallelizing them, move defaults to a TopDownMutator using
WalkDeps to only visit defaults modules.

Test: no changes to out/soong/build.ninja
Change-Id: I54ba65a7e2ae9503f4d217f63aa9178a7c5341f0
This commit is contained in:
Colin Cross 2016-08-09 12:00:45 -07:00
parent 6debdbad42
commit 1317701114
2 changed files with 30 additions and 26 deletions

View File

@ -26,7 +26,7 @@ import (
func init() { func init() {
RegisterBottomUpMutator("defaults_deps", defaultsDepsMutator) RegisterBottomUpMutator("defaults_deps", defaultsDepsMutator)
RegisterBottomUpMutator("defaults", defaultsMutator) RegisterTopDownMutator("defaults", defaultsMutator)
RegisterBottomUpMutator("arch", ArchMutator) RegisterBottomUpMutator("arch", ArchMutator)
} }

View File

@ -45,7 +45,7 @@ func (d *DefaultableModule) setProperties(props []interface{}) {
type Defaultable interface { type Defaultable interface {
defaults() *defaultsProperties defaults() *defaultsProperties
setProperties([]interface{}) setProperties([]interface{})
applyDefaults(BottomUpMutatorContext, Defaults) applyDefaults(TopDownMutatorContext, []Defaults)
} }
var _ Defaultable = (*DefaultableModule)(nil) var _ Defaultable = (*DefaultableModule)(nil)
@ -85,18 +85,20 @@ func InitDefaultsModule(module Module, d Defaults, props ...interface{}) (bluepr
var _ Defaults = (*DefaultsModule)(nil) var _ Defaults = (*DefaultsModule)(nil)
func (defaultable *DefaultableModule) applyDefaults(ctx BottomUpMutatorContext, func (defaultable *DefaultableModule) applyDefaults(ctx TopDownMutatorContext,
defaults Defaults) { defaultsList []Defaults) {
for _, prop := range defaultable.defaultableProperties { for _, defaults := range defaultsList {
for _, def := range defaults.properties() { for _, prop := range defaultable.defaultableProperties {
if proptools.TypeEqual(prop, def) { for _, def := range defaults.properties() {
err := proptools.PrependProperties(prop, def, nil) if proptools.TypeEqual(prop, def) {
if err != nil { err := proptools.PrependProperties(prop, def, nil)
if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { if err != nil {
ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
} else { ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
panic(err) } else {
panic(err)
}
} }
} }
} }
@ -110,19 +112,21 @@ func defaultsDepsMutator(ctx BottomUpMutatorContext) {
} }
} }
func defaultsMutator(ctx BottomUpMutatorContext) { func defaultsMutator(ctx TopDownMutatorContext) {
if defaultable, ok := ctx.Module().(Defaultable); ok { if defaultable, ok := ctx.Module().(Defaultable); ok && len(defaultable.defaults().Defaults) > 0 {
for _, defaultsDep := range defaultable.defaults().Defaults { var defaultsList []Defaults
ctx.VisitDirectDeps(func(m blueprint.Module) { ctx.WalkDeps(func(module, parent blueprint.Module) bool {
if ctx.OtherModuleName(m) == defaultsDep { if ctx.OtherModuleDependencyTag(module) == DefaultsDepTag {
if defaultsModule, ok := m.(Defaults); ok { if defaults, ok := module.(Defaults); ok {
defaultable.applyDefaults(ctx, defaultsModule) defaultsList = append(defaultsList, defaults)
} else { return len(defaults.defaults().Defaults) > 0
ctx.PropertyErrorf("defaults", "module %s is not an defaults module", } else {
ctx.OtherModuleName(m)) ctx.PropertyErrorf("defaults", "module %s is not an defaults module",
} ctx.OtherModuleName(module))
} }
}) }
} return false
})
defaultable.applyDefaults(ctx, defaultsList)
} }
} }