aboutsummaryrefslogtreecommitdiff
path: root/compiler_wrapper
diff options
context:
space:
mode:
authorTobias Bosch <tbosch@google.com>2019-08-15 10:29:43 -0700
committerTobias Bosch <tbosch@google.com>2019-08-16 17:18:31 +0000
commite66aac08f0d52c15652188ef4eddf0cfb8690813 (patch)
tree0744630a5aeaf3e2e1f47e00f5adc0a355111e6f /compiler_wrapper
parent058d491217696abc0d7e445716b9c16157810dbe (diff)
downloadtoolchain-utils-e66aac08f0d52c15652188ef4eddf0cfb8690813.tar.gz
Allow arguments with spaces when comparing to the old wrapper.
BUG=chromium:773875 TEST=unit test Change-Id: Ib284463c7904ab4ac737c401b2b7928bbae98655 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1756215 Reviewed-by: George Burgess <gbiv@chromium.org> Tested-by: Tobias Bosch <tbosch@google.com>
Diffstat (limited to 'compiler_wrapper')
-rw-r--r--compiler_wrapper/oldwrapper.go47
-rw-r--r--compiler_wrapper/oldwrapper_test.go46
2 files changed, 68 insertions, 25 deletions
diff --git a/compiler_wrapper/oldwrapper.go b/compiler_wrapper/oldwrapper.go
index 04458198..3e42088a 100644
--- a/compiler_wrapper/oldwrapper.go
+++ b/compiler_wrapper/oldwrapper.go
@@ -68,28 +68,20 @@ func compareToOldWrapper(env env, cfg *config, inputCmd *command, newCmdResults
func parseOldWrapperCommands(stderr string) (cmds []*command, remainingStderr string) {
allStderrLines := strings.Split(stderr, "\n")
remainingStderrLines := []string{}
+ commandPrefix := "command "
+ argPrefix := "arg "
+ envUpdatePrefix := "envupdate "
+ currentCmd := (*command)(nil)
for _, line := range allStderrLines {
- const commandPrefix = "command:"
- const envupdatePrefix = ".EnvUpdate:"
- envUpdateIdx := strings.Index(line, envupdatePrefix)
- if strings.Index(line, commandPrefix) == 0 {
- if envUpdateIdx == -1 {
- envUpdateIdx = len(line) - 1
+ if strings.HasPrefix(line, commandPrefix) {
+ currentCmd = &command{
+ Path: line[len(commandPrefix):],
}
- args := strings.Fields(line[len(commandPrefix):envUpdateIdx])
- envUpdateStr := line[envUpdateIdx+len(envupdatePrefix):]
- envUpdate := strings.Fields(envUpdateStr)
- if len(envUpdate) == 0 {
- // normalize empty slice to nil to make comparing empty envUpdates
- // simpler.
- envUpdate = nil
- }
- cmd := &command{
- Path: args[0],
- Args: args[1:],
- EnvUpdates: envUpdate,
- }
- cmds = append(cmds, cmd)
+ cmds = append(cmds, currentCmd)
+ } else if strings.HasPrefix(line, argPrefix) {
+ currentCmd.Args = append(currentCmd.Args, line[len(argPrefix):])
+ } else if strings.HasPrefix(line, envUpdatePrefix) {
+ currentCmd.EnvUpdates = append(currentCmd.EnvUpdates, line[len(envUpdatePrefix):])
} else {
remainingStderrLines = append(remainingStderrLines, line)
}
@@ -218,13 +210,16 @@ func callOldShellWrapper(env env, cfg *oldWrapperConfig, inputCmd *command, file
EXEC=exec
function exec_mock {
- echo command:${*}.EnvUpdate: 1>&2
+ echo command "$1" 1>&2
+ for arg in "${@:2}"; do
+ echo arg $arg 1>&2
+ done
{{if .MockCmds}}
echo '{{(index .CmdResults 0).Stdout}}'
echo '{{(index .CmdResults 0).Stderr}}' 1>&2
exit {{(index .CmdResults 0).Exitcode}}
{{else}}
- $EXEC ${*}
+ $EXEC "$@"
{{end}}
}
@@ -301,8 +296,12 @@ mockResults = [{{range .CmdResults}} {
def serialize_cmd(args):
current_env = os.environ
- envupdate = [k + "=" + current_env.get(k, '') for k in set(list(current_env.keys()) + list(init_env.keys())) if current_env.get(k, '') != init_env.get(k, '')]
- print('command:%s.EnvUpdate:%s' % (' '.join(args), ' '.join(envupdate)), file=sys.stderr)
+ envupdates = [k + "=" + current_env.get(k, '') for k in set(list(current_env.keys()) + list(init_env.keys())) if current_env.get(k, '') != init_env.get(k, '')]
+ print('command %s' % args[0], file=sys.stderr)
+ for arg in args[1:]:
+ print('arg %s' % arg, file=sys.stderr)
+ for update in envupdates:
+ print('envupdate %s' % update, file=sys.stderr)
def check_output_mock(args):
serialize_cmd(args)
diff --git a/compiler_wrapper/oldwrapper_test.go b/compiler_wrapper/oldwrapper_test.go
index a7747ba7..37a3050e 100644
--- a/compiler_wrapper/oldwrapper_test.go
+++ b/compiler_wrapper/oldwrapper_test.go
@@ -247,6 +247,50 @@ func TestCompareToOldWrapperEscapeStdoutAndStderr(t *testing.T) {
})
}
+func TestCompareToOldPythonWrapperArgumentsWithSpaces(t *testing.T) {
+ withTestContext(t, func(ctx *testContext) {
+ ctx.cfg.mockOldWrapperCmds = false
+ ctx.cfg.oldWrapperPath = filepath.Join(ctx.tempDir, "fakewrapper")
+
+ ctx.cmdMock = func(cmd *command, stdout io.Writer, stderr io.Writer) error {
+ writePythonMockWrapper(ctx, &mockWrapperConfig{
+ Cmds: []*mockWrapperCmd{
+ {
+ Path: cmd.Path,
+ Args: cmd.Args,
+ },
+ },
+ })
+ return nil
+ }
+
+ ctx.must(callCompiler(ctx, ctx.cfg,
+ ctx.newCommand(clangX86_64, "a b", "c", mainCc)))
+ })
+}
+
+func TestCompareToOldShellWrapperArgumentsWithSpaces(t *testing.T) {
+ withTestContext(t, func(ctx *testContext) {
+ ctx.cfg.mockOldWrapperCmds = false
+ ctx.cfg.oldWrapperPath = filepath.Join(ctx.tempDir, "fakewrapper")
+
+ ctx.cmdMock = func(cmd *command, stdout io.Writer, stderr io.Writer) error {
+ writeShellMockWrapper(ctx, &mockWrapperConfig{
+ Cmds: []*mockWrapperCmd{
+ {
+ Path: cmd.Path,
+ Args: cmd.Args,
+ },
+ },
+ })
+ return nil
+ }
+
+ ctx.must(callCompiler(ctx, ctx.cfg,
+ ctx.newCommand(clangX86_64, "a b", "c", mainCc)))
+ })
+}
+
func writePythonMockWrapper(ctx *testContext, cfg *mockWrapperConfig) {
const mockTemplate = `
from __future__ import print_function
@@ -300,7 +344,7 @@ function fake_exec {
exit {{(index .Cmds 0).ExitCode}}
}
-$EXEC {{(index .Cmds 0).Path}}{{range (index .Cmds 0).Args}} {{.}}{{end}}
+$EXEC "{{(index .Cmds 0).Path}}"{{range (index .Cmds 0).Args}} "{{.}}"{{end}}
`
tmpl, err := template.New("mock").Parse(mockTemplate)
if err != nil {