From 37047f1c7e6062b1f51fefcb1539225dddf742d0 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 13 Dec 2016 17:06:13 -0800 Subject: [PATCH] Pass DepsContext to dependency methods Pass a DepsContext that embeds android.BottomUpMutatorContext instead of android.BaseContext so that dependency methods can directly add dependencies. Test: m -j Change-Id: Id4c157975d3d6f03efd99785d217bef486a76139 --- cc/binary.go | 2 +- cc/cc.go | 22 ++++++++++++++++------ cc/compiler.go | 2 +- cc/library.go | 2 +- cc/ndk_library.go | 2 +- cc/ndk_prebuilt.go | 4 ++-- cc/object.go | 2 +- cc/test.go | 6 +++--- cc/tidy.go | 2 +- cc/toolchain_library.go | 2 +- 10 files changed, 28 insertions(+), 18 deletions(-) diff --git a/cc/binary.go b/cc/binary.go index 7755b5fff..78883faed 100644 --- a/cc/binary.go +++ b/cc/binary.go @@ -96,7 +96,7 @@ func (binary *binaryDecorator) getStem(ctx BaseModuleContext) string { return stem + binary.Properties.Suffix } -func (binary *binaryDecorator) linkerDeps(ctx BaseModuleContext, deps Deps) Deps { +func (binary *binaryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps { deps = binary.baseLinker.linkerDeps(ctx, deps) if ctx.toolchain().Bionic() { if !Bool(binary.baseLinker.Properties.Nocrt) { diff --git a/cc/cc.go b/cc/cc.go index 3fc694fe3..74d3d3da1 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -171,16 +171,21 @@ type BaseModuleContext interface { ModuleContextIntf } +type DepsContext interface { + android.BottomUpMutatorContext + ModuleContextIntf +} + type feature interface { begin(ctx BaseModuleContext) - deps(ctx BaseModuleContext, deps Deps) Deps + deps(ctx DepsContext, deps Deps) Deps flags(ctx ModuleContext, flags Flags) Flags props() []interface{} } type compiler interface { compilerInit(ctx BaseModuleContext) - compilerDeps(ctx BaseModuleContext, deps Deps) Deps + compilerDeps(ctx DepsContext, deps Deps) Deps compilerFlags(ctx ModuleContext, flags Flags) Flags compilerProps() []interface{} @@ -191,7 +196,7 @@ type compiler interface { type linker interface { linkerInit(ctx BaseModuleContext) - linkerDeps(ctx BaseModuleContext, deps Deps) Deps + linkerDeps(ctx DepsContext, deps Deps) Deps linkerFlags(ctx ModuleContext, flags Flags) Flags linkerProps() []interface{} @@ -307,6 +312,11 @@ type baseModuleContext struct { moduleContextImpl } +type depsContext struct { + android.BottomUpMutatorContext + moduleContextImpl +} + type moduleContext struct { android.ModuleContext moduleContextImpl @@ -534,7 +544,7 @@ func (c *Module) begin(ctx BaseModuleContext) { } } -func (c *Module) deps(ctx BaseModuleContext) Deps { +func (c *Module) deps(ctx DepsContext) Deps { deps := Deps{} if c.compiler != nil { @@ -604,8 +614,8 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { return } - ctx := &baseModuleContext{ - BaseContext: actx, + ctx := &depsContext{ + BottomUpMutatorContext: actx, moduleContextImpl: moduleContextImpl{ mod: c, }, diff --git a/cc/compiler.go b/cc/compiler.go index 99f56b7b0..e6f432c67 100644 --- a/cc/compiler.go +++ b/cc/compiler.go @@ -129,7 +129,7 @@ func (compiler *baseCompiler) compilerProps() []interface{} { func (compiler *baseCompiler) compilerInit(ctx BaseModuleContext) {} -func (compiler *baseCompiler) compilerDeps(ctx BaseModuleContext, deps Deps) Deps { +func (compiler *baseCompiler) compilerDeps(ctx DepsContext, deps Deps) Deps { deps.GeneratedSources = append(deps.GeneratedSources, compiler.Properties.Generated_sources...) deps.GeneratedHeaders = append(deps.GeneratedHeaders, compiler.Properties.Generated_headers...) diff --git a/cc/library.go b/cc/library.go index 666c47ab2..8474f969d 100644 --- a/cc/library.go +++ b/cc/library.go @@ -351,7 +351,7 @@ func (library *libraryDecorator) linkerInit(ctx BaseModuleContext) { library.relocationPacker.packingInit(ctx) } -func (library *libraryDecorator) linkerDeps(ctx BaseModuleContext, deps Deps) Deps { +func (library *libraryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps { deps = library.baseLinker.linkerDeps(ctx, deps) if library.static() { diff --git a/cc/ndk_library.go b/cc/ndk_library.go index 0e4273132..afa7927ee 100644 --- a/cc/ndk_library.go +++ b/cc/ndk_library.go @@ -242,7 +242,7 @@ func (c *stubDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) O return compileObjs(ctx, flagsToBuilderFlags(flags), subdir, srcs, nil) } -func (linker *stubDecorator) linkerDeps(ctx BaseModuleContext, deps Deps) Deps { +func (linker *stubDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps { return Deps{} } diff --git a/cc/ndk_prebuilt.go b/cc/ndk_prebuilt.go index 63f892101..676d63d0d 100644 --- a/cc/ndk_prebuilt.go +++ b/cc/ndk_prebuilt.go @@ -62,7 +62,7 @@ type ndkPrebuiltObjectLinker struct { objectLinker } -func (*ndkPrebuiltObjectLinker) linkerDeps(ctx BaseModuleContext, deps Deps) Deps { +func (*ndkPrebuiltObjectLinker) linkerDeps(ctx DepsContext, deps Deps) Deps { // NDK objects can't have any dependencies return deps } @@ -96,7 +96,7 @@ func (ndk *ndkPrebuiltLibraryLinker) linkerProps() []interface{} { return append(ndk.libraryDecorator.linkerProps(), &ndk.Properties, &ndk.flagExporter.Properties) } -func (*ndkPrebuiltLibraryLinker) linkerDeps(ctx BaseModuleContext, deps Deps) Deps { +func (*ndkPrebuiltLibraryLinker) linkerDeps(ctx DepsContext, deps Deps) Deps { // NDK libraries can't have any dependencies return deps } diff --git a/cc/object.go b/cc/object.go index 16ed45518..eaddd890a 100644 --- a/cc/object.go +++ b/cc/object.go @@ -54,7 +54,7 @@ func (object *objectLinker) linkerProps() []interface{} { func (*objectLinker) linkerInit(ctx BaseModuleContext) {} -func (object *objectLinker) linkerDeps(ctx BaseModuleContext, deps Deps) Deps { +func (object *objectLinker) linkerDeps(ctx DepsContext, deps Deps) Deps { deps.ObjFiles = append(deps.ObjFiles, object.Properties.Objs...) return deps } diff --git a/cc/test.go b/cc/test.go index a2b827f5a..07eb621a6 100644 --- a/cc/test.go +++ b/cc/test.go @@ -199,7 +199,7 @@ func (test *testBinary) linkerInit(ctx BaseModuleContext) { test.binaryDecorator.linkerInit(ctx) } -func (test *testBinary) linkerDeps(ctx BaseModuleContext, deps Deps) Deps { +func (test *testBinary) linkerDeps(ctx DepsContext, deps Deps) Deps { deps = test.testDecorator.linkerDeps(ctx, deps) deps = test.binaryDecorator.linkerDeps(ctx, deps) return deps @@ -250,7 +250,7 @@ func (test *testLibrary) linkerInit(ctx BaseModuleContext) { test.libraryDecorator.linkerInit(ctx) } -func (test *testLibrary) linkerDeps(ctx BaseModuleContext, deps Deps) Deps { +func (test *testLibrary) linkerDeps(ctx DepsContext, deps Deps) Deps { deps = test.testDecorator.linkerDeps(ctx, deps) deps = test.libraryDecorator.linkerDeps(ctx, deps) return deps @@ -288,7 +288,7 @@ func (benchmark *benchmarkDecorator) linkerInit(ctx BaseModuleContext) { benchmark.binaryDecorator.linkerInit(ctx) } -func (benchmark *benchmarkDecorator) linkerDeps(ctx BaseModuleContext, deps Deps) Deps { +func (benchmark *benchmarkDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps { deps = benchmark.binaryDecorator.linkerDeps(ctx, deps) deps.StaticLibs = append(deps.StaticLibs, "libgoogle-benchmark") return deps diff --git a/cc/tidy.go b/cc/tidy.go index 2216f5873..9dcc946ac 100644 --- a/cc/tidy.go +++ b/cc/tidy.go @@ -44,7 +44,7 @@ func (tidy *tidyFeature) props() []interface{} { func (tidy *tidyFeature) begin(ctx BaseModuleContext) { } -func (tidy *tidyFeature) deps(ctx BaseModuleContext, deps Deps) Deps { +func (tidy *tidyFeature) deps(ctx DepsContext, deps Deps) Deps { return deps } diff --git a/cc/toolchain_library.go b/cc/toolchain_library.go index 6ca9dc33f..1bbe77464 100644 --- a/cc/toolchain_library.go +++ b/cc/toolchain_library.go @@ -33,7 +33,7 @@ type toolchainLibraryDecorator struct { *libraryDecorator } -func (*toolchainLibraryDecorator) linkerDeps(ctx BaseModuleContext, deps Deps) Deps { +func (*toolchainLibraryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps { // toolchain libraries can't have any dependencies return deps }