mirror of
https://github.com/golang/go
synced 2024-11-20 00:04:43 -07:00
cmd/go: quote command line arguments in debug output
Debug output from go test -x may contain empty arguments. This CL quotes arguments if needed. E.g. the output of go test -x is now .../6g -o ./_go_.6 -p testmain -complete -D "" -I . -I $WORK ./_testmain.go which is easier to grasp. R=golang-dev, bradfitz, minux.ma, r CC=golang-dev https://golang.org/cl/8633043
This commit is contained in:
parent
696901204f
commit
ce64f7365f
@ -1237,7 +1237,7 @@ func (b *builder) processOutput(out []byte) string {
|
||||
func (b *builder) runOut(dir string, desc string, env []string, cmdargs ...interface{}) ([]byte, error) {
|
||||
cmdline := stringList(cmdargs...)
|
||||
if buildN || buildX {
|
||||
b.showcmd(dir, "%s", strings.Join(cmdline, " "))
|
||||
b.showcmd(dir, "%s", joinUnambiguously(cmdline))
|
||||
if buildN {
|
||||
return nil, nil
|
||||
}
|
||||
@ -1304,6 +1304,24 @@ func (b *builder) runOut(dir string, desc string, env []string, cmdargs ...inter
|
||||
}
|
||||
}
|
||||
|
||||
// joinUnambiguously prints the slice, quoting where necessary to make the
|
||||
// output unambiguous.
|
||||
func joinUnambiguously(a []string) string {
|
||||
var buf bytes.Buffer
|
||||
for i, s := range a {
|
||||
if i > 0 {
|
||||
buf.WriteByte(' ')
|
||||
}
|
||||
q := strconv.Quote(s)
|
||||
if s == "" || strings.Contains(s, " ") || len(q) > len(s)+2 {
|
||||
buf.WriteString(q)
|
||||
} else {
|
||||
buf.WriteString(s)
|
||||
}
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// mkdir makes the named directory.
|
||||
func (b *builder) mkdir(dir string) error {
|
||||
b.exec.Lock()
|
||||
|
Loading…
Reference in New Issue
Block a user