Skip to content

Commit

Permalink
cmd/go: skip package loading if explicitly cleaning a cache
Browse files Browse the repository at this point in the history
Fixes #28680
Fixes #29925

Change-Id: I9f7effb3e7743b96b0b8a797d6e1044b39d9b86b
Reviewed-on: https://go-review.googlesource.com/c/go/+/167717
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
  • Loading branch information
Bryan C. Mills committed Mar 15, 2019
1 parent cb8054a commit 9238a8f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/cmd/go/alldocs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions src/cmd/go/internal/clean/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ The go command builds most objects in a temporary directory,
so go clean is mainly concerned with object files left by other
tools or by manual invocations of go build.
Specifically, clean removes the following files from each of the
If a package argument is given or the -i or -r flag is set,
clean removes the following files from each of the
source directories corresponding to the import paths:
_obj/ old object directory, left from Makefiles
Expand Down Expand Up @@ -105,7 +106,16 @@ func init() {
}

func runClean(cmd *base.Command, args []string) {
if len(args) > 0 || !modload.Enabled() || modload.HasModRoot() {
// golang.org/issue/29925: only load packages before cleaning if
// either the flags and arguments explicitly imply a package,
// or no other target (such as a cache) was requested to be cleaned.
cleanPkg := len(args) > 0 || cleanI || cleanR
if (!modload.Enabled() || modload.HasModRoot()) &&
!cleanCache && !cleanModcache && !cleanTestcache {
cleanPkg = true
}

if cleanPkg {
for _, pkg := range load.PackagesAndErrors(args) {
clean(pkg)
}
Expand Down
5 changes: 2 additions & 3 deletions src/cmd/go/testdata/script/mod_clean_cache.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ go clean -r -modcache
! exists ../replaced/test.out # BUG: should still exist

# 'go clean -modcache' should not download anything before cleaning.
# BUG(golang.org/issue/28680): Today, it does.
go mod edit -require rsc.io/quote@v1.99999999.0-not-a-real-version
! go clean -modcache # BUG: should succeed
stderr 'finding rsc.io' # BUG: should not resolve module
go clean -modcache
! stderr 'finding rsc.io'
go mod edit -droprequire rsc.io/quote

-- go.mod --
Expand Down

0 comments on commit 9238a8f

Please sign in to comment.