]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: skip package loading if explicitly cleaning a cache
authorBryan C. Mills <bcmills@google.com>
Thu, 14 Mar 2019 21:08:25 +0000 (17:08 -0400)
committerBryan C. Mills <bcmills@google.com>
Fri, 15 Mar 2019 12:51:21 +0000 (12:51 +0000)
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>
src/cmd/go/alldocs.go
src/cmd/go/internal/clean/clean.go
src/cmd/go/testdata/script/mod_clean_cache.txt

index d037d86bff20fcb653b44447cdb8b902667c41c5..55371c12159c015ba4db46e99dea3792944815fa 100644 (file)
 // 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
index 27121ed2ae679b1cfc155852065aca41622bfd3c..3389d5f18b591b49156f5742d3b9fa0f4853a3f2 100644 (file)
@@ -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
@@ -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)
                }
index a9519f9d9086c656219b8357a21dc53f2e96ee90..01fbc381e043b2ae6e543eb50d64f7d5e533d752 100644 (file)
@@ -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 --