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

proposal: cmd/go: go env GOBIN should always return a path #50714

Closed
mikesep opened this issue Jan 20, 2022 · 3 comments
Closed

proposal: cmd/go: go env GOBIN should always return a path #50714

mikesep opened this issue Jan 20, 2022 · 3 comments

Comments

@mikesep
Copy link

mikesep commented Jan 20, 2022

The go command seems to be missing a way to ask where programs are being installed. I'd like to propose that go env GOBIN should return the location where go install would install programs even when GOBIN hasn't been overridden.

Current behavior

$ unset GOPATH GOBIN

$ printf "GOPATH=[%s]\nGOBIN=[%s]\n" $(go env GOPATH) $(go env GOBIN)
GOPATH=[/Users/mikesep/go]
GOBIN=[]

$ env GOPATH=/tmp/gopath /bin/sh -c 'printf "GOPATH=[%s]\nGOBIN=[%s]\n" $(go env GOPATH) $(go env GOBIN)'
GOPATH=[/tmp/gopath]
GOBIN=[]

$ env GOBIN=/tmp/gobin /bin/sh -c 'printf "GOPATH=[%s]\nGOBIN=[%s]\n" $(go env GOPATH) $(go env GOBIN)'
GOPATH=[/Users/mikesep/go]
GOBIN=[/tmp/gobin]

$ env GOPATH=/tmp/gopath GOBIN=/tmp/gobin /bin/sh -c 'printf "GOPATH=[%s]\nGOBIN=[%s]\n" $(go env GOPATH) $(go env GOBIN)'
GOPATH=[/tmp/gopath]
GOBIN=[/tmp/gobin]

Proposed behavior

$ unset GOPATH GOBIN

$ printf "GOPATH=[%s]\nGOBIN=[%s]\n" $(go env GOPATH) $(go env GOBIN)
GOPATH=[/Users/mikesep/go]
GOBIN=[/Users/mikesep/go/bin]

$ env GOPATH=/tmp/gopath /bin/sh -c 'printf "GOPATH=[%s]\nGOBIN=[%s]\n" $(go env GOPATH) $(go env GOBIN)'
GOPATH=[/tmp/gopath]
GOBIN=[/tmp/gopath/bin]

$ # unchanged:
$ env GOBIN=/tmp/gobin /bin/sh -c 'printf "GOPATH=[%s]\nGOBIN=[%s]\n" $(go env GOPATH) $(go env GOBIN)'
GOPATH=[/Users/mikesep/go]
GOBIN=[/tmp/gobin]

$ # unchanged:
$ env GOPATH=/tmp/gopath GOBIN=/tmp/gobin /bin/sh -c 'printf "GOPATH=[%s]\nGOBIN=[%s]\n" $(go env GOPATH) $(go env GOBIN)'
GOPATH=[/tmp/gopath]
GOBIN=[/tmp/gobin]

In short, go env GOBIN would never return an empty string.

In investigating how this could be implemented, I was reminded that there is code in cmd/go that takes into account multi-part GOPATH values when figuring out where to install binaries. At first glance, I think we'd want to have go env GOBIN use the same logic.

@gopherbot gopherbot added this to the Proposal milestone Jan 20, 2022
@mikesep
Copy link
Author

mikesep commented Jan 20, 2022

If accepted, I'd be happy to work on the implementation of this feature.

@seankhliao
Copy link
Member

Duplicate of #42823

@seankhliao seankhliao marked this as a duplicate of #42823 Jan 20, 2022
@mikesep
Copy link
Author

mikesep commented Jan 20, 2022

Thanks @seankhliao, I missed that one. 😊

@golang golang locked and limited conversation to collaborators Jan 20, 2023
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