Fix generated sources and headers

Add two cc properties: `generated_sources` and `generated_headers`,
instead of just adding genrule modules to `deps`. Label these with the
dep tagging mechanism, add the generated_headers paths to the include
paths, and add dependencies to generated headers for each compile.

Add dependencies so that regular sources can include generated yacc
headers, not just other generated lex/yacc files. Static/shared specific
sources still don't have dependencies to or from regular sources though.

Switch from an implicit dependency on generated files to an orderonly
dependency, since the depfile will take care of the necessary implicit
dependencies for incremental builds.

Change-Id: I436675acb1f57329d98b81c56dcb4384201a68ea
This commit is contained in:
Dan Willemsen
2016-04-20 14:21:14 -07:00
parent 21b481b757
commit b40aab6955
3 changed files with 74 additions and 26 deletions

View File

@@ -199,7 +199,7 @@ func TransformSourceToObj(ctx common.AndroidModuleContext, subdir string, srcFil
Rule: cc, Rule: cc,
Output: objFile, Output: objFile,
Input: srcFile, Input: srcFile,
Implicits: deps, OrderOnly: deps,
Args: map[string]string{ Args: map[string]string{
"cFlags": moduleCflags, "cFlags": moduleCflags,
"ccCmd": ccCmd, "ccCmd": ccCmd,

View File

@@ -177,6 +177,9 @@ type Deps struct {
ObjFiles []string ObjFiles []string
GeneratedSources []string
GeneratedHeaders []string
Cflags, ReexportedCflags []string Cflags, ReexportedCflags []string
CrtBegin, CrtEnd string CrtBegin, CrtEnd string
@@ -189,6 +192,9 @@ type PathDeps struct {
ObjFiles common.Paths ObjFiles common.Paths
WholeStaticLibObjFiles common.Paths WholeStaticLibObjFiles common.Paths
GeneratedSources common.Paths
GeneratedHeaders common.Paths
Cflags, ReexportedCflags []string Cflags, ReexportedCflags []string
CrtBegin, CrtEnd common.OptionalPath CrtBegin, CrtEnd common.OptionalPath
@@ -266,6 +272,14 @@ type BaseCompilerProperties struct {
// If possible, don't use this. // If possible, don't use this.
Local_include_files []string `android:"arch_variant"` Local_include_files []string `android:"arch_variant"`
// list of generated sources to compile. These are the names of gensrcs or
// genrule modules.
Generated_sources []string `android:"arch_variant"`
// list of generated headers to add to the include path. These are the names
// of genrule modules.
Generated_headers []string `android:"arch_variant"`
// pass -frtti instead of -fno-rtti // pass -frtti instead of -fno-rtti
Rtti *bool Rtti *bool
@@ -457,7 +471,7 @@ type feature interface {
type compiler interface { type compiler interface {
feature feature
compile(ctx ModuleContext, flags Flags) common.Paths compile(ctx ModuleContext, flags Flags, deps PathDeps) common.Paths
} }
type linker interface { type linker interface {
@@ -484,6 +498,8 @@ var (
staticDepTag = dependencyTag{name: "static", library: true} staticDepTag = dependencyTag{name: "static", library: true}
lateStaticDepTag = dependencyTag{name: "late static", library: true} lateStaticDepTag = dependencyTag{name: "late static", library: true}
wholeStaticDepTag = dependencyTag{name: "whole static", library: true} wholeStaticDepTag = dependencyTag{name: "whole static", library: true}
genSourceDepTag = dependencyTag{name: "gen source"}
genHeaderDepTag = dependencyTag{name: "gen header"}
objDepTag = dependencyTag{name: "obj"} objDepTag = dependencyTag{name: "obj"}
crtBeginDepTag = dependencyTag{name: "crtbegin"} crtBeginDepTag = dependencyTag{name: "crtbegin"}
crtEndDepTag = dependencyTag{name: "crtend"} crtEndDepTag = dependencyTag{name: "crtend"}
@@ -664,7 +680,7 @@ func (c *Module) GenerateAndroidBuildActions(actx common.AndroidModuleContext) {
var objFiles common.Paths var objFiles common.Paths
if c.compiler != nil { if c.compiler != nil {
objFiles = c.compiler.compile(ctx, flags) objFiles = c.compiler.compile(ctx, flags, deps)
if ctx.Failed() { if ctx.Failed() {
return return
} }
@@ -769,6 +785,9 @@ func (c *Module) depsMutator(actx common.AndroidBottomUpMutatorContext) {
actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag, actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
deps.LateSharedLibs...) deps.LateSharedLibs...)
actx.AddDependency(ctx.module(), genSourceDepTag, deps.GeneratedSources...)
actx.AddDependency(ctx.module(), genHeaderDepTag, deps.GeneratedHeaders...)
actx.AddDependency(ctx.module(), objDepTag, deps.ObjFiles...) actx.AddDependency(ctx.module(), objDepTag, deps.ObjFiles...)
if deps.CrtBegin != "" { if deps.CrtBegin != "" {
@@ -821,7 +840,25 @@ func (c *Module) depsToPaths(ctx common.AndroidModuleContext) PathDeps {
c, _ := m.(*Module) c, _ := m.(*Module)
if c == nil { if c == nil {
if tag != common.DefaultsDepTag { switch tag {
case common.DefaultsDepTag:
case genSourceDepTag:
if genRule, ok := m.(genrule.SourceFileGenerator); ok {
depPaths.GeneratedSources = append(depPaths.GeneratedSources,
genRule.GeneratedSourceFiles()...)
} else {
ctx.ModuleErrorf("module %q is not a gensrcs or genrule", name)
}
case genHeaderDepTag:
if genRule, ok := m.(genrule.SourceFileGenerator); ok {
depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
genRule.GeneratedSourceFiles()...)
depPaths.Cflags = append(depPaths.Cflags,
includeDirsToFlags(common.Paths{genRule.GeneratedHeaderDir()}))
} else {
ctx.ModuleErrorf("module %q is not a genrule", name)
}
default:
ctx.ModuleErrorf("depends on non-cc module %q", name) ctx.ModuleErrorf("depends on non-cc module %q", name)
} }
return return
@@ -923,7 +960,13 @@ func (compiler *baseCompiler) props() []interface{} {
} }
func (compiler *baseCompiler) begin(ctx BaseModuleContext) {} func (compiler *baseCompiler) begin(ctx BaseModuleContext) {}
func (compiler *baseCompiler) deps(ctx BaseModuleContext, deps Deps) Deps { return deps }
func (compiler *baseCompiler) deps(ctx BaseModuleContext, deps Deps) Deps {
deps.GeneratedSources = append(deps.GeneratedSources, compiler.Properties.Generated_sources...)
deps.GeneratedHeaders = append(deps.GeneratedHeaders, compiler.Properties.Generated_headers...)
return deps
}
// Create a Flags struct that collects the compile flags from global values, // Create a Flags struct that collects the compile flags from global values,
// per-target values, module type values, and per-module Blueprints properties // per-target values, module type values, and per-module Blueprints properties
@@ -1072,36 +1115,30 @@ func (compiler *baseCompiler) flags(ctx ModuleContext, flags Flags) Flags {
return flags return flags
} }
func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags) common.Paths { func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags, deps PathDeps) common.Paths {
// Compile files listed in c.Properties.Srcs into objects // Compile files listed in c.Properties.Srcs into objects
objFiles := compiler.compileObjs(ctx, flags, "", compiler.Properties.Srcs, compiler.Properties.Exclude_srcs) objFiles := compiler.compileObjs(ctx, flags, "",
compiler.Properties.Srcs, compiler.Properties.Exclude_srcs,
deps.GeneratedSources, deps.GeneratedHeaders)
if ctx.Failed() { if ctx.Failed() {
return nil return nil
} }
var genSrcs common.Paths
ctx.VisitDirectDeps(func(module blueprint.Module) {
if gen, ok := module.(genrule.SourceFileGenerator); ok {
genSrcs = append(genSrcs, gen.GeneratedSourceFiles()...)
}
})
if len(genSrcs) != 0 {
genObjs := TransformSourceToObj(ctx, "", genSrcs, flagsToBuilderFlags(flags), nil)
objFiles = append(objFiles, genObjs...)
}
return objFiles return objFiles
} }
// Compile a list of source files into objects a specified subdirectory // Compile a list of source files into objects a specified subdirectory
func (compiler *baseCompiler) compileObjs(ctx common.AndroidModuleContext, flags Flags, func (compiler *baseCompiler) compileObjs(ctx common.AndroidModuleContext, flags Flags,
subdir string, srcFiles, excludes []string) common.Paths { subdir string, srcFiles, excludes []string, extraSrcs, deps common.Paths) common.Paths {
buildFlags := flagsToBuilderFlags(flags) buildFlags := flagsToBuilderFlags(flags)
inputFiles := ctx.ExpandSources(srcFiles, excludes) inputFiles := ctx.ExpandSources(srcFiles, excludes)
srcPaths, deps := genSources(ctx, inputFiles, buildFlags) inputFiles = append(inputFiles, extraSrcs...)
srcPaths, gendeps := genSources(ctx, inputFiles, buildFlags)
deps = append(deps, gendeps...)
return TransformSourceToObj(ctx, subdir, srcPaths, buildFlags, deps) return TransformSourceToObj(ctx, subdir, srcPaths, buildFlags, deps)
} }
@@ -1307,18 +1344,20 @@ func (library *libraryCompiler) flags(ctx ModuleContext, flags Flags) Flags {
return flags return flags
} }
func (library *libraryCompiler) compile(ctx ModuleContext, flags Flags) common.Paths { func (library *libraryCompiler) compile(ctx ModuleContext, flags Flags, deps PathDeps) common.Paths {
var objFiles common.Paths var objFiles common.Paths
objFiles = library.baseCompiler.compile(ctx, flags) objFiles = library.baseCompiler.compile(ctx, flags, deps)
library.reuseObjFiles = objFiles library.reuseObjFiles = objFiles
if library.linker.static() { if library.linker.static() {
objFiles = append(objFiles, library.compileObjs(ctx, flags, common.DeviceStaticLibrary, objFiles = append(objFiles, library.compileObjs(ctx, flags, common.DeviceStaticLibrary,
library.Properties.Static.Srcs, library.Properties.Static.Exclude_srcs)...) library.Properties.Static.Srcs, library.Properties.Static.Exclude_srcs,
nil, deps.GeneratedHeaders)...)
} else { } else {
objFiles = append(objFiles, library.compileObjs(ctx, flags, common.DeviceSharedLibrary, objFiles = append(objFiles, library.compileObjs(ctx, flags, common.DeviceSharedLibrary,
library.Properties.Shared.Srcs, library.Properties.Shared.Exclude_srcs)...) library.Properties.Shared.Srcs, library.Properties.Shared.Exclude_srcs,
nil, deps.GeneratedHeaders)...)
} }
return objFiles return objFiles

View File

@@ -39,6 +39,7 @@ func init() {
type SourceFileGenerator interface { type SourceFileGenerator interface {
GeneratedSourceFiles() common.Paths GeneratedSourceFiles() common.Paths
GeneratedHeaderDir() common.Path
} }
type HostToolProvider interface { type HostToolProvider interface {
@@ -68,6 +69,8 @@ type generator struct {
deps common.Paths deps common.Paths
rule blueprint.Rule rule blueprint.Rule
genPath common.Path
outputFiles common.Paths outputFiles common.Paths
} }
@@ -82,6 +85,10 @@ func (g *generator) GeneratedSourceFiles() common.Paths {
return g.outputFiles return g.outputFiles
} }
func (g *generator) GeneratedHeaderDir() common.Path {
return g.genPath
}
func genruleDepsMutator(ctx common.AndroidBottomUpMutatorContext) { func genruleDepsMutator(ctx common.AndroidBottomUpMutatorContext) {
if g, ok := ctx.Module().(*generator); ok { if g, ok := ctx.Module().(*generator); ok {
if g.properties.Tool != "" { if g.properties.Tool != "" {
@@ -111,6 +118,8 @@ func (g *generator) GenerateAndroidBuildActions(ctx common.AndroidModuleContext)
} }
}) })
g.genPath = common.PathForModuleGen(ctx, "")
for _, task := range g.tasks(ctx) { for _, task := range g.tasks(ctx) {
g.generateSourceFile(ctx, task) g.generateSourceFile(ctx, task)
} }