From b40aab6955ebb85b8ab5b3934838a4df507fa62c Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Wed, 20 Apr 2016 14:21:14 -0700 Subject: [PATCH] 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 --- cc/builder.go | 2 +- cc/cc.go | 89 +++++++++++++++++++++++++++++++++------------- genrule/genrule.go | 9 +++++ 3 files changed, 74 insertions(+), 26 deletions(-) diff --git a/cc/builder.go b/cc/builder.go index bcfbb6eec..38bb141ca 100644 --- a/cc/builder.go +++ b/cc/builder.go @@ -199,7 +199,7 @@ func TransformSourceToObj(ctx common.AndroidModuleContext, subdir string, srcFil Rule: cc, Output: objFile, Input: srcFile, - Implicits: deps, + OrderOnly: deps, Args: map[string]string{ "cFlags": moduleCflags, "ccCmd": ccCmd, diff --git a/cc/cc.go b/cc/cc.go index 1c1ef10e6..8910ce748 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -177,6 +177,9 @@ type Deps struct { ObjFiles []string + GeneratedSources []string + GeneratedHeaders []string + Cflags, ReexportedCflags []string CrtBegin, CrtEnd string @@ -189,6 +192,9 @@ type PathDeps struct { ObjFiles common.Paths WholeStaticLibObjFiles common.Paths + GeneratedSources common.Paths + GeneratedHeaders common.Paths + Cflags, ReexportedCflags []string CrtBegin, CrtEnd common.OptionalPath @@ -266,6 +272,14 @@ type BaseCompilerProperties struct { // If possible, don't use this. 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 Rtti *bool @@ -457,7 +471,7 @@ type feature interface { type compiler interface { feature - compile(ctx ModuleContext, flags Flags) common.Paths + compile(ctx ModuleContext, flags Flags, deps PathDeps) common.Paths } type linker interface { @@ -484,6 +498,8 @@ var ( staticDepTag = dependencyTag{name: "static", library: true} lateStaticDepTag = dependencyTag{name: "late static", library: true} wholeStaticDepTag = dependencyTag{name: "whole static", library: true} + genSourceDepTag = dependencyTag{name: "gen source"} + genHeaderDepTag = dependencyTag{name: "gen header"} objDepTag = dependencyTag{name: "obj"} crtBeginDepTag = dependencyTag{name: "crtbegin"} crtEndDepTag = dependencyTag{name: "crtend"} @@ -664,7 +680,7 @@ func (c *Module) GenerateAndroidBuildActions(actx common.AndroidModuleContext) { var objFiles common.Paths if c.compiler != nil { - objFiles = c.compiler.compile(ctx, flags) + objFiles = c.compiler.compile(ctx, flags, deps) if ctx.Failed() { return } @@ -769,6 +785,9 @@ func (c *Module) depsMutator(actx common.AndroidBottomUpMutatorContext) { actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag, deps.LateSharedLibs...) + actx.AddDependency(ctx.module(), genSourceDepTag, deps.GeneratedSources...) + actx.AddDependency(ctx.module(), genHeaderDepTag, deps.GeneratedHeaders...) + actx.AddDependency(ctx.module(), objDepTag, deps.ObjFiles...) if deps.CrtBegin != "" { @@ -821,7 +840,25 @@ func (c *Module) depsToPaths(ctx common.AndroidModuleContext) PathDeps { c, _ := m.(*Module) 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) } return @@ -922,8 +959,14 @@ func (compiler *baseCompiler) props() []interface{} { return []interface{}{&compiler.Properties} } -func (compiler *baseCompiler) begin(ctx BaseModuleContext) {} -func (compiler *baseCompiler) deps(ctx BaseModuleContext, deps Deps) Deps { return deps } +func (compiler *baseCompiler) begin(ctx BaseModuleContext) {} + +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, // 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 } -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 - 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() { 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 } // Compile a list of source files into objects a specified subdirectory 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) 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) } @@ -1307,18 +1344,20 @@ func (library *libraryCompiler) flags(ctx ModuleContext, flags Flags) 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 - objFiles = library.baseCompiler.compile(ctx, flags) + objFiles = library.baseCompiler.compile(ctx, flags, deps) library.reuseObjFiles = objFiles if library.linker.static() { 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 { 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 diff --git a/genrule/genrule.go b/genrule/genrule.go index 248da49cc..3c2e331fd 100644 --- a/genrule/genrule.go +++ b/genrule/genrule.go @@ -39,6 +39,7 @@ func init() { type SourceFileGenerator interface { GeneratedSourceFiles() common.Paths + GeneratedHeaderDir() common.Path } type HostToolProvider interface { @@ -68,6 +69,8 @@ type generator struct { deps common.Paths rule blueprint.Rule + genPath common.Path + outputFiles common.Paths } @@ -82,6 +85,10 @@ func (g *generator) GeneratedSourceFiles() common.Paths { return g.outputFiles } +func (g *generator) GeneratedHeaderDir() common.Path { + return g.genPath +} + func genruleDepsMutator(ctx common.AndroidBottomUpMutatorContext) { if g, ok := ctx.Module().(*generator); ok { 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) { g.generateSourceFile(ctx, task) }