]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: with -x, don't report removing a non-existent objdir
authorIan Lance Taylor <iant@golang.org>
Tue, 27 Mar 2018 17:29:06 +0000 (10:29 -0700)
committerIan Lance Taylor <iant@golang.org>
Tue, 27 Mar 2018 19:55:14 +0000 (19:55 +0000)
Fixes #24389
Fixes #24396

Change-Id: I37399528700e2a39d9523d7c41bdc929618eb095
Reviewed-on: https://go-review.googlesource.com/102619
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/go/go_test.go
src/cmd/go/internal/work/exec.go

index b5200335ad257e4738dce3995e3c1721f61d3e9a..74254230a9860cbf9cab6dcd5dbf4437c958598d 100644 (file)
@@ -5960,3 +5960,19 @@ func TestFilepathUnderCwdFormat(t *testing.T) {
        tg.run("test", "-x", "-cover", "log")
        tg.grepStderrNot(`\.log\.cover\.go`, "-x output should contain correctly formatted filepath under cwd")
 }
+
+// Issue 24396.
+func TestDontReportRemoveOfEmptyDir(t *testing.T) {
+       tg := testgo(t)
+       defer tg.cleanup()
+       tg.parallel()
+       tg.tempFile("src/a/a.go", `package a`)
+       tg.setenv("GOPATH", tg.path("."))
+       tg.run("install", "-x", "a")
+       tg.run("install", "-x", "a")
+       // The second install should have printed only a WORK= line,
+       // nothing else.
+       if bytes.Count(tg.stdout.Bytes(), []byte{'\n'})+bytes.Count(tg.stderr.Bytes(), []byte{'\n'}) > 1 {
+               t.Error("unnecessary output when installing installed package")
+       }
+}
index ee1eac8040d3a3786879da2a87a5496e5414952a..502d0d4132f2391a6182e94d2f21bf1387372fad 100644 (file)
@@ -1136,7 +1136,11 @@ func BuildInstallFunc(b *Builder, a *Action) (err error) {
 func (b *Builder) cleanup(a *Action) {
        if !cfg.BuildWork {
                if cfg.BuildX {
-                       b.Showcmd("", "rm -r %s", a.Objdir)
+                       // Don't say we are removing the directory if
+                       // we never created it.
+                       if _, err := os.Stat(a.Objdir); err == nil || cfg.BuildN {
+                               b.Showcmd("", "rm -r %s", a.Objdir)
+                       }
                }
                os.RemoveAll(a.Objdir)
        }