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
diff --git a/cc/cc.go b/cc/cc.go
index 8910ce7..417dc0d 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -341,6 +341,12 @@
 	} `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 @@
 	// 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 @@
 	staticBinary() bool
 }
 
-type exportedFlagsProducer interface {
-	exportedFlags() []string
-}
-
 type baseInstaller struct {
 	Properties InstallerProperties
 
@@ -1308,6 +1306,31 @@
 // 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 @@
 
 type libraryLinker struct {
 	baseLinker
+	flagExporter
 
 	Properties LibraryLinkerProperties
 
@@ -1373,8 +1397,6 @@
 		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 @@
 }
 
 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 @@
 	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 @@
 		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 @@
 		&BaseCompilerProperties{},
 		&BaseLinkerProperties{},
 		&LibraryCompilerProperties{},
+		&FlagExporterProperties{},
 		&LibraryLinkerProperties{},
 		&BinaryLinkerProperties{},
 		&TestLinkerProperties{},
@@ -2178,16 +2198,13 @@
 
 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 @@
 		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 @@
 		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()