Add genrule tool_file to better handle deps
am: f7f3d69cf5
* commit 'f7f3d69cf58cdb0bb15ea0b376a6e0381e971905':
Add genrule tool_file to better handle deps
Change-Id: I04054b0c22d2e05ad877c69187b6fc2551b743b2
This commit is contained in:
commit
d8fd035fad
|
@ -48,6 +48,7 @@ type HostToolProvider interface {
|
||||||
|
|
||||||
type generatorProperties struct {
|
type generatorProperties struct {
|
||||||
// command to run on one or more input files. Available variables for substitution:
|
// command to run on one or more input files. Available variables for substitution:
|
||||||
|
// $tool: the path to the `tool` or `tool_file`
|
||||||
// $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
|
||||||
|
@ -57,6 +58,9 @@ type generatorProperties struct {
|
||||||
// name of the module (if any) that produces the host executable. Leave empty for
|
// name of the module (if any) that produces the host executable. Leave empty for
|
||||||
// prebuilts or scripts that do not need a module to build them.
|
// prebuilts or scripts that do not need a module to build them.
|
||||||
Tool string
|
Tool string
|
||||||
|
|
||||||
|
// Local file that is used as the tool
|
||||||
|
Tool_file string
|
||||||
}
|
}
|
||||||
|
|
||||||
type generator struct {
|
type generator struct {
|
||||||
|
@ -101,15 +105,27 @@ func genruleDepsMutator(ctx common.AndroidBottomUpMutatorContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *generator) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
|
func (g *generator) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
|
||||||
|
if g.properties.Tool != "" && g.properties.Tool_file != "" {
|
||||||
|
ctx.ModuleErrorf("`tool` and `tool_file` may not be specified at the same time")
|
||||||
|
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 " + g.properties.Cmd,
|
||||||
})
|
}, "tool")
|
||||||
|
|
||||||
|
var tool string
|
||||||
|
if g.properties.Tool_file != "" {
|
||||||
|
toolpath := common.PathForModuleSrc(ctx, g.properties.Tool_file)
|
||||||
|
g.deps = append(g.deps, toolpath)
|
||||||
|
tool = toolpath.String()
|
||||||
|
} else if g.properties.Tool != "" {
|
||||||
ctx.VisitDirectDeps(func(module blueprint.Module) {
|
ctx.VisitDirectDeps(func(module blueprint.Module) {
|
||||||
if t, ok := module.(HostToolProvider); ok {
|
if t, ok := module.(HostToolProvider); ok {
|
||||||
p := t.HostToolPath()
|
p := t.HostToolPath()
|
||||||
if p.Valid() {
|
if p.Valid() {
|
||||||
g.deps = append(g.deps, p.Path())
|
g.deps = append(g.deps, p.Path())
|
||||||
|
tool = p.String()
|
||||||
} else {
|
} else {
|
||||||
ctx.ModuleErrorf("host tool %q missing output file", ctx.OtherModuleName(module))
|
ctx.ModuleErrorf("host tool %q missing output file", ctx.OtherModuleName(module))
|
||||||
}
|
}
|
||||||
|
@ -117,20 +133,24 @@ func (g *generator) GenerateAndroidBuildActions(ctx common.AndroidModuleContext)
|
||||||
ctx.ModuleErrorf("unknown dependency %q", ctx.OtherModuleName(module))
|
ctx.ModuleErrorf("unknown dependency %q", ctx.OtherModuleName(module))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
g.genPath = common.PathForModuleGen(ctx, "")
|
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, tool)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *generator) generateSourceFile(ctx common.AndroidModuleContext, task generateTask) {
|
func (g *generator) generateSourceFile(ctx common.AndroidModuleContext, task generateTask, tool string) {
|
||||||
ctx.ModuleBuild(pctx, common.ModuleBuildParams{
|
ctx.ModuleBuild(pctx, common.ModuleBuildParams{
|
||||||
Rule: g.rule,
|
Rule: g.rule,
|
||||||
Output: task.out,
|
Output: task.out,
|
||||||
Inputs: task.in,
|
Inputs: task.in,
|
||||||
Implicits: g.deps,
|
Implicits: g.deps,
|
||||||
|
Args: map[string]string{
|
||||||
|
"tool": tool,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
g.outputFiles = append(g.outputFiles, task.out)
|
g.outputFiles = append(g.outputFiles, task.out)
|
||||||
|
@ -179,7 +199,7 @@ func GenRuleFactory() (blueprint.Module, []interface{}) {
|
||||||
return []generateTask{
|
return []generateTask{
|
||||||
{
|
{
|
||||||
in: ctx.ExpandSources(properties.Srcs, nil),
|
in: ctx.ExpandSources(properties.Srcs, nil),
|
||||||
out: properties.Out,
|
out: common.PathForModuleGen(ctx, properties.Out),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -192,5 +212,5 @@ type genRuleProperties struct {
|
||||||
Srcs []string
|
Srcs []string
|
||||||
|
|
||||||
// name of the output file that will be generated
|
// name of the output file that will be generated
|
||||||
Out common.ModuleGenPath
|
Out string
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue