Don't pass same argument twice for defaults modules initialization

InitDefaultsModule and InitDefaultableModule were requiring the
module to be passed in as an argument twice, once as a
android.Module and once as an android.DefaultableMOdule.  Use
a type assertion instead.

Test: builds
Change-Id: I57d721e68a4f016e02c17a678af5f2ba25a9a430
This commit is contained in:
Colin Cross 2017-07-07 14:33:33 -07:00
parent ec95f7f2f6
commit 1f44a3aa4f
2 changed files with 26 additions and 22 deletions

View File

@ -29,16 +29,16 @@ type defaultsProperties struct {
Defaults []string
}
type DefaultableModule struct {
type DefaultableModuleBase struct {
defaultsProperties defaultsProperties
defaultableProperties []interface{}
}
func (d *DefaultableModule) defaults() *defaultsProperties {
func (d *DefaultableModuleBase) defaults() *defaultsProperties {
return &d.defaultsProperties
}
func (d *DefaultableModule) setProperties(props []interface{}) {
func (d *DefaultableModuleBase) setProperties(props []interface{}) {
d.defaultableProperties = props
}
@ -48,17 +48,21 @@ type Defaultable interface {
applyDefaults(TopDownMutatorContext, []Defaults)
}
var _ Defaultable = (*DefaultableModule)(nil)
func InitDefaultableModule(module Module, d Defaultable) {
d.setProperties(module.GetProperties())
module.AddProperties(d.defaults())
type DefaultableModule interface {
Module
Defaultable
}
type DefaultsModule struct {
DefaultableModule
var _ Defaultable = (*DefaultableModuleBase)(nil)
func InitDefaultableModule(module DefaultableModule) {
module.(Defaultable).setProperties(module.(Module).GetProperties())
module.AddProperties(module.defaults())
}
type DefaultsModuleBase struct {
DefaultableModuleBase
defaultProperties []interface{}
}
@ -68,31 +72,31 @@ type Defaults interface {
properties() []interface{}
}
func (d *DefaultsModule) isDefaults() bool {
func (d *DefaultsModuleBase) isDefaults() bool {
return true
}
func (d *DefaultsModule) properties() []interface{} {
func (d *DefaultsModuleBase) properties() []interface{} {
return d.defaultableProperties
}
func InitDefaultsModule(module Module, d Defaults) {
func InitDefaultsModule(module DefaultableModule) {
module.AddProperties(
&hostAndDeviceProperties{},
&commonProperties{},
&variableProperties{})
InitArchModule(module)
InitDefaultableModule(module, d)
InitDefaultableModule(module)
module.AddProperties(&module.base().nameProperties)
module.base().module = module
}
var _ Defaults = (*DefaultsModule)(nil)
var _ Defaults = (*DefaultsModuleBase)(nil)
func (defaultable *DefaultableModule) applyDefaults(ctx TopDownMutatorContext,
func (defaultable *DefaultableModuleBase) applyDefaults(ctx TopDownMutatorContext,
defaultsList []Defaults) {
for _, defaults := range defaultsList {

View File

@ -275,7 +275,7 @@ var (
// to construct the output file. Behavior can be customized with a Customizer interface
type Module struct {
android.ModuleBase
android.DefaultableModule
android.DefaultableModuleBase
Properties BaseProperties
unused UnusedProperties
@ -339,7 +339,7 @@ func (c *Module) Init() android.Module {
android.InitAndroidArchModule(c, c.hod, c.multilib)
android.InitDefaultableModule(c, c)
android.InitDefaultableModule(c)
return c
}
@ -1138,7 +1138,7 @@ func (c *Module) HostToolPath() android.OptionalPath {
//
type Defaults struct {
android.ModuleBase
android.DefaultsModule
android.DefaultsModuleBase
}
func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
@ -1174,7 +1174,7 @@ func DefaultsFactory(props ...interface{}) android.Module {
&SAbiProperties{},
)
android.InitDefaultsModule(module, module)
android.InitDefaultsModule(module)
return module
}