Remove moduleContextImpl struct
The moduleContextImpl structure contains duplicate information on the contexts. BaseModuleContext, ModuleContext and DepsContext can already surface which Module is being processed via Module(). Because most of the Rust-specific methods on the *Context structures simply forward to the Module methods, expose a RustModule() method. Test: cd external/rust/crates; mma Change-Id: Ifee90825d54081fc5e9a8df0b7c4580412e9158c
This commit is contained in:
68
rust/rust.go
68
rust/rust.go
@@ -506,39 +506,50 @@ type DepsContext interface {
|
||||
}
|
||||
|
||||
type ModuleContextIntf interface {
|
||||
RustModule() *Module
|
||||
toolchain() config.Toolchain
|
||||
baseModuleName() string
|
||||
CrateName() string
|
||||
nativeCoverage() bool
|
||||
}
|
||||
|
||||
type depsContext struct {
|
||||
android.BottomUpMutatorContext
|
||||
moduleContextImpl
|
||||
}
|
||||
|
||||
type moduleContext struct {
|
||||
android.ModuleContext
|
||||
moduleContextImpl
|
||||
}
|
||||
|
||||
func (ctx *moduleContextImpl) nativeCoverage() bool {
|
||||
return ctx.mod.nativeCoverage()
|
||||
type baseModuleContext struct {
|
||||
android.BaseModuleContext
|
||||
}
|
||||
|
||||
func (ctx *moduleContext) RustModule() *Module {
|
||||
return ctx.Module().(*Module)
|
||||
}
|
||||
|
||||
func (ctx *moduleContext) toolchain() config.Toolchain {
|
||||
return ctx.RustModule().toolchain(ctx)
|
||||
}
|
||||
|
||||
func (ctx *depsContext) RustModule() *Module {
|
||||
return ctx.Module().(*Module)
|
||||
}
|
||||
|
||||
func (ctx *depsContext) toolchain() config.Toolchain {
|
||||
return ctx.RustModule().toolchain(ctx)
|
||||
}
|
||||
|
||||
func (ctx *baseModuleContext) RustModule() *Module {
|
||||
return ctx.Module().(*Module)
|
||||
}
|
||||
|
||||
func (ctx *baseModuleContext) toolchain() config.Toolchain {
|
||||
return ctx.RustModule().toolchain(ctx)
|
||||
}
|
||||
|
||||
func (mod *Module) nativeCoverage() bool {
|
||||
return mod.compiler != nil && mod.compiler.nativeCoverage()
|
||||
}
|
||||
|
||||
type moduleContextImpl struct {
|
||||
mod *Module
|
||||
ctx BaseModuleContext
|
||||
}
|
||||
|
||||
func (ctx *moduleContextImpl) toolchain() config.Toolchain {
|
||||
return ctx.mod.toolchain(ctx.ctx)
|
||||
}
|
||||
|
||||
func (mod *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
|
||||
if mod.cachedToolchain == nil {
|
||||
mod.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
|
||||
@@ -552,11 +563,7 @@ func (d *Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
|
||||
ctx := &moduleContext{
|
||||
ModuleContext: actx,
|
||||
moduleContextImpl: moduleContextImpl{
|
||||
mod: mod,
|
||||
},
|
||||
}
|
||||
ctx.ctx = ctx
|
||||
|
||||
toolchain := mod.toolchain(ctx)
|
||||
|
||||
@@ -607,14 +614,6 @@ func (mod *Module) deps(ctx DepsContext) Deps {
|
||||
|
||||
}
|
||||
|
||||
func (ctx *moduleContextImpl) baseModuleName() string {
|
||||
return ctx.mod.ModuleBase.BaseModuleName()
|
||||
}
|
||||
|
||||
func (ctx *moduleContextImpl) CrateName() string {
|
||||
return ctx.mod.CrateName()
|
||||
}
|
||||
|
||||
type dependencyTag struct {
|
||||
blueprint.BaseDependencyTag
|
||||
name string
|
||||
@@ -811,11 +810,7 @@ func libNameFromFilePath(filepath android.Path) string {
|
||||
func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
|
||||
ctx := &depsContext{
|
||||
BottomUpMutatorContext: actx,
|
||||
moduleContextImpl: moduleContextImpl{
|
||||
mod: mod,
|
||||
},
|
||||
}
|
||||
ctx.ctx = ctx
|
||||
|
||||
deps := mod.deps(ctx)
|
||||
commonDepVariations := []blueprint.Variation{}
|
||||
@@ -862,19 +857,10 @@ func BeginMutator(ctx android.BottomUpMutatorContext) {
|
||||
}
|
||||
}
|
||||
|
||||
type baseModuleContext struct {
|
||||
android.BaseModuleContext
|
||||
moduleContextImpl
|
||||
}
|
||||
|
||||
func (mod *Module) beginMutator(actx android.BottomUpMutatorContext) {
|
||||
ctx := &baseModuleContext{
|
||||
BaseModuleContext: actx,
|
||||
moduleContextImpl: moduleContextImpl{
|
||||
mod: mod,
|
||||
},
|
||||
}
|
||||
ctx.ctx = ctx
|
||||
|
||||
mod.begin(ctx)
|
||||
}
|
||||
|
Reference in New Issue
Block a user