diff options
Diffstat (limited to 'cc/library.go')
| -rw-r--r-- | cc/library.go | 142 |
1 files changed, 68 insertions, 74 deletions
diff --git a/cc/library.go b/cc/library.go index 0bc5b5bba..fab583753 100644 --- a/cc/library.go +++ b/cc/library.go @@ -15,6 +15,7 @@ package cc import ( + "fmt" "io" "path/filepath" "regexp" @@ -207,8 +208,10 @@ func LibraryHeaderFactory() android.Module { type flagExporter struct { Properties FlagExporterProperties - flags []string - flagsDeps android.Paths + dirs []string + systemDirs []string + flags []string + deps android.Paths } func (f *flagExporter) exportedIncludes(ctx ModuleContext) android.Paths { @@ -219,32 +222,57 @@ func (f *flagExporter) exportedIncludes(ctx ModuleContext) android.Paths { } } -func (f *flagExporter) exportIncludes(ctx ModuleContext, inc string) { - includeDirs := f.exportedIncludes(ctx) - for _, dir := range includeDirs.Strings() { - f.flags = append(f.flags, inc+dir) - } +func (f *flagExporter) exportIncludes(ctx ModuleContext) { + f.dirs = append(f.dirs, f.exportedIncludes(ctx).Strings()...) +} + +func (f *flagExporter) exportIncludesAsSystem(ctx ModuleContext) { + f.systemDirs = append(f.systemDirs, f.exportedIncludes(ctx).Strings()...) +} + +func (f *flagExporter) reexportDirs(dirs ...string) { + f.dirs = append(f.dirs, dirs...) +} + +func (f *flagExporter) reexportSystemDirs(dirs ...string) { + f.systemDirs = append(f.systemDirs, dirs...) } -func (f *flagExporter) reexportFlags(flags []string) { +func (f *flagExporter) reexportFlags(flags ...string) { + for _, flag := range flags { + if strings.HasPrefix(flag, "-I") || strings.HasPrefix(flag, "-isystem") { + panic(fmt.Errorf("Exporting invalid flag %q: "+ + "use reexportDirs or reexportSystemDirs to export directories", flag)) + } + } f.flags = append(f.flags, flags...) } -func (f *flagExporter) reexportDeps(deps android.Paths) { - f.flagsDeps = append(f.flagsDeps, deps...) +func (f *flagExporter) reexportDeps(deps ...android.Path) { + f.deps = append(f.deps, deps...) +} + +func (f *flagExporter) exportedDirs() []string { + return f.dirs +} + +func (f *flagExporter) exportedSystemDirs() []string { + return f.systemDirs } func (f *flagExporter) exportedFlags() []string { return f.flags } -func (f *flagExporter) exportedFlagsDeps() android.Paths { - return f.flagsDeps +func (f *flagExporter) exportedDeps() android.Paths { + return f.deps } type exportedFlagsProducer interface { + exportedDirs() []string + exportedSystemDirs() []string exportedFlags() []string - exportedFlagsDeps() android.Paths + exportedDeps() android.Paths } var _ exportedFlagsProducer = (*flagExporter)(nil) @@ -256,9 +284,7 @@ type libraryDecorator struct { MutatedProperties LibraryMutatedProperties // For reusing static library objects for shared library - reuseObjects Objects - reuseExportedFlags []string - reuseExportedDeps android.Paths + reuseObjects Objects // table-of-contents file to optimize out relinking when possible tocFile android.OptionalPath @@ -405,25 +431,6 @@ func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags, d return flags } -func extractExportIncludesFromFlags(flags []string) []string { - // This method is used in the generation of rules which produce - // abi-dumps for source files. Exported headers are needed to infer the - // abi exported by a library and filter out the rest of the abi dumped - // from a source. We extract the include flags exported by a library. - // This includes the flags exported which are re-exported from static - // library dependencies, exported header library dependencies and - // generated header dependencies. -isystem headers are not included - // since for bionic libraries, abi-filtering is taken care of by version - // scripts. - var exportedIncludes []string - for _, flag := range flags { - if strings.HasPrefix(flag, "-I") { - exportedIncludes = append(exportedIncludes, flag) - } - } - return exportedIncludes -} - func (library *libraryDecorator) shouldCreateVndkSourceAbiDump(ctx ModuleContext) bool { if library.Properties.Header_abi_checker.Enabled != nil { return Bool(library.Properties.Header_abi_checker.Enabled) @@ -456,8 +463,8 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa for _, dir := range exportIncludeDirs.Strings() { SourceAbiFlags = append(SourceAbiFlags, "-I"+dir) } - for _, reexportedInclude := range extractExportIncludesFromFlags(library.sabi.Properties.ReexportedIncludeFlags) { - SourceAbiFlags = append(SourceAbiFlags, reexportedInclude) + for _, reexportedInclude := range library.sabi.Properties.ReexportedIncludes { + SourceAbiFlags = append(SourceAbiFlags, "-I"+reexportedInclude) } flags.SAbiFlags = SourceAbiFlags total_length := len(library.baseCompiler.Properties.Srcs) + len(deps.GeneratedSources) + len(library.Properties.Shared.Srcs) + @@ -487,7 +494,7 @@ type libraryInterface interface { getWholeStaticMissingDeps() []string static() bool objs() Objects - reuseObjs() (Objects, []string, android.Paths) + reuseObjs() (Objects, exportedFlagsProducer) toc() android.OptionalPath // Returns true if the build options for the module have selected a static or shared build @@ -644,7 +651,7 @@ func (library *libraryDecorator) linkStatic(ctx ModuleContext, TransformObjToStaticLib(ctx, library.objects.objFiles, builderFlags, outputFile, objs.tidyFiles) - library.coverageOutputFile = TransformCoverageFilesToLib(ctx, library.objects, builderFlags, + library.coverageOutputFile = TransformCoverageFilesToZip(ctx, library.objects, ctx.ModuleName()+library.MutatedProperties.VariantName) library.wholeStaticMissingDeps = ctx.GetMissingDependencies() @@ -764,7 +771,7 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext, objs.sAbiDumpFiles = append(objs.sAbiDumpFiles, deps.StaticLibObjs.sAbiDumpFiles...) objs.sAbiDumpFiles = append(objs.sAbiDumpFiles, deps.WholeStaticLibObjs.sAbiDumpFiles...) - library.coverageOutputFile = TransformCoverageFilesToLib(ctx, objs, builderFlags, library.getLibName(ctx)) + library.coverageOutputFile = TransformCoverageFilesToZip(ctx, objs, library.getLibName(ctx)) library.linkSAbiDumpFiles(ctx, objs, fileName, ret) return ret @@ -814,8 +821,8 @@ func (library *libraryDecorator) linkSAbiDumpFiles(ctx ModuleContext, objs Objec for _, dir := range exportIncludeDirs.Strings() { SourceAbiFlags = append(SourceAbiFlags, "-I"+dir) } - for _, reexportedInclude := range extractExportIncludesFromFlags(library.sabi.Properties.ReexportedIncludeFlags) { - SourceAbiFlags = append(SourceAbiFlags, reexportedInclude) + for _, reexportedInclude := range library.sabi.Properties.ReexportedIncludes { + SourceAbiFlags = append(SourceAbiFlags, "-I"+reexportedInclude) } exportedHeaderFlags := strings.Join(SourceAbiFlags, " ") library.sAbiOutputFile = TransformDumpToLinkedDump(ctx, objs.sAbiDumpFiles, soFile, fileName, exportedHeaderFlags, @@ -842,19 +849,17 @@ func (library *libraryDecorator) link(ctx ModuleContext, out = library.linkShared(ctx, flags, deps, objs) } - library.exportIncludes(ctx, "-I") - library.reexportFlags(deps.ReexportedFlags) - library.reexportDeps(deps.ReexportedFlagsDeps) + library.exportIncludes(ctx) + library.reexportDirs(deps.ReexportedDirs...) + library.reexportSystemDirs(deps.ReexportedSystemDirs...) + library.reexportFlags(deps.ReexportedFlags...) + library.reexportDeps(deps.ReexportedDeps...) if Bool(library.Properties.Aidl.Export_aidl_headers) { if library.baseCompiler.hasSrcExt(".aidl") { - flags := []string{ - "-I" + android.PathForModuleGen(ctx, "aidl").String(), - } - library.reexportFlags(flags) - library.reuseExportedFlags = append(library.reuseExportedFlags, flags...) - library.reexportDeps(library.baseCompiler.pathDeps) // TODO: restrict to aidl deps - library.reuseExportedDeps = append(library.reuseExportedDeps, library.baseCompiler.pathDeps...) + dir := android.PathForModuleGen(ctx, "aidl").String() + library.reexportDirs(dir) + library.reexportDeps(library.baseCompiler.pathDeps...) // TODO: restrict to aidl deps } } @@ -862,26 +867,16 @@ func (library *libraryDecorator) link(ctx ModuleContext, if library.baseCompiler.hasSrcExt(".proto") { includes := []string{} if flags.proto.CanonicalPathFromRoot { - includes = append(includes, "-I"+flags.proto.SubDir.String()) + includes = append(includes, flags.proto.SubDir.String()) } - includes = append(includes, "-I"+flags.proto.Dir.String()) - library.reexportFlags(includes) - library.reuseExportedFlags = append(library.reuseExportedFlags, includes...) - library.reexportDeps(library.baseCompiler.pathDeps) // TODO: restrict to proto deps - library.reuseExportedDeps = append(library.reuseExportedDeps, library.baseCompiler.pathDeps...) + includes = append(includes, flags.proto.Dir.String()) + library.reexportDirs(includes...) + library.reexportDeps(library.baseCompiler.pathDeps...) // TODO: restrict to proto deps } } if library.baseCompiler.hasSrcExt(".sysprop") { - internalFlags := []string{ - "-I" + android.PathForModuleGen(ctx, "sysprop", "include").String(), - } - systemFlags := []string{ - "-I" + android.PathForModuleGen(ctx, "sysprop/system", "include").String(), - } - - flags := internalFlags - + dir := android.PathForModuleGen(ctx, "sysprop", "include").String() if library.Properties.Sysprop.Platform != nil { isProduct := ctx.ProductSpecific() && !ctx.useVndk() isVendor := ctx.useVndk() @@ -890,17 +885,16 @@ func (library *libraryDecorator) link(ctx ModuleContext, useSystem := isProduct || (isOwnerPlatform == isVendor) if useSystem { - flags = systemFlags + dir = android.PathForModuleGen(ctx, "sysprop/system", "include").String() } } - library.reexportFlags(flags) - library.reexportDeps(library.baseCompiler.pathDeps) - library.reuseExportedFlags = append(library.reuseExportedFlags, flags...) + library.reexportDirs(dir) + library.reexportDeps(library.baseCompiler.pathDeps...) } if library.buildStubs() { - library.reexportFlags([]string{"-D" + versioningMacroName(ctx.ModuleName()) + "=" + library.stubsVersion()}) + library.reexportFlags("-D" + versioningMacroName(ctx.ModuleName()) + "=" + library.stubsVersion()) } return out @@ -922,8 +916,8 @@ func (library *libraryDecorator) objs() Objects { return library.objects } -func (library *libraryDecorator) reuseObjs() (Objects, []string, android.Paths) { - return library.reuseObjects, library.reuseExportedFlags, library.reuseExportedDeps +func (library *libraryDecorator) reuseObjs() (Objects, exportedFlagsProducer) { + return library.reuseObjects, &library.flagExporter } func (library *libraryDecorator) toc() android.OptionalPath { |