Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(157)

Unified Diff: src/cmd/go/build.go

Issue 8633043: code review 8633043: cmd/go: quote empty command line arguments in debug output (Closed)
Patch Set: diff -r 9bb42a7021c9 https://code.google.com/p/go/ Created 11 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/cmd/go/build.go
===================================================================
--- a/src/cmd/go/build.go
+++ b/src/cmd/go/build.go
@@ -1237,7 +1237,7 @@
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 @@
}
}
+// joinUnambiguously prints the slice, quoting where necessary to make the
+// output unambiguous.
+func joinUnambiguously(a []string) string {
r 2013/04/12 20:59:27 that's a mouthful yet still not quite right. meh.
+ 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()
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b