Skip to content

Commit

Permalink
cmd/toolstash: don't pass -N when compiling runtime
Browse files Browse the repository at this point in the history
The runtime cannot be compiled with optimizations disabled.
This lead to very confusing error messages
when toolstash -cmp failed.

Change-Id: Ie341d633ff9b26693b475957309591ff0757f1ab
Reviewed-on: https://go-review.googlesource.com/38378
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
  • Loading branch information
josharian committed Mar 20, 2017
1 parent 2946dd1 commit a5c9681
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions cmd/toolstash/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,26 @@ func compareTool() {
log.Fatalf("unknown tool %s", tool)

case tool == "compile" || strings.HasSuffix(tool, "g"): // compiler
cmdN := append([]string{cmd[0], "-N"}, cmd[1:]...)
useDashN := true
for _, s := range cmd {
if s == "-+" {
// Compiling runtime. Don't use -N.
useDashN = false
break
}
}
cmdN := injectflags(cmd, nil, useDashN)
_, ok := cmpRun(false, cmdN)
if !ok {
log.Printf("compiler output differs, even with optimizers disabled (-N)")
cmd = append([]string{cmd[0], "-v", "-N", "-m=2"}, cmd[1:]...)
if useDashN {
log.Printf("compiler output differs, with optimizers disabled (-N)")
} else {
log.Printf("compiler output differs")
}
cmd = injectflags(cmd, []string{"-v", "-m=2"}, useDashN)
break
}
cmd = append([]string{cmd[0], "-v", "-m=2"}, cmd[1:]...)
cmd = injectflags(cmd, []string{"-v", "-m=2"}, false)
log.Printf("compiler output differs, only with optimizers enabled")

case tool == "asm" || strings.HasSuffix(tool, "a"): // assembler
Expand All @@ -293,13 +305,23 @@ func compareTool() {
extra = "-v=2"
}

cmdS := append([]string{cmd[0], extra}, cmd[1:]...)
cmdS := injectflags(cmd, []string{extra}, false)
outfile, _ = cmpRun(true, cmdS)

fmt.Fprintf(os.Stderr, "\n%s\n", compareLogs(outfile))
os.Exit(2)
}

func injectflags(cmd []string, extra []string, addDashN bool) []string {
x := []string{cmd[0]}
if addDashN {
x = append(x, "-N")
}
x = append(x, extra...)
x = append(x, cmd[1:]...)
return x
}

func cmpRun(keepLog bool, cmd []string) (outfile string, match bool) {
cmdStash := make([]string, len(cmd))
copy(cmdStash, cmd)
Expand Down

0 comments on commit a5c9681

Please sign in to comment.