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
This commit is contained in:
Jeff Gaston 2017-12-08 12:45:35 -08:00 committed by Colin Cross
parent c331599a88
commit 31603067b0
1 changed files with 4 additions and 1 deletions

View File

@ -277,7 +277,10 @@ func (g *Module) GenerateAndroidBuildActions(ctx android.ModuleContext) {
} }
genDir := android.PathForModuleGen(ctx) 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{ ruleParams := blueprint.RuleParams{
Command: sandboxCommand, Command: sandboxCommand,