diff options
author | Dan Willemsen <dwillemsen@google.com> | 2016-09-28 16:19:10 -0700 |
---|---|---|
committer | Dan Willemsen <dwillemsen@google.com> | 2016-09-28 17:38:57 -0700 |
commit | 3f4539b03578dcfab37f6e615db062b3399793df (patch) | |
tree | f7deb05bd98bca392ab26fd631bfbdf56265239e /genrule | |
parent | 4aa75ca244ef7d0150978af626c0478fa784e93d (diff) | |
download | build_soong-3f4539b03578dcfab37f6e615db062b3399793df.tar.gz build_soong-3f4539b03578dcfab37f6e615db062b3399793df.tar.bz2 build_soong-3f4539b03578dcfab37f6e615db062b3399793df.zip |
Parse genrule's cmd property
Instead of just passing this to ninja, use os.Expand to parse the
variable substitutions. While we're here, define a new "genDir" variable
that is the root of this module's generated directory.
Bug: 31742855
Test: Ensure invalid variables cause error
Test: Inspect commands in build.ninja
Change-Id: Iff6d0499ab57367669e73df52ab7c647358da13b
Diffstat (limited to 'genrule')
-rw-r--r-- | genrule/genrule.go | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/genrule/genrule.go b/genrule/genrule.go index ecc5ab80..a49a5dde 100644 --- a/genrule/genrule.go +++ b/genrule/genrule.go @@ -15,6 +15,8 @@ package genrule import ( + "os" + "github.com/google/blueprint" "android/soong" @@ -52,6 +54,7 @@ type generatorProperties struct { // $in: one or more input files // $out: a single output file // $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 Cmd string @@ -109,8 +112,30 @@ func (g *generator) GenerateAndroidBuildActions(ctx android.ModuleContext) { 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{ - Command: "PATH=$$PATH:$hostBin " + g.properties.Cmd, + Command: "PATH=$$PATH:$hostBin " + cmd, }, "tool") 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) { g.generateSourceFile(ctx, task, tool) } |