Rename DynamicDependerModuleContext to BaseModuleContext

DynamicDependerModuleContext is really a base module context used
by multiple types of ModuleContext interfaces.  Rename it to
BaseModuleContext, and create a new DynamicDependerModuleContext
that just wraps it.

Change-Id: Ibb402e1d680d50ed15d6548e99b32cc0b5b52b12
This commit is contained in:
Colin Cross 2014-12-18 11:05:45 -08:00
parent 573a2fd4fc
commit be1a9a10cd
2 changed files with 20 additions and 16 deletions

View file

@ -619,7 +619,7 @@ func (c *Context) moduleDepNames(info *moduleInfo,
module := c.modules[info.properties.Name] module := c.modules[info.properties.Name]
dynamicDepender, ok := module.(DynamicDependerModule) dynamicDepender, ok := module.(DynamicDependerModule)
if ok { if ok {
ddmctx := &dynamicDependerModuleContext{ ddmctx := &baseModuleContext{
context: c, context: c,
config: config, config: config,
info: info, info: info,
@ -865,7 +865,7 @@ func (c *Context) preGenerateModuleBuildActions(config interface{}) (errs []erro
if preGenerateModule, ok := module.(preGenerateModule); ok { if preGenerateModule, ok := module.(preGenerateModule); ok {
mctx := &preModuleContext{ mctx := &preModuleContext{
dynamicDependerModuleContext: dynamicDependerModuleContext{ baseModuleContext: baseModuleContext{
context: c, context: c,
config: config, config: config,
info: info, info: info,
@ -910,7 +910,7 @@ func (c *Context) generateModuleBuildActions(config interface{},
mctx := &moduleContext{ mctx := &moduleContext{
preModuleContext: preModuleContext{ preModuleContext: preModuleContext{
dynamicDependerModuleContext: dynamicDependerModuleContext{ baseModuleContext: baseModuleContext{
context: c, context: c,
config: config, config: config,
info: info, info: info,

View file

@ -86,7 +86,7 @@ type DynamicDependerModule interface {
DynamicDependencies(DynamicDependerModuleContext) []string DynamicDependencies(DynamicDependerModuleContext) []string
} }
type DynamicDependerModuleContext interface { type BaseModuleContext interface {
ModuleName() string ModuleName() string
ModuleDir() string ModuleDir() string
Config() interface{} Config() interface{}
@ -98,8 +98,12 @@ type DynamicDependerModuleContext interface {
Failed() bool Failed() bool
} }
type DynamicDependerModuleContext interface {
BaseModuleContext
}
type PreModuleContext interface { type PreModuleContext interface {
DynamicDependerModuleContext BaseModuleContext
OtherModuleName(m Module) string OtherModuleName(m Module) string
OtherModuleErrorf(m Module, fmt string, args ...interface{}) OtherModuleErrorf(m Module, fmt string, args ...interface{})
@ -118,33 +122,33 @@ type ModuleContext interface {
AddNinjaFileDeps(deps ...string) AddNinjaFileDeps(deps ...string)
} }
var _ DynamicDependerModuleContext = (*dynamicDependerModuleContext)(nil) var _ BaseModuleContext = (*baseModuleContext)(nil)
type dynamicDependerModuleContext struct { type baseModuleContext struct {
context *Context context *Context
config interface{} config interface{}
info *moduleInfo info *moduleInfo
errs []error errs []error
} }
func (d *dynamicDependerModuleContext) ModuleName() string { func (d *baseModuleContext) ModuleName() string {
return d.info.properties.Name return d.info.properties.Name
} }
func (d *dynamicDependerModuleContext) ContainsProperty(name string) bool { func (d *baseModuleContext) ContainsProperty(name string) bool {
_, ok := d.info.propertyPos[name] _, ok := d.info.propertyPos[name]
return ok return ok
} }
func (d *dynamicDependerModuleContext) ModuleDir() string { func (d *baseModuleContext) ModuleDir() string {
return filepath.Dir(d.info.relBlueprintsFile) return filepath.Dir(d.info.relBlueprintsFile)
} }
func (d *dynamicDependerModuleContext) Config() interface{} { func (d *baseModuleContext) Config() interface{} {
return d.config return d.config
} }
func (d *dynamicDependerModuleContext) Errorf(pos scanner.Position, func (d *baseModuleContext) Errorf(pos scanner.Position,
format string, args ...interface{}) { format string, args ...interface{}) {
d.errs = append(d.errs, &Error{ d.errs = append(d.errs, &Error{
@ -153,7 +157,7 @@ func (d *dynamicDependerModuleContext) Errorf(pos scanner.Position,
}) })
} }
func (d *dynamicDependerModuleContext) ModuleErrorf(format string, func (d *baseModuleContext) ModuleErrorf(format string,
args ...interface{}) { args ...interface{}) {
d.errs = append(d.errs, &Error{ d.errs = append(d.errs, &Error{
@ -162,7 +166,7 @@ func (d *dynamicDependerModuleContext) ModuleErrorf(format string,
}) })
} }
func (d *dynamicDependerModuleContext) PropertyErrorf(property, format string, func (d *baseModuleContext) PropertyErrorf(property, format string,
args ...interface{}) { args ...interface{}) {
pos, ok := d.info.propertyPos[property] pos, ok := d.info.propertyPos[property]
@ -176,14 +180,14 @@ func (d *dynamicDependerModuleContext) PropertyErrorf(property, format string,
}) })
} }
func (d *dynamicDependerModuleContext) Failed() bool { func (d *baseModuleContext) Failed() bool {
return len(d.errs) > 0 return len(d.errs) > 0
} }
var _ PreModuleContext = (*preModuleContext)(nil) var _ PreModuleContext = (*preModuleContext)(nil)
type preModuleContext struct { type preModuleContext struct {
dynamicDependerModuleContext baseModuleContext
module Module module Module
} }