diff options
author | Jeff Gaston <jeffrygaston@google.com> | 2017-12-08 12:45:35 -0800 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2017-12-11 23:55:03 +0000 |
commit | 31603067b0cc7c67f56c3d7415c886a17b4e6d24 (patch) | |
tree | 4f1a92321680c6745116d42740b5ebbdf5582475 /genrule | |
parent | c331599a8878bfe40f6030ce5cfc10603f739a8d (diff) | |
download | build_soong-31603067b0cc7c67f56c3d7415c886a17b4e6d24.tar.gz build_soong-31603067b0cc7c67f56c3d7415c886a17b4e6d24.tar.bz2 build_soong-31603067b0cc7c67f56c3d7415c886a17b4e6d24.zip |
Escape genrule commands
Bug: 70387174
Test: Put this text into an Android.bp:
genrule {
name: "test_genrule",
tool_files: ["foo"],
out: ["foo.c"],
cmd: "for i in a b c; do echo $$i; done > $(out)",
}
cc_library {
name: "libtest_genrule",
srcs: [":test_genrule"],
}
and then run `m -j libtest_genrule`. Although the library
shouldn't compile, check that it produces a foo.c that has
"a\nb\n\c\n" and not "\n\n\n".
Change-Id: I139106479439c9b3a95f1a2ecc23e73570d7bd59
Diffstat (limited to 'genrule')
-rw-r--r-- | genrule/genrule.go | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/genrule/genrule.go b/genrule/genrule.go index 8c1969f2..4f3ba93b 100644 --- a/genrule/genrule.go +++ b/genrule/genrule.go @@ -277,7 +277,10 @@ func (g *Module) GenerateAndroidBuildActions(ctx android.ModuleContext) { } genDir := android.PathForModuleGen(ctx) - sandboxCommand := fmt.Sprintf("$sboxCmd --sandbox-path %s --output-root %s -c %q %s $allouts", sandboxPath, genDir, rawCommand, depfilePlaceholder) + // Escape the command for the shell + rawCommand = "'" + strings.Replace(rawCommand, "'", `'\''`, -1) + "'" + sandboxCommand := fmt.Sprintf("$sboxCmd --sandbox-path %s --output-root %s -c %s %s $allouts", + sandboxPath, genDir, rawCommand, depfilePlaceholder) ruleParams := blueprint.RuleParams{ Command: sandboxCommand, |