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 run produces indirect dependencies in go.mod #26483

Closed
mwf opened this issue Jul 19, 2018 · 4 comments
Closed

cmd/go: go run produces indirect dependencies in go.mod #26483

mwf opened this issue Jul 19, 2018 · 4 comments

Comments

@mwf
Copy link

mwf commented Jul 19, 2018

What version of Go are you using (go version)?

Latest go devel: go version devel +d278f09333 Thu Jul 19 05:40:37 2018 +0000 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

cd `mktemp -d`
curl -sS https://swtch.com/hello.go >hello.go
go mod -init -module=example.com/test
go run hello.go
cat go.mod

What did you expect to see?

go.mod

module example.com/test

require rsc.io/quote v1.5.2

What did you see instead?

module example.com/test

require rsc.io/quote v1.5.2 // indirect

It's OK to see // indirect if we use go get rsc.io/quote but it's a little bit strange to see this artifact after go run.

I believe go run should work exactly like go build and resolve the imports with go mod -sync implicitly.

@bcmills
Copy link
Contributor

bcmills commented Jul 19, 2018

I believe go run should work exactly like go build and resolve the imports with go mod -sync implicitly.

Note that go build does not do the same thing as go mod -sync: it will add modules as needed (because that can be done locally), but won't remove them (because that requires a broader analysis of transitive imports).

@mwf
Copy link
Author

mwf commented Jul 19, 2018

Oh, sure, I forgot about this difference :)

My point is it's better for go run to behave like go build as everyone assume it.

@bcmills
Copy link
Contributor

bcmills commented Jul 19, 2018

go run allows you to run files that are not actually part of the package in normal use: for example, consider src/cmd/go/testdata/addmod.go:

// +build ignore

It seems reasonable to update the go.mod file with whatever you needed to actually build those files, but they really are “indirect”, in the sense that they are not included by any possible build that imports packages from your module. If you happened to run a file that is also part of a package, go mod -sync should remove the // indirect comment. (If that doesn't happen today, please reopen.)

@bcmills bcmills closed this as completed Jul 19, 2018
@mwf
Copy link
Author

mwf commented Jul 19, 2018

Perfectly makes sense, thank you!

@golang golang locked and limited conversation to collaborators Jul 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants