[go] cmd/go: go clean should not accept flags like -modcache with packages

69 views
Skip to first unread message

Gopher Robot (Gerrit)

unread,
Aug 30, 2022, 1:22:55 PM8/30/22
to xie cui, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Heschi Kreinick, Bryan Mills, Michael Matloob, Ian Lance Taylor, Russ Cox, golang-co...@googlegroups.com

Gopher Robot submitted this change.

View Change


Approvals: Bryan Mills: Looks good to me, approved; Run TryBots; Automatically submit change Heschi Kreinick: Looks good to me, but someone else must approve Gopher Robot: TryBots succeeded
cmd/go: go clean should not accept flags like -modcache with packages

For #53725

Change-Id: I99a85b437d5f918dba74c4eccefcf8087193646a
Reviewed-on: https://go-review.googlesource.com/c/go/+/425874
Run-TryBot: Bryan Mills <bcm...@google.com>
Auto-Submit: Bryan Mills <bcm...@google.com>
Reviewed-by: Heschi Kreinick <hes...@google.com>
TryBot-Result: Gopher Robot <go...@golang.org>
Reviewed-by: Bryan Mills <bcm...@google.com>
---
M src/cmd/go/internal/clean/clean.go
M src/cmd/go/testdata/script/clean_cache_n.txt
M src/cmd/go/testdata/script/clean_testcache.txt
M src/cmd/go/testdata/script/mod_clean_cache.txt
M src/cmd/go/testdata/script/test_fuzz_cache.txt
5 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/src/cmd/go/internal/clean/clean.go b/src/cmd/go/internal/clean/clean.go
index 37e126a..2417cc0 100644
--- a/src/cmd/go/internal/clean/clean.go
+++ b/src/cmd/go/internal/clean/clean.go
@@ -118,6 +118,23 @@
}

func runClean(ctx context.Context, cmd *base.Command, args []string) {
+ if len(args) > 0 {
+ cacheFlag := ""
+ switch {
+ case cleanCache:
+ cacheFlag = "-cache"
+ case cleanTestcache:
+ cacheFlag = "-testcache"
+ case cleanFuzzcache:
+ cacheFlag = "-fuzzcache"
+ case cleanModcache:
+ cacheFlag = "-modcache"
+ }
+ if cacheFlag != "" {
+ base.Fatalf("go: clean %s cannot be used with package arguments", cacheFlag)
+ }
+ }
+
// 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.
diff --git a/src/cmd/go/testdata/script/clean_cache_n.txt b/src/cmd/go/testdata/script/clean_cache_n.txt
index 4497b36..72f9abf 100644
--- a/src/cmd/go/testdata/script/clean_cache_n.txt
+++ b/src/cmd/go/testdata/script/clean_cache_n.txt
@@ -15,6 +15,9 @@
go clean -cache
! exists $GOCACHE/00

+! go clean -cache .
+stderr 'go: clean -cache cannot be used with package arguments'
+
-- main.go --
package main

diff --git a/src/cmd/go/testdata/script/clean_testcache.txt b/src/cmd/go/testdata/script/clean_testcache.txt
index b3f32fe..3f98602 100644
--- a/src/cmd/go/testdata/script/clean_testcache.txt
+++ b/src/cmd/go/testdata/script/clean_testcache.txt
@@ -8,6 +8,8 @@
go clean -testcache
go test x_test.go
! stdout 'cached'
+! go clean -testcache ../x
+stderr 'go: clean -testcache cannot be used with package arguments'

# golang.org/issue/29100: 'go clean -testcache' should succeed
# if the cache directory doesn't exist at all.
diff --git a/src/cmd/go/testdata/script/mod_clean_cache.txt b/src/cmd/go/testdata/script/mod_clean_cache.txt
index 01fbc38..2b8e820 100644
--- a/src/cmd/go/testdata/script/mod_clean_cache.txt
+++ b/src/cmd/go/testdata/script/mod_clean_cache.txt
@@ -35,6 +35,9 @@
! stderr 'finding rsc.io'
go mod edit -droprequire rsc.io/quote

+! go clean -modcache m
+stderr 'go: clean -modcache cannot be used with package arguments'
+
-- go.mod --
module m
-- m.go --
diff --git a/src/cmd/go/testdata/script/test_fuzz_cache.txt b/src/cmd/go/testdata/script/test_fuzz_cache.txt
index 19fb764..752ab3a 100644
--- a/src/cmd/go/testdata/script/test_fuzz_cache.txt
+++ b/src/cmd/go/testdata/script/test_fuzz_cache.txt
@@ -37,6 +37,9 @@
stdout 'new interesting: 0'
stdout 'total: 1'

+! go clean -fuzzcache example.com/y
+stderr 'go: clean -fuzzcache cannot be used with package arguments'
+
-- go.mod --
module example.com/y


To view, visit change 425874. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I99a85b437d5f918dba74c4eccefcf8087193646a
Gerrit-Change-Number: 425874
Gerrit-PatchSet: 4
Gerrit-Owner: xie cui <5235...@qq.com>
Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Heschi Kreinick <hes...@google.com>
Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
Gerrit-CC: Russ Cox <r...@golang.org>
Gerrit-MessageType: merged
Reply all
Reply to author
Forward
0 new messages