aboutsummaryrefslogtreecommitdiff
path: root/compiler_wrapper
diff options
context:
space:
mode:
authorTobias Bosch <tbosch@google.com>2019-08-21 14:49:43 -0700
committerTobias Bosch <tbosch@google.com>2019-08-21 22:06:49 +0000
commit6a6b52504d18b06f7ca871eff8cdad4e966c01e0 (patch)
tree7fd905f9958c1e1a76438f26e62a94a56ced3bc4 /compiler_wrapper
parenteede79ffa29e58657ed16259545b2f3c23edac2f (diff)
downloadtoolchain-utils-6a6b52504d18b06f7ca871eff8cdad4e966c01e0.tar.gz
Support \ while capturing stdout / stderr.
Also don't store stdout / stderr in old wrapper if we are not mocking commands. BUG=chromium:773875 TEST=emerge app-text/openjade Change-Id: I54e2167f011e14a468aa7800d2d5aae13ecb0c61 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1764497 Tested-by: Tobias Bosch <tbosch@google.com> Reviewed-by: George Burgess <gbiv@chromium.org>
Diffstat (limited to 'compiler_wrapper')
-rw-r--r--compiler_wrapper/oldwrapper.go4
-rw-r--r--compiler_wrapper/oldwrapper_test.go8
2 files changed, 7 insertions, 5 deletions
diff --git a/compiler_wrapper/oldwrapper.go b/compiler_wrapper/oldwrapper.go
index 268f1cab..2f0683db 100644
--- a/compiler_wrapper/oldwrapper.go
+++ b/compiler_wrapper/oldwrapper.go
@@ -26,7 +26,7 @@ const compareToOldWrapperFilePattern = "old_wrapper_compare"
const tempDir = "/tmp"
func compareToOldWrapper(env env, cfg *config, inputCmd *command, stdinBuffer []byte, newCmdResults []*commandResult, newExitCode int) error {
- pythonStringEscaper := strings.NewReplacer("\n", "\\n", "'", "\\'")
+ pythonStringEscaper := strings.NewReplacer("\n", "\\n", "'", "\\'", "\\", "\\\\")
oldWrapperCfg, err := newOldWrapperConfig(env, cfg, inputCmd)
if err != nil {
@@ -295,11 +295,13 @@ import subprocess
init_env = os.environ.copy()
+{{if .MockCmds}}
mockResults = [{{range .CmdResults}} {
'stdout': '{{.Stdout}}',
'stderr': '{{.Stderr}}',
'exitcode': {{.Exitcode}},
},{{end}}]
+{{end}}
def serialize_cmd(args):
current_env = os.environ
diff --git a/compiler_wrapper/oldwrapper_test.go b/compiler_wrapper/oldwrapper_test.go
index e1752ce0..7024e034 100644
--- a/compiler_wrapper/oldwrapper_test.go
+++ b/compiler_wrapper/oldwrapper_test.go
@@ -224,8 +224,8 @@ func TestCompareToOldWrapperEscapeStdoutAndStderr(t *testing.T) {
ctx.cfg.oldWrapperPath = filepath.Join(ctx.tempDir, "fakewrapper")
ctx.cmdMock = func(cmd *command, stdin io.Reader, stdout io.Writer, stderr io.Writer) error {
- io.WriteString(stdout, "a\n'b'")
- io.WriteString(stderr, "c\n'd'")
+ io.WriteString(stdout, "a\n'b'\\")
+ io.WriteString(stderr, "c\n'd'\\")
writePythonMockWrapper(ctx, &mockWrapperConfig{
Cmds: []*mockWrapperCmd{
{
@@ -239,10 +239,10 @@ func TestCompareToOldWrapperEscapeStdoutAndStderr(t *testing.T) {
ctx.must(callCompiler(ctx, ctx.cfg,
ctx.newCommand(clangX86_64, mainCc)))
- if ctx.stdoutString() != "a\n'b'" {
+ if ctx.stdoutString() != "a\n'b'\\" {
t.Errorf("unexpected stdout. Got: %s", ctx.stdoutString())
}
- if ctx.stderrString() != "c\n'd'" {
+ if ctx.stderrString() != "c\n'd'\\" {
t.Errorf("unexpected stderr. Got: %s", ctx.stderrString())
}
})