Merge "Allow defaults modules to have defaults"

This commit is contained in:
Colin Cross
2016-07-27 23:20:05 +00:00
committed by Gerrit Code Review
2 changed files with 8 additions and 13 deletions

View File

@@ -26,7 +26,7 @@ import (
func init() { func init() {
RegisterBottomUpMutator("defaults_deps", defaultsDepsMutator) RegisterBottomUpMutator("defaults_deps", defaultsDepsMutator)
RegisterTopDownMutator("defaults", defaultsMutator) RegisterBottomUpMutator("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(TopDownMutatorContext, Defaults) applyDefaults(BottomUpMutatorContext, Defaults)
} }
var _ Defaultable = (*DefaultableModule)(nil) var _ Defaultable = (*DefaultableModule)(nil)
@@ -61,12 +61,13 @@ func InitDefaultableModule(module Module, d Defaultable,
} }
type DefaultsModule struct { type DefaultsModule struct {
DefaultableModule
defaultProperties []interface{} defaultProperties []interface{}
} }
type Defaults interface { type Defaults interface {
Defaultable
isDefaults() bool isDefaults() bool
setProperties([]interface{})
properties() []interface{} properties() []interface{}
} }
@@ -75,22 +76,16 @@ func (d *DefaultsModule) isDefaults() bool {
} }
func (d *DefaultsModule) properties() []interface{} { func (d *DefaultsModule) properties() []interface{} {
return d.defaultProperties return d.defaultableProperties
}
func (d *DefaultsModule) setProperties(props []interface{}) {
d.defaultProperties = props
} }
func InitDefaultsModule(module Module, d Defaults, props ...interface{}) (blueprint.Module, []interface{}) { func InitDefaultsModule(module Module, d Defaults, props ...interface{}) (blueprint.Module, []interface{}) {
d.setProperties(props) return InitDefaultableModule(module, d, props...)
return module, props
} }
var _ Defaults = (*DefaultsModule)(nil) var _ Defaults = (*DefaultsModule)(nil)
func (defaultable *DefaultableModule) applyDefaults(ctx TopDownMutatorContext, func (defaultable *DefaultableModule) applyDefaults(ctx BottomUpMutatorContext,
defaults Defaults) { defaults Defaults) {
for _, prop := range defaultable.defaultableProperties { 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 { if defaultable, ok := ctx.Module().(Defaultable); ok {
for _, defaultsDep := range defaultable.defaults().Defaults { for _, defaultsDep := range defaultable.defaults().Defaults {
ctx.VisitDirectDeps(func(m blueprint.Module) { ctx.VisitDirectDeps(func(m blueprint.Module) {