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: clarify error from 'go install' when arguments have mismatched versions and paths #51196

Closed
rittneje opened this issue Feb 14, 2022 · 5 comments
Labels
FrozenDueToAge GoCommand cmd/go help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@rittneje
Copy link

rittneje commented Feb 14, 2022

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

$ go version
1.17.7

Does this issue reproduce with the latest release?

Yes

What did you do?

go install github.com/maxbrunsfeld/counterfeiter/v6@v6.4.1 golang.org/x/tools/cmd/goimports@v0.1.9

What did you expect to see?

It should install both binaries without issue.

What did you see instead?

go install: golang.org/x/tools/cmd/goimports@v0.1.9: all arguments must have the same version (@v6.4.1)

This used to work in the pre-mod days - I could install multiple unrelated binaries from local paths without issue. This seems like an arbitrary and unnecessary restriction. I shouldn't need to run the go command multiple times.

@dmitshur dmitshur added the GoCommand cmd/go label Feb 14, 2022
@dmitshur
Copy link
Contributor

dmitshur commented Feb 15, 2022

Thanks for the report.

As far as I know this is working as intended, but one of @bcmills, @matloob, @jayconrod may have more up to date information, or link to a better existing source of past discussion.

It's still possible to install arbitrary local commands with go install cmd/a cmd/b syntax as it was in GOPATH mode. The "@​version" syntax is new to module mode, and it has additional restrictions, documented at https://pkg.go.dev/cmd/go#hdr-Compile_and_install_packages_and_dependencies:

To eliminate ambiguity about which module versions are used in the build, the arguments must satisfy the following constraints:

  • All arguments must refer to packages in the same module at the same version.

Making it work for multiple modules at different versions was considered during the design of this feature, but it was decided that installing unrelated commands from different modules will need multiple go install cmd@version invocations. Note that it is possible to install multiple commands from a single module version in one invocation.

I'll close this because the go command is working as intended and documented, but feel free to reopen or comment if I've missed something.

@rittneje
Copy link
Author

@dmitshur Definitely I think the order of checks (same version and same module) should be reversed. Because right now the error message implies that if goimports and counterfeiter were coincidentally the same version then it would work, which makes it seem especially arbitrary.

@bcmills bcmills reopened this Feb 15, 2022
@bcmills bcmills closed this as completed Feb 15, 2022
@bcmills
Copy link
Member

bcmills commented Feb 15, 2022

Hrm. We can tell that the versions are different in this case without doing any lookups on the network or in the module cache. I suppose that we could technically prove that the two packages are from separate modules in this case too, but in general that's trickier if their paths overlap.

@rittneje
Copy link
Author

@bcmills Maybe as a simpler solution, the error can be changed to align with the statement from the docs: "all arguments must refer to packages in the same module at the same version".

@bcmills bcmills reopened this Feb 16, 2022
@bcmills bcmills changed the title cmd/go: cannot install multiple unrelated binaries at once cmd/go: clarify error from 'go install' when arguments have mismatched versions and paths Feb 16, 2022
@bcmills bcmills added help wanted NeedsFix The path to resolution is known, but the work has not been done. labels Feb 16, 2022
@bcmills bcmills added this to the Backlog milestone Feb 16, 2022
@gopherbot
Copy link

Change https://go.dev/cl/388154 mentions this issue: cmd/go: clarify error from 'go install' when arguments have mismatched versions and paths

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge GoCommand cmd/go help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants