Merge changes from topic 'genrule-multi-out'

* changes:
  Remove shared lib name checks
  Add export_generated_headers
  Support multiple outputs for genrule
  Parse genrule's cmd property
  Expose HostToolPath on the cc module to fix genrule.tool
This commit is contained in:
Treehugger Robot
2016-09-29 05:33:03 +00:00
committed by Gerrit Code Review
6 changed files with 104 additions and 42 deletions

View File

@@ -69,7 +69,7 @@ type binaryDecorator struct {
Properties BinaryLinkerProperties Properties BinaryLinkerProperties
hostToolPath android.OptionalPath toolPath android.OptionalPath
} }
var _ linker = (*binaryDecorator)(nil) var _ linker = (*binaryDecorator)(nil)
@@ -256,9 +256,6 @@ func (binary *binaryDecorator) link(ctx ModuleContext,
fileName := binary.getStem(ctx) + flags.Toolchain.ExecutableSuffix() fileName := binary.getStem(ctx) + flags.Toolchain.ExecutableSuffix()
outputFile := android.PathForModuleOut(ctx, fileName) outputFile := android.PathForModuleOut(ctx, fileName)
ret := outputFile ret := outputFile
if ctx.Os().Class == android.Host {
binary.hostToolPath = android.OptionalPathForPath(outputFile)
}
var linkerDeps android.Paths var linkerDeps android.Paths
@@ -291,6 +288,13 @@ func (binary *binaryDecorator) link(ctx ModuleContext,
return ret return ret
} }
func (binary *binaryDecorator) HostToolPath() android.OptionalPath { func (binary *binaryDecorator) install(ctx ModuleContext, file android.Path) {
return binary.hostToolPath binary.baseInstaller.install(ctx, file)
if ctx.Os().Class == android.Host {
binary.toolPath = android.OptionalPathForPath(binary.baseInstaller.path)
}
}
func (binary *binaryDecorator) hostToolPath() android.OptionalPath {
return binary.toolPath
} }

View File

@@ -377,13 +377,6 @@ func TransformObjToDynamicBinary(ctx android.ModuleContext,
} }
for _, lib := range sharedLibs { for _, lib := range sharedLibs {
file := filepath.Base(lib.String())
if !strings.HasPrefix(file, "lib") {
panic("shared library " + lib.String() + " does not start with lib")
}
if !strings.HasSuffix(file, flags.toolchain.ShlibSuffix()) {
panic("shared library " + lib.String() + " does not end with " + flags.toolchain.ShlibSuffix())
}
libFlagsList = append(libFlagsList, lib.String()) libFlagsList = append(libFlagsList, lib.String())
} }

View File

@@ -64,6 +64,8 @@ type Deps struct {
GeneratedSources []string GeneratedSources []string
GeneratedHeaders []string GeneratedHeaders []string
ReexportGeneratedHeaders []string
CrtBegin, CrtEnd string CrtBegin, CrtEnd string
} }
@@ -181,6 +183,7 @@ type installer interface {
installerProps() []interface{} installerProps() []interface{}
install(ctx ModuleContext, path android.Path) install(ctx ModuleContext, path android.Path)
inData() bool inData() bool
hostToolPath() android.OptionalPath
} }
type dependencyTag struct { type dependencyTag struct {
@@ -201,6 +204,7 @@ var (
wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true} wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
genSourceDepTag = dependencyTag{name: "gen source"} genSourceDepTag = dependencyTag{name: "gen source"}
genHeaderDepTag = dependencyTag{name: "gen header"} genHeaderDepTag = dependencyTag{name: "gen header"}
genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
objDepTag = dependencyTag{name: "obj"} objDepTag = dependencyTag{name: "obj"}
crtBeginDepTag = dependencyTag{name: "crtbegin"} crtBeginDepTag = dependencyTag{name: "crtbegin"}
crtEndDepTag = dependencyTag{name: "crtend"} crtEndDepTag = dependencyTag{name: "crtend"}
@@ -502,6 +506,12 @@ func (c *Module) deps(ctx BaseModuleContext) Deps {
} }
} }
for _, gen := range deps.ReexportGeneratedHeaders {
if !inList(gen, deps.GeneratedHeaders) {
ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
}
}
return deps return deps
} }
@@ -593,7 +603,14 @@ func (c *Module) depsMutator(actx android.BottomUpMutatorContext) {
deps.LateSharedLibs...) deps.LateSharedLibs...)
actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...) actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
actx.AddDependency(c, genHeaderDepTag, deps.GeneratedHeaders...)
for _, gen := range deps.GeneratedHeaders {
depTag := genHeaderDepTag
if inList(gen, deps.ReexportGeneratedHeaders) {
depTag = genHeaderExportDepTag
}
actx.AddDependency(c, depTag, gen)
}
actx.AddDependency(c, objDepTag, deps.ObjFiles...) actx.AddDependency(c, objDepTag, deps.ObjFiles...)
@@ -735,12 +752,15 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
} else { } else {
ctx.ModuleErrorf("module %q is not a gensrcs or genrule", name) ctx.ModuleErrorf("module %q is not a gensrcs or genrule", name)
} }
case genHeaderDepTag: case genHeaderDepTag, genHeaderExportDepTag:
if genRule, ok := m.(genrule.SourceFileGenerator); ok { if genRule, ok := m.(genrule.SourceFileGenerator); ok {
depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
genRule.GeneratedSourceFiles()...) genRule.GeneratedSourceFiles()...)
depPaths.Flags = append(depPaths.Flags, flags := includeDirsToFlags(android.Paths{genRule.GeneratedHeaderDir()})
includeDirsToFlags(android.Paths{genRule.GeneratedHeaderDir()})) depPaths.Flags = append(depPaths.Flags, flags)
if tag == genHeaderExportDepTag {
depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
}
} else { } else {
ctx.ModuleErrorf("module %q is not a genrule", name) ctx.ModuleErrorf("module %q is not a genrule", name)
} }
@@ -845,6 +865,13 @@ func (c *Module) InstallInData() bool {
return c.installer.inData() return c.installer.inData()
} }
func (c *Module) HostToolPath() android.OptionalPath {
if c.installer == nil {
return android.OptionalPath{}
}
return c.installer.hostToolPath()
}
// //
// Defaults // Defaults
// //

View File

@@ -80,3 +80,7 @@ func (installer *baseInstaller) install(ctx ModuleContext, file android.Path) {
func (installer *baseInstaller) inData() bool { func (installer *baseInstaller) inData() bool {
return installer.location == InstallInData return installer.location == InstallInData
} }
func (installer *baseInstaller) hostToolPath() android.OptionalPath {
return android.OptionalPath{}
}

View File

@@ -67,6 +67,10 @@ type BaseLinkerProperties struct {
// present in static_libs. // present in static_libs.
Export_static_lib_headers []string `android:"arch_variant"` Export_static_lib_headers []string `android:"arch_variant"`
// list of generated headers to re-export include directories from. Entries must be
// present in generated_headers.
Export_generated_headers []string `android:"arch_variant"`
// don't link in crt_begin and crt_end. This flag should only be necessary for // don't link in crt_begin and crt_end. This flag should only be necessary for
// compiling crt or libc. // compiling crt or libc.
Nocrt *bool `android:"arch_variant"` Nocrt *bool `android:"arch_variant"`
@@ -107,6 +111,7 @@ func (linker *baseLinker) linkerDeps(ctx BaseModuleContext, deps Deps) Deps {
deps.ReexportStaticLibHeaders = append(deps.ReexportStaticLibHeaders, linker.Properties.Export_static_lib_headers...) deps.ReexportStaticLibHeaders = append(deps.ReexportStaticLibHeaders, linker.Properties.Export_static_lib_headers...)
deps.ReexportSharedLibHeaders = append(deps.ReexportSharedLibHeaders, linker.Properties.Export_shared_lib_headers...) deps.ReexportSharedLibHeaders = append(deps.ReexportSharedLibHeaders, linker.Properties.Export_shared_lib_headers...)
deps.ReexportGeneratedHeaders = append(deps.ReexportGeneratedHeaders, linker.Properties.Export_generated_headers...)
if ctx.ModuleName() != "libcompiler_rt-extras" { if ctx.ModuleName() != "libcompiler_rt-extras" {
deps.LateStaticLibs = append(deps.LateStaticLibs, "libcompiler_rt-extras") deps.LateStaticLibs = append(deps.LateStaticLibs, "libcompiler_rt-extras")

View File

@@ -15,6 +15,8 @@
package genrule package genrule
import ( import (
"os"
"github.com/google/blueprint" "github.com/google/blueprint"
"android/soong" "android/soong"
@@ -52,6 +54,7 @@ type generatorProperties struct {
// $in: one or more input files // $in: one or more input files
// $out: a single output file // $out: a single output file
// $srcDir: the root directory of the source tree // $srcDir: the root directory of the source tree
// $genDir: the sandbox directory for this tool; contains $out
// The host bin directory will be in the path // The host bin directory will be in the path
Cmd string Cmd string
@@ -82,7 +85,7 @@ type taskFunc func(ctx android.ModuleContext) []generateTask
type generateTask struct { type generateTask struct {
in android.Paths in android.Paths
out android.ModuleGenPath out android.WritablePaths
} }
func (g *generator) GeneratedSourceFiles() android.Paths { func (g *generator) GeneratedSourceFiles() android.Paths {
@@ -109,8 +112,30 @@ func (g *generator) GenerateAndroidBuildActions(ctx android.ModuleContext) {
return return
} }
g.genPath = android.PathForModuleGen(ctx, "")
cmd := os.Expand(g.properties.Cmd, func(name string) string {
switch name {
case "$":
return "$$"
case "tool":
return "${tool}"
case "in":
return "${in}"
case "out":
return "${out}"
case "srcDir":
return "${srcDir}"
case "genDir":
return g.genPath.String()
default:
ctx.PropertyErrorf("cmd", "unknown variable '%s'", name)
}
return ""
})
g.rule = ctx.Rule(pctx, "generator", blueprint.RuleParams{ g.rule = ctx.Rule(pctx, "generator", blueprint.RuleParams{
Command: "PATH=$$PATH:$hostBin " + g.properties.Cmd, Command: "PATH=$$PATH:$hostBin " + cmd,
}, "tool") }, "tool")
var tool string var tool string
@@ -134,8 +159,6 @@ func (g *generator) GenerateAndroidBuildActions(ctx android.ModuleContext) {
}) })
} }
g.genPath = android.PathForModuleGen(ctx, "")
for _, task := range g.tasks(ctx) { for _, task := range g.tasks(ctx) {
g.generateSourceFile(ctx, task, tool) g.generateSourceFile(ctx, task, tool)
} }
@@ -144,7 +167,7 @@ func (g *generator) GenerateAndroidBuildActions(ctx android.ModuleContext) {
func (g *generator) generateSourceFile(ctx android.ModuleContext, task generateTask, tool string) { func (g *generator) generateSourceFile(ctx android.ModuleContext, task generateTask, tool string) {
ctx.ModuleBuild(pctx, android.ModuleBuildParams{ ctx.ModuleBuild(pctx, android.ModuleBuildParams{
Rule: g.rule, Rule: g.rule,
Output: task.out, Outputs: task.out,
Inputs: task.in, Inputs: task.in,
Implicits: g.deps, Implicits: g.deps,
Args: map[string]string{ Args: map[string]string{
@@ -152,7 +175,9 @@ func (g *generator) generateSourceFile(ctx android.ModuleContext, task generateT
}, },
}) })
g.outputFiles = append(g.outputFiles, task.out) for _, outputFile := range task.out {
g.outputFiles = append(g.outputFiles, outputFile)
}
} }
func generatorFactory(tasks taskFunc, props ...interface{}) (blueprint.Module, []interface{}) { func generatorFactory(tasks taskFunc, props ...interface{}) (blueprint.Module, []interface{}) {
@@ -174,7 +199,7 @@ func GenSrcsFactory() (blueprint.Module, []interface{}) {
for _, in := range srcFiles { for _, in := range srcFiles {
tasks = append(tasks, generateTask{ tasks = append(tasks, generateTask{
in: android.Paths{in}, in: android.Paths{in},
out: android.GenPathWithExt(ctx, in, properties.Output_extension), out: android.WritablePaths{android.GenPathWithExt(ctx, in, properties.Output_extension)},
}) })
} }
return tasks return tasks
@@ -195,10 +220,14 @@ func GenRuleFactory() (blueprint.Module, []interface{}) {
properties := &genRuleProperties{} properties := &genRuleProperties{}
tasks := func(ctx android.ModuleContext) []generateTask { tasks := func(ctx android.ModuleContext) []generateTask {
outs := make(android.WritablePaths, len(properties.Out))
for i, out := range properties.Out {
outs[i] = android.PathForModuleGen(ctx, out)
}
return []generateTask{ return []generateTask{
{ {
in: ctx.ExpandSources(properties.Srcs, nil), in: ctx.ExpandSources(properties.Srcs, nil),
out: android.PathForModuleGen(ctx, properties.Out), out: outs,
}, },
} }
} }
@@ -210,6 +239,6 @@ type genRuleProperties struct {
// list of input files // list of input files
Srcs []string Srcs []string
// name of the output file that will be generated // names of the output files that will be generated
Out string Out []string
} }