// 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
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
}
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)
}
! 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 --