aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2016-04-05 16:42:05 -0700
committerColin Cross <ccross@android.com>2016-04-21 16:35:03 -0700
commit919281aa918222fa2181c8dd19a2d2225f292180 (patch)
tree7ef02b2f18a978f06b147f349ced95b951ed9499
parentf7f3d69cf58cdb0bb15ea0b376a6e0381e971905 (diff)
downloadbuild_soong-919281aa918222fa2181c8dd19a2d2225f292180.tar.gz
build_soong-919281aa918222fa2181c8dd19a2d2225f292180.tar.bz2
build_soong-919281aa918222fa2181c8dd19a2d2225f292180.zip
Refactor out exported cflags
Exported cflags are needed by a variety of cc module types. Refactor them into an object that can be composed into any cc module type. Change-Id: I7427ba71085917ca3ec522abadfa2bf33ab43440
-rw-r--r--cc/cc.go69
1 files changed, 42 insertions, 27 deletions
diff --git a/cc/cc.go b/cc/cc.go
index 8910ce74..417dc0d0 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -341,6 +341,12 @@ type LibraryCompilerProperties struct {
} `android:"arch_variant"`
}
+type FlagExporterProperties struct {
+ // list of directories relative to the Blueprints file that will
+ // be added to the include path using -I for any module that links against this module
+ Export_include_dirs []string `android:"arch_variant"`
+}
+
type LibraryLinkerProperties struct {
Static struct {
Whole_static_libs []string `android:"arch_variant"`
@@ -362,10 +368,6 @@ type LibraryLinkerProperties struct {
// local file name to pass to the linker as -force_symbols_weak_list
Force_symbols_weak_list *string `android:"arch_variant"`
- // list of directories relative to the Blueprints file that will
- // be added to the include path using -I for any module that links against this module
- Export_include_dirs []string `android:"arch_variant"`
-
// don't link in crt_begin and crt_end. This flag should only be necessary for
// compiling crt or libc.
Nocrt *bool `android:"arch_variant"`
@@ -1271,10 +1273,6 @@ type baseLinkerInterface interface {
staticBinary() bool
}
-type exportedFlagsProducer interface {
- exportedFlags() []string
-}
-
type baseInstaller struct {
Properties InstallerProperties
@@ -1308,6 +1306,31 @@ func (installer *baseInstaller) inData() bool {
// Combined static+shared libraries
//
+type flagExporter struct {
+ Properties FlagExporterProperties
+
+ flags []string
+}
+
+func (f *flagExporter) exportIncludes(ctx ModuleContext, inc string) {
+ includeDirs := common.PathsForModuleSrc(ctx, f.Properties.Export_include_dirs)
+ f.flags = append(f.flags, common.JoinWithPrefix(includeDirs.Strings(), inc))
+}
+
+func (f *flagExporter) reexportFlags(flags []string) {
+ f.flags = append(f.flags, flags...)
+}
+
+func (f *flagExporter) exportedFlags() []string {
+ return f.flags
+}
+
+type exportedFlagsProducer interface {
+ exportedFlags() []string
+}
+
+var _ exportedFlagsProducer = (*flagExporter)(nil)
+
type libraryCompiler struct {
baseCompiler
@@ -1365,6 +1388,7 @@ func (library *libraryCompiler) compile(ctx ModuleContext, flags Flags, deps Pat
type libraryLinker struct {
baseLinker
+ flagExporter
Properties LibraryLinkerProperties
@@ -1373,8 +1397,6 @@ type libraryLinker struct {
BuildShared bool `blueprint:"mutated"`
}
- exportFlags []string
-
// If we're used as a whole_static_lib, our missing dependencies need
// to be given
wholeStaticMissingDeps []string
@@ -1384,11 +1406,13 @@ type libraryLinker struct {
}
var _ linker = (*libraryLinker)(nil)
-var _ exportedFlagsProducer = (*libraryLinker)(nil)
func (library *libraryLinker) props() []interface{} {
props := library.baseLinker.props()
- return append(props, &library.Properties, &library.dynamicProperties)
+ return append(props,
+ &library.Properties,
+ &library.dynamicProperties,
+ &library.flagExporter.Properties)
}
func (library *libraryLinker) flags(ctx ModuleContext, flags Flags) Flags {
@@ -1452,10 +1476,6 @@ func (library *libraryLinker) deps(ctx BaseModuleContext, deps Deps) Deps {
return deps
}
-func (library *libraryLinker) exportedFlags() []string {
- return library.exportFlags
-}
-
func (library *libraryLinker) linkStatic(ctx ModuleContext,
flags Flags, deps PathDeps, objFiles common.Paths) common.Path {
@@ -1542,9 +1562,8 @@ func (library *libraryLinker) link(ctx ModuleContext,
out = library.linkShared(ctx, flags, deps, objFiles)
}
- includeDirs := common.PathsForModuleSrc(ctx, library.Properties.Export_include_dirs)
- library.exportFlags = []string{includeDirsToFlags(includeDirs)}
- library.exportFlags = append(library.exportFlags, deps.ReexportedCflags...)
+ library.exportIncludes(ctx, "-I")
+ library.reexportFlags(deps.ReexportedCflags)
return out
}
@@ -2065,6 +2084,7 @@ func defaultsFactory() (blueprint.Module, []interface{}) {
&BaseCompilerProperties{},
&BaseLinkerProperties{},
&LibraryCompilerProperties{},
+ &FlagExporterProperties{},
&LibraryLinkerProperties{},
&BinaryLinkerProperties{},
&TestLinkerProperties{},
@@ -2178,16 +2198,13 @@ func (c *ndkPrebuiltObjectLinker) link(ctx ModuleContext, flags Flags,
type ndkPrebuiltLibraryLinker struct {
libraryLinker
- Properties struct {
- Export_include_dirs []string `android:"arch_variant"`
- }
}
var _ baseLinkerInterface = (*ndkPrebuiltLibraryLinker)(nil)
var _ exportedFlagsProducer = (*libraryLinker)(nil)
func (ndk *ndkPrebuiltLibraryLinker) props() []interface{} {
- return append(ndk.libraryLinker.props(), &ndk.Properties)
+ return append(ndk.libraryLinker.props(), &ndk.Properties, &ndk.flagExporter.Properties)
}
func (*ndkPrebuiltLibraryLinker) deps(ctx BaseModuleContext, deps Deps) Deps {
@@ -2210,8 +2227,7 @@ func (ndk *ndkPrebuiltLibraryLinker) link(ctx ModuleContext, flags Flags,
ctx.ModuleErrorf("NDK prebuilts must have an ndk_lib prefixed name")
}
- includeDirs := common.PathsForModuleSrc(ctx, ndk.Properties.Export_include_dirs)
- ndk.exportFlags = []string{common.JoinWithPrefix(includeDirs.Strings(), "-isystem ")}
+ ndk.exportIncludes(ctx, "-isystem")
return ndkPrebuiltModuleToPath(ctx, flags.Toolchain, flags.Toolchain.ShlibSuffix(),
ctx.sdkVersion())
@@ -2269,8 +2285,7 @@ func (ndk *ndkPrebuiltStlLinker) link(ctx ModuleContext, flags Flags,
ctx.ModuleErrorf("NDK prebuilts must have an ndk_lib prefixed name")
}
- includeDirs := common.PathsForModuleSrc(ctx, ndk.Properties.Export_include_dirs)
- ndk.exportFlags = []string{includeDirsToFlags(includeDirs)}
+ ndk.exportIncludes(ctx, "-I")
libName := strings.TrimPrefix(ctx.ModuleName(), "ndk_")
libExt := flags.Toolchain.ShlibSuffix()