Skip to content

Commit ad0ebc3

Browse files
cmd/go: with -x, don't report removing a non-existent objdir
Fixes #24389 Fixes #24396 Change-Id: I37399528700e2a39d9523d7c41bdc929618eb095 Reviewed-on: https://go-review.googlesource.com/102619 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 711a373 commit ad0ebc3

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/cmd/go/go_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5960,3 +5960,19 @@ func TestFilepathUnderCwdFormat(t *testing.T) {
59605960
tg.run("test", "-x", "-cover", "log")
59615961
tg.grepStderrNot(`\.log\.cover\.go`, "-x output should contain correctly formatted filepath under cwd")
59625962
}
5963+
5964+
// Issue 24396.
5965+
func TestDontReportRemoveOfEmptyDir(t *testing.T) {
5966+
tg := testgo(t)
5967+
defer tg.cleanup()
5968+
tg.parallel()
5969+
tg.tempFile("src/a/a.go", `package a`)
5970+
tg.setenv("GOPATH", tg.path("."))
5971+
tg.run("install", "-x", "a")
5972+
tg.run("install", "-x", "a")
5973+
// The second install should have printed only a WORK= line,
5974+
// nothing else.
5975+
if bytes.Count(tg.stdout.Bytes(), []byte{'\n'})+bytes.Count(tg.stderr.Bytes(), []byte{'\n'}) > 1 {
5976+
t.Error("unnecessary output when installing installed package")
5977+
}
5978+
}

src/cmd/go/internal/work/exec.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,11 @@ func BuildInstallFunc(b *Builder, a *Action) (err error) {
11361136
func (b *Builder) cleanup(a *Action) {
11371137
if !cfg.BuildWork {
11381138
if cfg.BuildX {
1139-
b.Showcmd("", "rm -r %s", a.Objdir)
1139+
// Don't say we are removing the directory if
1140+
// we never created it.
1141+
if _, err := os.Stat(a.Objdir); err == nil || cfg.BuildN {
1142+
b.Showcmd("", "rm -r %s", a.Objdir)
1143+
}
11401144
}
11411145
os.RemoveAll(a.Objdir)
11421146
}

0 commit comments

Comments
 (0)