From e7b07137d4422c421e3e9c9bb4d6859d637fc3e1 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Wed, 27 Jul 2016 10:15:06 -0700 Subject: [PATCH] Allow defaults modules to have defaults Allow chaining defaults modules by making Defaults be a Defaultable. Change-Id: I4ba86c07f7aad9c396ed33d55fe95d1fb78e487d --- android/arch.go | 2 +- android/defaults.go | 19 +++++++------------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/android/arch.go b/android/arch.go index 13fcb2987..d6b28363b 100644 --- a/android/arch.go +++ b/android/arch.go @@ -26,7 +26,7 @@ import ( func init() { RegisterBottomUpMutator("defaults_deps", defaultsDepsMutator) - RegisterTopDownMutator("defaults", defaultsMutator) + RegisterBottomUpMutator("defaults", defaultsMutator) RegisterBottomUpMutator("arch", ArchMutator) } diff --git a/android/defaults.go b/android/defaults.go index f9cf0cc8d..2c589b92a 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(TopDownMutatorContext, Defaults) + applyDefaults(BottomUpMutatorContext, Defaults) } var _ Defaultable = (*DefaultableModule)(nil) @@ -61,12 +61,13 @@ func InitDefaultableModule(module Module, d Defaultable, } type DefaultsModule struct { + DefaultableModule defaultProperties []interface{} } type Defaults interface { + Defaultable isDefaults() bool - setProperties([]interface{}) properties() []interface{} } @@ -75,22 +76,16 @@ func (d *DefaultsModule) isDefaults() bool { } func (d *DefaultsModule) properties() []interface{} { - return d.defaultProperties -} - -func (d *DefaultsModule) setProperties(props []interface{}) { - d.defaultProperties = props + return d.defaultableProperties } func InitDefaultsModule(module Module, d Defaults, props ...interface{}) (blueprint.Module, []interface{}) { - d.setProperties(props) - - return module, props + return InitDefaultableModule(module, d, props...) } var _ Defaults = (*DefaultsModule)(nil) -func (defaultable *DefaultableModule) applyDefaults(ctx TopDownMutatorContext, +func (defaultable *DefaultableModule) applyDefaults(ctx BottomUpMutatorContext, defaults Defaults) { for _, prop := range defaultable.defaultableProperties { @@ -115,7 +110,7 @@ func defaultsDepsMutator(ctx BottomUpMutatorContext) { } } -func defaultsMutator(ctx TopDownMutatorContext) { +func defaultsMutator(ctx BottomUpMutatorContext) { if defaultable, ok := ctx.Module().(Defaultable); ok { for _, defaultsDep := range defaultable.defaults().Defaults { ctx.VisitDirectDeps(func(m blueprint.Module) {