1
0
mirror of https://github.com/golang/go synced 2024-11-18 01:04:48 -07:00

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 <bradfitz@golang.org>
This commit is contained in:
Ian Lance Taylor 2018-03-27 10:29:06 -07:00
parent 711a373cc3
commit ad0ebc3994
2 changed files with 21 additions and 1 deletions

View 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")
}
}

View 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)
}