-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: assume GOPATH=$HOME/go if not set #17262
Comments
I like it, but do we have any specific preference for "gocode" and not something like "gopath"? |
How many people already use GOPATH=$HOME/gocode? It seems to me not many. That suggests it is the wrong default. |
"gocode" will have search engine and other confusion with the popular tool github.com/nsf/gocode. |
Do we have any information about what most people do? I use GOPATH=$HOME/gopath myself. |
Thumbs up here if you currently use GOPATH=$HOME |
Thumbs up here if you currently use GOPATH=$HOME/gopath |
Thumbs up here if you currently use GOPATH=$HOME/gocode |
Should I do a twitter poll on @golang? |
@campoy, sounds good. Probably better than inviting everybody to this bug. |
How about $HOME/go (which is what I use). |
See also : http://go-talks.appspot.com/github.com/freeformz/talks/20160712_gophercon/talk.slide#7 $HOME: 8.9% I really wish I had split out more options for this one. |
Voting started: https://twitter.com/golang/status/781189567437164544 On Wed, Sep 28, 2016, 10:51 AM Edward Muller [email protected]
|
$HOME/go is conflicting with the path go source code (go.googlesource.com/go) is often checked out. It is bad that the community blessed this location as a default for GOPATH :( I worry if someone forgets to set their GOPATH and runs the go tool, it will mess their current development directory. |
@rakyll to each their own, just wanted to indicate what I and many others use. go.googlesource.com/go is checked out in /usr/local/go.git on my system. |
For the record I use |
@freeformz, I guess we don't have to care about the existing canonical paths that are outside of $HOME. The default for GOPATH is going to be in $HOME somewhere and the minimal requirement should be that it doesn't conflict with any critical existing path. $HOME/gocode sounds alien to me but it could be a very good choice. |
The point being, it matters less what the default is, just that there is one. |
It does matter what the default is, because setting this default will essentially make it how everyone new to Go is working a few years from now. The go command goes out of its way not to get confused when GOPATH=$GOROOT explicitly; I'm sure the same logic can be made to apply to am implicit setting as well. So I'm not too worried about smashing $HOME/go accidentally. I still wonder if instead of a fixed default we should be auto-sniffing the current directory's parents to figure out where GOPATH is. This is what many source tools do these days (for example, every version control system), so it's a concept people would understand. And it doesn't force them to use one directory name or to have only one GOPATH workspace. But we might as well have that discussion on the original issue. |
@rsc I'd love that default to be
To be clear, I wasn't trying to be flippant when I said
Rather trying to emphasise the goal of this proposal is to have the go tool use a default value for I'm 👎 on auto sniffing because it fails a major use case, which is:
|
A default value of |
Sounds great.
Not on darwin. |
If this is for newcomers, I would advise against |
@mvdan I understand and your reaction was why I did not propose If I personally want to set my |
There is no default HOME variable on Windows. What do you propose to do on Windows?
I am always worried about having $GOPATH/bin in my PATH. Alex |
I'm not an experienced windows user, but I assume there is some notion of a base path where documents and settings are stored. For the purpose of this discussion assume that I'm talking about that path in the context of windows users. If no such path exists, assume C:/gocode. Wrt to my comment on GOPATH=$HOME, while this is and will continue to be my personal preference, I recognise that this is a contentious option for a default value and as such did not suggest it as the proposed value. |
My proposed behavior for this change: Environment variables
> unset GOPATH
> unset HOME
> go env GOPATH
> unset GOPATH
> go env GOPATH
/Users/campoy/go GOPATH creationCurrently if The only change is that if
> unset GOPATH
> unset HOME
> go get github.com/golang/example/hello
package github.com/golang/example/hello: cannot download, $GOPATH not set. For more details see: 'go help gopath'
👎
> unset GOPATH
> go get github.com/golang/example/hello
warning: GOPATH is not set, creating directory /Users/campoy/go. See 'go help gopath' for more information
👍
> unset GOPATH
> touch ~/go
> go get github.com/golang/example/hello
package github.com/golang/example/hello: can't use GOPATH at /Users/campoy/go: it is not a directory
👎
> unset GOPATH
> mkdir ~/go
> go get github.com/golang/example/hello
👍 > unset GOPATH
> mkdir -p ~/go/src
> touch ~/go/others
> go get github.com/golang/example/hello
👍
> unset GOPATH
> mkdir ~/go
> touch ~/go/others
> go get github.com/golang/example/hello
package github.com/golang/example/hello: can't use GOPATH at /Users/campoy/go: it is not empty, and no 'src' was found
👎 So only a new warning is included whenever a directory is created using a default |
@campoy the behavior proposal looks great. But again as an advanced user I want to know how many of us seriously use Since I work on multiple projects I usually do something like this:
|
@jinmatt If you don't like |
Thank you for the design sketch.
It's not a warning: warnings are bad. On the other hand if the create fails then you might well want to print
Both of those messages can be printed regardless of whether GOPATH is inferred or set explicitly.
Edit: pretend that Github markdown didn't completely screw this up. |
@campoy Regarding the It just seems simpler to explain if $HOME/go/src gets created on the first go get (or $GOPATH/src if that environment variable is set) |
Today, when GOPATH is set, the necessary directories are created, unconditionally, as needed. |
Whenever GOPATH is not defined in the environment, use $HOME/go as its default value. For Windows systems use %USERPROFILE%/go and $home/go for plan9. The choice of these environment variables is based on what Docker currently does. The os/user package is not used to avoid having a cgo dependency. Updates #17262. Documentation changes forthcoming. Change-Id: I6368fbfbc5afda99d6e64c35c1980076fcf45344 Reviewed-on: https://go-review.googlesource.com/32019 TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Russ Cox <[email protected]>
CL https://golang.org/cl/33356 mentions this issue. |
CL https://golang.org/cl/33730 mentions this issue. |
This avoids the need to have GOPATH set and is in line with how Go itself behaves, see golang/go#17262. While at it, make the workspace directory check a bit stricter by really checking for a directory.
As of Go v1.8, $HOME/go is the default $GOPATH. See golang/go#17262 for the discussion.
This proposal is a simplification of #12488.
In short, if the user has not set
$GOPATH
in their environment thego
tool will default to a value ofGOPATH=$HOME/gocode
.Rationale
At the moment all the documentation we have says "you have to set a GOPATH", then people get distracted and upset because they don't understand why they have to do this.
By choosing a default GOPATH, we can make our documentation easier because we can say things like
will check out the
github.com/foo/bar
repo into$HOME/gocode/src/github.com/foo/bar
.We don't need to distract newcomers with having to set an env var, all we need to do is put a little parenthetical note at the bottom of the page
Compatibility
This proposal only changes the experience for newcomers who have not chosen to set a
$GOPATH
variable. For anyone using Go 1.1-1.7 today, your experience will be unchanged as you are currently required to set$GOPATH
.The text was updated successfully, but these errors were encountered: