Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: go clean <package> downloads modules #32977

Open
hyangah opened this issue Jul 8, 2019 · 3 comments
Open

cmd/go: go clean <package> downloads modules #32977

hyangah opened this issue Jul 8, 2019 · 3 comments
Labels
modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@hyangah
Copy link
Contributor

hyangah commented Jul 8, 2019

#28680 is fixed and go clean --modcache command no longer donwloads modules before cleaning if no argument is given to the command.

Note however 'go clean' accepts packages parameter as an argument(which isn't relevant to -modcache but is still meaningful for other purposes of go clean). If they are given, go clean still downloads the modules and even updates the go.mod file.

$ go help clean
usage: go clean [clean flags] [build flags] [packages]
...
$ export GOPATH=$(mktemp -d)
$ go1.13beta1 clean -testcache -cache -modcache
$ go1.13beta1 mod init scratch
go: creating new go.mod: module scratch
$ go1.13beta1 clean  golang.org/x/text
go: finding golang.org/x/text v0.3.2
go: downloading golang.org/x/text v0.3.2
go: extracting golang.org/x/text v0.3.2
$ cat go.mod
module scratch

go 1.13

require golang.org/x/text v0.3.2 // indirect

And the go clean -modcache <package> behaves differently.

$ go1.13beta1 clean -modcache golang.org/x/text
$ go1.13beta1 clean -modcache golang.org/x/text
go: downloading golang.org/x/text v0.3.2
go: extracting golang.org/x/text v0.3.2
go: finding golang.org/x/text v0.3.2
@hyangah hyangah added the modules label Jul 8, 2019
@bcmills bcmills added this to the Go1.14 milestone Jul 8, 2019
@bcmills bcmills added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 8, 2019
@bcmills
Copy link
Contributor

bcmills commented Jul 8, 2019

Probably the best we could do here is to detect that the argument to clean is not in the main module and error out.

Per https://tip.golang.org/cmd/go/#hdr-Remove_object_files_and_cached_files:

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: […]

But of course we cannot remove files from the (read-only) module cache.

CC @jayconrod

@hitzhangjie
Copy link
Contributor

I have following project:

  • greeter
    |- go.mod: defines module a.b.c
    |- *.go

after I run go build it generates a.b.c, after I run go test it generates a.b.c.test.

But when I run go clean, a.b.c and a.b.c.test not removed, while in go 1.12.6 it works fine.

@bcmills
Copy link
Contributor

bcmills commented Sep 26, 2019

@hitzhangjie, that seems mostly unrelated to the issue reported here. If you are seeing something you believe to be a regression, please file a new issue with complete steps to reproduce it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants