Make *Context.Config return a Config instead of a interface{}

In Soong, a Config() method will always return a Config.  Make
ModuleContext, SingletonContext, TopDownMutatorContext and
BottomUpMutatorContext's Config() methods explictly return
a Config to avoid having to type-assert everywhere.  Overriding
the Config method requires duplicating the list of methods in
blueprint.BaseModuleContext and blueprint.BottomUpMutatorContext,
following the same pattern used by the other *Contexts.

Config() obsoletes the AConfig() method used in some places, which
will be cleaned up in the next patch.

Test: m checkbuild
Change-Id: Ibe21efde933959811d52443496967ab8ce71215e
This commit is contained in:
Colin Cross
2017-11-29 00:27:14 -08:00
parent 178d5fefc0
commit aabf67968c
13 changed files with 90 additions and 51 deletions

View File

@@ -29,7 +29,7 @@ import (
// Path methods.
type PathContext interface {
Fs() pathtools.FileSystem
Config() interface{}
Config() Config
AddNinjaFileDeps(deps ...string)
}
@@ -37,8 +37,8 @@ type PathGlobContext interface {
GlobWithDeps(globPattern string, excludes []string) ([]string, error)
}
var _ PathContext = blueprint.SingletonContext(nil)
var _ PathContext = blueprint.ModuleContext(nil)
var _ PathContext = SingletonContext(nil)
var _ PathContext = ModuleContext(nil)
type ModuleInstallPathContext interface {
PathContext
@@ -67,15 +67,6 @@ type moduleErrorf interface {
var _ moduleErrorf = blueprint.ModuleContext(nil)
// pathConfig returns the android Config interface associated to the context.
// Panics if the context isn't affiliated with an android build.
func pathConfig(ctx PathContext) Config {
if ret, ok := ctx.Config().(Config); ok {
return ret
}
panic("Paths may only be used on Soong builds")
}
// reportPathError will register an error with the attached context. It
// attempts ctx.ModuleErrorf for a better error message first, then falls
// back to ctx.Errorf.
@@ -197,7 +188,7 @@ type Paths []Path
// PathsForSource returns Paths rooted from SrcDir
func PathsForSource(ctx PathContext, paths []string) Paths {
if pathConfig(ctx).AllowMissingDependencies() {
if ctx.Config().AllowMissingDependencies() {
if modCtx, ok := ctx.(ModuleContext); ok {
ret := make(Paths, 0, len(paths))
intermediates := pathForModule(modCtx).withRel("missing")
@@ -476,14 +467,14 @@ var _ Path = SourcePath{}
// code that is embedding ninja variables in paths
func safePathForSource(ctx PathContext, path string) SourcePath {
p := validateSafePath(ctx, path)
ret := SourcePath{basePath{p, pathConfig(ctx), ""}}
ret := SourcePath{basePath{p, ctx.Config(), ""}}
abs, err := filepath.Abs(ret.String())
if err != nil {
reportPathError(ctx, "%s", err.Error())
return ret
}
buildroot, err := filepath.Abs(pathConfig(ctx).buildDir)
buildroot, err := filepath.Abs(ctx.Config().buildDir)
if err != nil {
reportPathError(ctx, "%s", err.Error())
return ret
@@ -501,14 +492,14 @@ func safePathForSource(ctx PathContext, path string) SourcePath {
// On error, it will return a usable, but invalid SourcePath, and report a ModuleError.
func PathForSource(ctx PathContext, pathComponents ...string) SourcePath {
p := validatePath(ctx, pathComponents...)
ret := SourcePath{basePath{p, pathConfig(ctx), ""}}
ret := SourcePath{basePath{p, ctx.Config(), ""}}
abs, err := filepath.Abs(ret.String())
if err != nil {
reportPathError(ctx, "%s", err.Error())
return ret
}
buildroot, err := filepath.Abs(pathConfig(ctx).buildDir)
buildroot, err := filepath.Abs(ctx.Config().buildDir)
if err != nil {
reportPathError(ctx, "%s", err.Error())
return ret
@@ -536,14 +527,14 @@ func ExistentPathForSource(ctx PathContext, intermediates string, pathComponents
}
p := validatePath(ctx, pathComponents...)
path := SourcePath{basePath{p, pathConfig(ctx), ""}}
path := SourcePath{basePath{p, ctx.Config(), ""}}
abs, err := filepath.Abs(path.String())
if err != nil {
reportPathError(ctx, "%s", err.Error())
return OptionalPath{}
}
buildroot, err := filepath.Abs(pathConfig(ctx).buildDir)
buildroot, err := filepath.Abs(ctx.Config().buildDir)
if err != nil {
reportPathError(ctx, "%s", err.Error())
return OptionalPath{}
@@ -652,7 +643,7 @@ var _ Path = OutputPath{}
// On error, it will return a usable, but invalid OutputPath, and report a ModuleError.
func PathForOutput(ctx PathContext, pathComponents ...string) OutputPath {
path := validatePath(ctx, pathComponents...)
return OutputPath{basePath{path, pathConfig(ctx), ""}}
return OutputPath{basePath{path, ctx.Config(), ""}}
}
func (p OutputPath) writablePath() {}
@@ -905,7 +896,7 @@ func PathForPhony(ctx PathContext, phony string) WritablePath {
if strings.ContainsAny(phony, "$/") {
reportPathError(ctx, "Phony target contains invalid character ($ or /): %s", phony)
}
return OutputPath{basePath{phony, pathConfig(ctx), ""}}
return OutputPath{basePath{phony, ctx.Config(), ""}}
}
type testPath struct {