Merge "Separate exported includes out of flags"

This commit is contained in:
Treehugger Robot 2019-06-11 04:57:47 +00:00 committed by Gerrit Code Review
commit b879fb6b4b
9 changed files with 133 additions and 113 deletions

View file

@ -156,12 +156,18 @@ func makeOverrideModuleNames(ctx AndroidMkContext, overrides []string) []string
func (library *libraryDecorator) androidMkWriteExportedFlags(w io.Writer) {
exportedFlags := library.exportedFlags()
for _, dir := range library.exportedDirs() {
exportedFlags = append(exportedFlags, "-I"+dir)
}
for _, dir := range library.exportedSystemDirs() {
exportedFlags = append(exportedFlags, "-isystem "+dir)
}
if len(exportedFlags) > 0 {
fmt.Fprintln(w, "LOCAL_EXPORT_CFLAGS :=", strings.Join(exportedFlags, " "))
}
exportedFlagsDeps := library.exportedFlagsDeps()
if len(exportedFlagsDeps) > 0 {
fmt.Fprintln(w, "LOCAL_EXPORT_C_INCLUDE_DEPS :=", strings.Join(exportedFlagsDeps.Strings(), " "))
exportedDeps := library.exportedDeps()
if len(exportedDeps) > 0 {
fmt.Fprintln(w, "LOCAL_EXPORT_C_INCLUDE_DEPS :=", strings.Join(exportedDeps.Strings(), " "))
}
}

View file

@ -119,8 +119,13 @@ type PathDeps struct {
GeneratedSources android.Paths
GeneratedHeaders android.Paths
Flags, ReexportedFlags []string
ReexportedFlagsDeps android.Paths
Flags []string
IncludeDirs []string
SystemIncludeDirs []string
ReexportedDirs []string
ReexportedSystemDirs []string
ReexportedFlags []string
ReexportedDeps android.Paths
// Paths to crt*.o files
CrtBegin, CrtEnd android.OptionalPath
@ -988,6 +993,14 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
for _, dir := range deps.IncludeDirs {
flags.GlobalFlags = append(flags.GlobalFlags, "-I"+dir)
}
for _, dir := range deps.SystemIncludeDirs {
flags.GlobalFlags = append(flags.GlobalFlags, "-isystem "+dir)
}
c.flags = flags
// We need access to all the flags seen by a source file.
if c.sabi != nil {
@ -1578,6 +1591,13 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
llndkLibraries := llndkLibraries(ctx.Config())
vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
reexportExporter := func(exporter exportedFlagsProducer) {
depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
}
ctx.VisitDirectDeps(func(dep android.Module) {
depName := ctx.OtherModuleName(dep)
depTag := ctx.OtherModuleDependencyTag(dep)
@ -1599,14 +1619,13 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
genRule.GeneratedDeps()...)
flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
depPaths.Flags = append(depPaths.Flags, flags)
dirs := genRule.GeneratedHeaderDirs().Strings()
depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
if depTag == genHeaderExportDepTag {
depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
genRule.GeneratedDeps()...)
depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
// Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs...)
}
} else {
@ -1644,10 +1663,9 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
if depTag == reuseObjTag {
if l, ok := ccDep.compiler.(libraryInterface); ok {
c.staticVariant = ccDep
objs, flags, deps := l.reuseObjs()
objs, exporter := l.reuseObjs()
depPaths.Objs = depPaths.Objs.Append(objs)
depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
reexportExporter(exporter)
return
}
}
@ -1710,18 +1728,20 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
}
if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
flags := i.exportedFlags()
deps := i.exportedFlagsDeps()
depPaths.Flags = append(depPaths.Flags, flags...)
depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
depPaths.IncludeDirs = append(depPaths.IncludeDirs, i.exportedDirs()...)
depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedDeps()...)
depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
if t.reexportFlags {
depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
reexportExporter(i)
// Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
// Re-exported shared library headers must be included as well since they can help us with type information
// about template instantiations (instantiated from their headers).
c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
// -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
// scripts.
c.sabi.Properties.ReexportedIncludes = append(
c.sabi.Properties.ReexportedIncludes, i.exportedDirs()...)
}
}
@ -1883,12 +1903,16 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
// Dedup exported flags from dependencies
depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
depPaths.IncludeDirs = android.FirstUniqueStrings(depPaths.IncludeDirs)
depPaths.SystemIncludeDirs = android.FirstUniqueStrings(depPaths.SystemIncludeDirs)
depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
depPaths.ReexportedDirs = android.FirstUniqueStrings(depPaths.ReexportedDirs)
depPaths.ReexportedSystemDirs = android.FirstUniqueStrings(depPaths.ReexportedSystemDirs)
depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
if c.sabi != nil {
c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
}
return depPaths

View file

@ -25,9 +25,7 @@ type kernelHeadersDecorator struct {
func (stub *kernelHeadersDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path {
if ctx.Device() {
f := &stub.libraryDecorator.flagExporter
for _, dir := range ctx.DeviceConfig().DeviceKernelHeaderDirs() {
f.flags = append(f.flags, "-isystem "+dir)
}
f.reexportSystemDirs(ctx.DeviceConfig().DeviceKernelHeaderDirs()...)
}
return stub.libraryDecorator.linkStatic(ctx, flags, deps, objs)
}

View file

@ -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) reexportFlags(flags []string) {
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) {
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
@ -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 {

View file

@ -145,17 +145,17 @@ func (stub *llndkStubDecorator) link(ctx ModuleContext, flags Flags, deps PathDe
timestampFiles = append(timestampFiles, stub.processHeaders(ctx, dir, genHeaderOutDir))
}
includePrefix := "-I"
if Bool(stub.Properties.Export_headers_as_system) {
includePrefix = "-isystem "
stub.reexportSystemDirs(genHeaderOutDir.String())
} else {
stub.reexportDirs(genHeaderOutDir.String())
}
stub.reexportFlags([]string{includePrefix + genHeaderOutDir.String()})
stub.reexportDeps(timestampFiles)
stub.reexportDeps(timestampFiles...)
}
if Bool(stub.Properties.Export_headers_as_system) {
stub.exportIncludes(ctx, "-isystem ")
stub.exportIncludesAsSystem(ctx)
stub.libraryDecorator.flagExporter.Properties.Export_include_dirs = []string{}
}

View file

@ -151,7 +151,7 @@ func (ndk *ndkPrebuiltStlLinker) link(ctx ModuleContext, flags Flags,
ctx.ModuleErrorf("NDK prebuilt libraries must have an ndk_lib prefixed name")
}
ndk.exportIncludes(ctx, "-isystem ")
ndk.exportIncludesAsSystem(ctx)
libName := strings.TrimPrefix(ctx.ModuleName(), "ndk_")
libExt := flags.Toolchain.ShlibSuffix()

View file

@ -85,9 +85,11 @@ func (p *prebuiltLibraryLinker) link(ctx ModuleContext,
flags Flags, deps PathDeps, objs Objects) android.Path {
// TODO(ccross): verify shared library dependencies
if len(p.properties.Srcs) > 0 {
p.libraryDecorator.exportIncludes(ctx, "-I")
p.libraryDecorator.reexportFlags(deps.ReexportedFlags)
p.libraryDecorator.reexportDeps(deps.ReexportedFlagsDeps)
p.libraryDecorator.exportIncludes(ctx)
p.libraryDecorator.reexportDirs(deps.ReexportedDirs...)
p.libraryDecorator.reexportSystemDirs(deps.ReexportedSystemDirs...)
p.libraryDecorator.reexportFlags(deps.ReexportedFlags...)
p.libraryDecorator.reexportDeps(deps.ReexportedDeps...)
builderFlags := flagsToBuilderFlags(flags)

View file

@ -28,8 +28,8 @@ var (
)
type SAbiProperties struct {
CreateSAbiDumps bool `blueprint:"mutated"`
ReexportedIncludeFlags []string
CreateSAbiDumps bool `blueprint:"mutated"`
ReexportedIncludes []string `blueprint:"mutated"`
}
type sabi struct {

View file

@ -29,10 +29,6 @@ func includeDirsToFlags(dirs android.Paths) string {
return android.JoinWithPrefix(dirs.Strings(), "-I")
}
func includeFilesToFlags(files android.Paths) string {
return android.JoinWithPrefix(files.Strings(), "-include ")
}
func ldDirsToFlags(dirs []string) string {
return android.JoinWithPrefix(dirs, "-L")
}