From 1317701114ee164d244ceefdfd42a12cd417ae33 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 9 Aug 2016 12:00:45 -0700 Subject: [PATCH] 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 --- android/arch.go | 2 +- android/defaults.go | 54 ++++++++++++++++++++++++--------------------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/android/arch.go b/android/arch.go index fde106d82..c767bd708 100644 --- a/android/arch.go +++ b/android/arch.go @@ -26,7 +26,7 @@ import ( func init() { RegisterBottomUpMutator("defaults_deps", defaultsDepsMutator) - RegisterBottomUpMutator("defaults", defaultsMutator) + RegisterTopDownMutator("defaults", defaultsMutator) RegisterBottomUpMutator("arch", ArchMutator) } diff --git a/android/defaults.go b/android/defaults.go index 2c589b92a..11ce09976 100644 --- a/android/defaults.go +++ b/android/defaults.go @@ -45,7 +45,7 @@ func (d *DefaultableModule) setProperties(props []interface{}) { type Defaultable interface { defaults() *defaultsProperties setProperties([]interface{}) - applyDefaults(BottomUpMutatorContext, Defaults) + applyDefaults(TopDownMutatorContext, []Defaults) } var _ Defaultable = (*DefaultableModule)(nil) @@ -85,18 +85,20 @@ func InitDefaultsModule(module Module, d Defaults, props ...interface{}) (bluepr var _ Defaults = (*DefaultsModule)(nil) -func (defaultable *DefaultableModule) applyDefaults(ctx BottomUpMutatorContext, - defaults Defaults) { +func (defaultable *DefaultableModule) applyDefaults(ctx TopDownMutatorContext, + defaultsList []Defaults) { - for _, prop := range defaultable.defaultableProperties { - for _, def := range defaults.properties() { - if proptools.TypeEqual(prop, def) { - err := proptools.PrependProperties(prop, def, nil) - if err != nil { - if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { - ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) - } else { - panic(err) + for _, defaults := range defaultsList { + for _, prop := range defaultable.defaultableProperties { + for _, def := range defaults.properties() { + if proptools.TypeEqual(prop, def) { + err := proptools.PrependProperties(prop, def, nil) + if err != nil { + if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { + ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) + } else { + panic(err) + } } } } @@ -110,19 +112,21 @@ func defaultsDepsMutator(ctx BottomUpMutatorContext) { } } -func defaultsMutator(ctx BottomUpMutatorContext) { - if defaultable, ok := ctx.Module().(Defaultable); ok { - for _, defaultsDep := range defaultable.defaults().Defaults { - ctx.VisitDirectDeps(func(m blueprint.Module) { - if ctx.OtherModuleName(m) == defaultsDep { - if defaultsModule, ok := m.(Defaults); ok { - defaultable.applyDefaults(ctx, defaultsModule) - } else { - ctx.PropertyErrorf("defaults", "module %s is not an defaults module", - ctx.OtherModuleName(m)) - } +func defaultsMutator(ctx TopDownMutatorContext) { + if defaultable, ok := ctx.Module().(Defaultable); ok && len(defaultable.defaults().Defaults) > 0 { + var defaultsList []Defaults + ctx.WalkDeps(func(module, parent blueprint.Module) bool { + if ctx.OtherModuleDependencyTag(module) == DefaultsDepTag { + if defaults, ok := module.(Defaults); ok { + defaultsList = append(defaultsList, defaults) + return len(defaults.defaults().Defaults) > 0 + } else { + ctx.PropertyErrorf("defaults", "module %s is not an defaults module", + ctx.OtherModuleName(module)) } - }) - } + } + return false + }) + defaultable.applyDefaults(ctx, defaultsList) } }