Commit 9238a8ff authored by Bryan C. Mills's avatar Bryan C. Mills

cmd/go: skip package loading if explicitly cleaning a cache

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: default avatarJay Conrod <jayconrod@google.com>
parent cb8054a6
...@@ -202,7 +202,8 @@ ...@@ -202,7 +202,8 @@
// so go clean is mainly concerned with object files left by other // so go clean is mainly concerned with object files left by other
// tools or by manual invocations of go build. // 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: // source directories corresponding to the import paths:
// //
// _obj/ old object directory, left from Makefiles // _obj/ old object directory, left from Makefiles
......
...@@ -33,7 +33,8 @@ The go command builds most objects in a temporary directory, ...@@ -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 so go clean is mainly concerned with object files left by other
tools or by manual invocations of go build. 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: source directories corresponding to the import paths:
_obj/ old object directory, left from Makefiles _obj/ old object directory, left from Makefiles
...@@ -105,7 +106,16 @@ func init() { ...@@ -105,7 +106,16 @@ func init() {
} }
func runClean(cmd *base.Command, args []string) { 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) { for _, pkg := range load.PackagesAndErrors(args) {
clean(pkg) clean(pkg)
} }
......
...@@ -30,10 +30,9 @@ go clean -r -modcache ...@@ -30,10 +30,9 @@ go clean -r -modcache
! exists ../replaced/test.out # BUG: should still exist ! exists ../replaced/test.out # BUG: should still exist
# 'go clean -modcache' should not download anything before cleaning. # '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 mod edit -require rsc.io/quote@v1.99999999.0-not-a-real-version
! go clean -modcache # BUG: should succeed go clean -modcache
stderr 'finding rsc.io' # BUG: should not resolve module ! stderr 'finding rsc.io'
go mod edit -droprequire rsc.io/quote go mod edit -droprequire rsc.io/quote
-- go.mod -- -- go.mod --
......
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