Commit ad0ebc39 authored by Ian Lance Taylor's avatar Ian Lance Taylor

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/102619Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 711a373c
......@@ -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")
}
}
......@@ -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)
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment