Refactor cc modules to use decorators instead of inheritance
For example , instead of trying to have libraryLinker inherit from
baseLinker and libraryCompiler inherit from baseCompiler, create a
single decorator object that wraps both baseLinker and baseCompiler.
Test: Builds, no unexpected changes to build.ninja
Change-Id: I2468adaea8466c203a240259ba5694b8b1df7a52
diff --git a/cc/linker.go b/cc/linker.go
index 9767755..df19de7 100644
--- a/cc/linker.go
+++ b/cc/linker.go
@@ -14,6 +14,11 @@
package cc
+import (
+ "android/soong/android"
+ "fmt"
+)
+
// This file contains the basic functionality for linking against static libraries and shared
// libraries. Final linking into libraries or executables is handled in library.go, binary.go, etc.
@@ -67,14 +72,15 @@
Nocrt *bool `android:"arch_variant"`
}
+func NewBaseLinker() *baseLinker {
+ return &baseLinker{}
+}
+
// baseLinker provides support for shared_libs, static_libs, and whole_static_libs properties
type baseLinker struct {
Properties BaseLinkerProperties
dynamicProperties struct {
- VariantIsShared bool `blueprint:"mutated"`
- VariantIsStatic bool `blueprint:"mutated"`
- VariantIsStaticBinary bool `blueprint:"mutated"`
- RunPaths []string `blueprint:"mutated"`
+ RunPaths []string `blueprint:"mutated"`
}
}
@@ -84,9 +90,9 @@
func (linker *baseLinker) linkerInit(ctx BaseModuleContext) {
if ctx.toolchain().Is64Bit() {
- linker.dynamicProperties.RunPaths = []string{"../lib64", "lib64"}
+ linker.dynamicProperties.RunPaths = append(linker.dynamicProperties.RunPaths, "../lib64", "lib64")
} else {
- linker.dynamicProperties.RunPaths = []string{"../lib", "lib"}
+ linker.dynamicProperties.RunPaths = append(linker.dynamicProperties.RunPaths, "../lib", "lib")
}
}
@@ -113,7 +119,7 @@
deps.LateStaticLibs = append(deps.LateStaticLibs, "libgcc")
}
- if !linker.static() {
+ if !ctx.static() {
if linker.Properties.System_shared_libs != nil {
deps.LateSharedLibs = append(deps.LateSharedLibs,
linker.Properties.System_shared_libs...)
@@ -158,7 +164,7 @@
flags.LdFlags = append(flags.LdFlags, linker.Properties.Ldflags...)
- if ctx.Host() && !linker.static() {
+ if ctx.Host() {
rpath_prefix := `\$$ORIGIN/`
if ctx.Darwin() {
rpath_prefix = "@loader_path/"
@@ -178,37 +184,7 @@
return flags
}
-func (linker *baseLinker) static() bool {
- return linker.dynamicProperties.VariantIsStatic
-}
-
-func (linker *baseLinker) staticBinary() bool {
- return linker.dynamicProperties.VariantIsStaticBinary
-}
-
-func (linker *baseLinker) setStatic(static bool) {
- linker.dynamicProperties.VariantIsStatic = static
-}
-
-func (linker *baseLinker) isDependencyRoot() bool {
- return false
-}
-
-type baseLinkerInterface interface {
- // Returns true if the build options for the module have selected a static or shared build
- buildStatic() bool
- buildShared() bool
-
- // Sets whether a specific variant is static or shared
- setStatic(bool)
-
- // Returns whether a specific variant is a static library or binary
- static() bool
-
- // Returns whether a module is a static binary
- staticBinary() bool
-
- // Returns true for dependency roots (binaries)
- // TODO(ccross): also handle dlopenable libraries
- isDependencyRoot() bool
+func (linker *baseLinker) link(ctx ModuleContext,
+ flags Flags, deps PathDeps, objFiles android.Paths) android.Path {
+ panic(fmt.Errorf("baseLinker doesn't know how to link"))
}