aboutsummaryrefslogtreecommitdiffstats
path: root/cc/ndk_prebuilt.go
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2016-07-29 17:28:03 -0700
committerColin Cross <ccross@android.com>2016-08-05 10:25:09 -0700
commitb916a38233e6862ec74dd840038ae224f6fde1c7 (patch)
treec830af79126bf82b750bad58bd9808a638607da8 /cc/ndk_prebuilt.go
parent01344df46ee1744dd1ff7815705564deb43ac7cb (diff)
downloadbuild_soong-b916a38233e6862ec74dd840038ae224f6fde1c7.tar.gz
build_soong-b916a38233e6862ec74dd840038ae224f6fde1c7.tar.bz2
build_soong-b916a38233e6862ec74dd840038ae224f6fde1c7.zip
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
Diffstat (limited to 'cc/ndk_prebuilt.go')
-rw-r--r--cc/ndk_prebuilt.go84
1 files changed, 31 insertions, 53 deletions
diff --git a/cc/ndk_prebuilt.go b/cc/ndk_prebuilt.go
index 2b24507e..407a026a 100644
--- a/cc/ndk_prebuilt.go
+++ b/cc/ndk_prebuilt.go
@@ -70,7 +70,11 @@ func (*ndkPrebuiltObjectLinker) linkerDeps(ctx BaseModuleContext, deps Deps) Dep
func ndkPrebuiltObjectFactory() (blueprint.Module, []interface{}) {
module := newBaseModule(android.DeviceSupported, android.MultilibBoth)
- module.linker = &ndkPrebuiltObjectLinker{}
+ module.linker = &ndkPrebuiltObjectLinker{
+ objectLinker: objectLinker{
+ baseLinker: NewBaseLinker(),
+ },
+ }
module.Properties.HideFromMake = true
return module.Init()
}
@@ -86,14 +90,11 @@ func (c *ndkPrebuiltObjectLinker) link(ctx ModuleContext, flags Flags,
}
type ndkPrebuiltLibraryLinker struct {
- libraryLinker
+ *libraryDecorator
}
-var _ baseLinkerInterface = (*ndkPrebuiltLibraryLinker)(nil)
-var _ exportedFlagsProducer = (*libraryLinker)(nil)
-
func (ndk *ndkPrebuiltLibraryLinker) linkerProps() []interface{} {
- return append(ndk.libraryLinker.linkerProps(), &ndk.Properties, &ndk.flagExporter.Properties)
+ return append(ndk.libraryDecorator.linkerProps(), &ndk.Properties, &ndk.flagExporter.Properties)
}
func (*ndkPrebuiltLibraryLinker) linkerDeps(ctx BaseModuleContext, deps Deps) Deps {
@@ -102,10 +103,14 @@ func (*ndkPrebuiltLibraryLinker) linkerDeps(ctx BaseModuleContext, deps Deps) De
}
func ndkPrebuiltLibraryFactory() (blueprint.Module, []interface{}) {
- module := newBaseModule(android.DeviceSupported, android.MultilibBoth)
- linker := &ndkPrebuiltLibraryLinker{}
- linker.dynamicProperties.BuildShared = true
+ module, library := NewLibrary(android.DeviceSupported, true, false)
+ linker := &ndkPrebuiltLibraryLinker{
+ libraryDecorator: library,
+ }
+ module.compiler = nil
module.linker = linker
+ module.installer = nil
+ module.stl = nil
module.Properties.HideFromMake = true
return module.Init()
}
@@ -128,19 +133,29 @@ type ndkPrebuiltStlLinker struct {
}
func ndkPrebuiltSharedStlFactory() (blueprint.Module, []interface{}) {
- module := newBaseModule(android.DeviceSupported, android.MultilibBoth)
- linker := &ndkPrebuiltStlLinker{}
- linker.dynamicProperties.BuildShared = true
+ module, library := NewLibrary(android.DeviceSupported, true, false)
+ linker := &ndkPrebuiltStlLinker{
+ ndkPrebuiltLibraryLinker: ndkPrebuiltLibraryLinker{
+ libraryDecorator: library,
+ },
+ }
+ module.compiler = nil
module.linker = linker
+ module.installer = nil
module.Properties.HideFromMake = true
return module.Init()
}
func ndkPrebuiltStaticStlFactory() (blueprint.Module, []interface{}) {
- module := newBaseModule(android.DeviceSupported, android.MultilibBoth)
- linker := &ndkPrebuiltStlLinker{}
- linker.dynamicProperties.BuildStatic = true
+ module, library := NewLibrary(android.DeviceSupported, false, true)
+ linker := &ndkPrebuiltStlLinker{
+ ndkPrebuiltLibraryLinker: ndkPrebuiltLibraryLinker{
+ libraryDecorator: library,
+ },
+ }
+ module.compiler = nil
module.linker = linker
+ module.installer = nil
module.Properties.HideFromMake = true
return module.Init()
}
@@ -177,7 +192,7 @@ func (ndk *ndkPrebuiltStlLinker) link(ctx ModuleContext, flags Flags,
libName := strings.TrimPrefix(ctx.ModuleName(), "ndk_")
libExt := flags.Toolchain.ShlibSuffix()
- if ndk.dynamicProperties.BuildStatic {
+ if ndk.Properties.BuildStatic {
libExt = staticLibraryExtension
}
@@ -186,40 +201,3 @@ func (ndk *ndkPrebuiltStlLinker) link(ctx ModuleContext, flags Flags,
libDir := getNdkStlLibDir(ctx, flags.Toolchain, stlName)
return libDir.Join(ctx, libName+libExt)
}
-
-func linkageMutator(mctx android.BottomUpMutatorContext) {
- if m, ok := mctx.Module().(*Module); ok {
- if m.linker != nil {
- if linker, ok := m.linker.(baseLinkerInterface); ok {
- var modules []blueprint.Module
- if linker.buildStatic() && linker.buildShared() {
- modules = mctx.CreateLocalVariations("static", "shared")
- static := modules[0].(*Module)
- shared := modules[1].(*Module)
-
- static.linker.(baseLinkerInterface).setStatic(true)
- shared.linker.(baseLinkerInterface).setStatic(false)
-
- if staticCompiler, ok := static.compiler.(*libraryCompiler); ok {
- sharedCompiler := shared.compiler.(*libraryCompiler)
- if len(staticCompiler.Properties.Static.Cflags) == 0 &&
- len(sharedCompiler.Properties.Shared.Cflags) == 0 {
- // Optimize out compiling common .o files twice for static+shared libraries
- mctx.AddInterVariantDependency(reuseObjTag, shared, static)
- sharedCompiler.baseCompiler.Properties.Srcs = nil
- sharedCompiler.baseCompiler.Properties.Generated_sources = nil
- }
- }
- } else if linker.buildStatic() {
- modules = mctx.CreateLocalVariations("static")
- modules[0].(*Module).linker.(baseLinkerInterface).setStatic(true)
- } else if linker.buildShared() {
- modules = mctx.CreateLocalVariations("shared")
- modules[0].(*Module).linker.(baseLinkerInterface).setStatic(false)
- } else {
- panic(fmt.Errorf("library %q not static or shared", mctx.ModuleName()))
- }
- }
- }
- }
-}