]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix formatting of file paths under cwd
authormotemen <motemen@gmail.com>
Mon, 26 Feb 2018 18:22:46 +0000 (18:22 +0000)
committerIan Lance Taylor <iant@golang.org>
Mon, 26 Feb 2018 19:42:47 +0000 (19:42 +0000)
The output of go with -x flag is formatted in a manner that file paths
under current directory are modified to start with a dot (.), but when
the directory path ends with a slash (/), the formatting goes wrong.

Fixes #23982

Change-Id: I8f8d15dd52bee882a9c6357eb9eabdc3eaa887c3
GitHub-Last-Rev: 1493f38bafdf2c40f16392b794fd1a12eb12a151
GitHub-Pull-Request: golang/go#23985
Reviewed-on: https://go-review.googlesource.com/95755
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/go/go_test.go
src/cmd/go/internal/work/exec.go

index 773b8240d27578519712a38d200dcf910babc3bc..8f5a1f6c71384f18fede25a19f07b0e767309fb9 100644 (file)
@@ -5921,3 +5921,11 @@ echo $* >>`+tg.path("pkg-config.out"))
                t.Errorf("got %q want %q", out, want)
        }
 }
+
+// Issue 23982
+func TestFilepathUnderCwdFormat(t *testing.T) {
+       tg := testgo(t)
+       defer tg.cleanup()
+       tg.run("test", "-x", "-cover", "log")
+       tg.grepStderrNot(`\.log\.cover\.go`, "-x output should contain correctly formatted filepath under cwd")
+}
index ab216e748f0c11639166949bd0879e4f82a4c78c..e61d6d5cc4dc30264954fa9d979959b86e0a0030 100644 (file)
@@ -1364,7 +1364,11 @@ func mayberemovefile(s string) {
 func (b *Builder) fmtcmd(dir string, format string, args ...interface{}) string {
        cmd := fmt.Sprintf(format, args...)
        if dir != "" && dir != "/" {
-               cmd = strings.Replace(" "+cmd, " "+dir, " .", -1)[1:]
+               dot := " ."
+               if dir[len(dir)-1] == filepath.Separator {
+                       dot += string(filepath.Separator)
+               }
+               cmd = strings.Replace(" "+cmd, " "+dir, dot, -1)[1:]
                if b.scriptDir != dir {
                        b.scriptDir = dir
                        cmd = "cd " + dir + "\n" + cmd