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: building Go distribution from source fails with "missing $GOPATH" #30960

Closed
ianlancetaylor opened this issue Mar 20, 2019 · 5 comments

Comments

Projects
None yet
3 participants
@ianlancetaylor
Copy link
Contributor

commented Mar 20, 2019

On an amd64 GNU/Linux system with no GOPATH set in the environment, and with the Go source code at $HOME/go so that the default GOPATH setting does not work, running make.bash fails with

Building Go cmd/dist using /usr/local/google/home/iant/go1.4.
Building Go toolchain1 using /usr/local/google/home/iant/go1.4.
Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1.
Building Go toolchain2 using go_bootstrap and Go toolchain1.
missing $GOPATH
go tool dist: FAILED: /usr/local/google/home/iant/go/pkg/tool/linux_amd64/go_bootstrap install -gcflags=all= -ldflags=all= -i cmd/asm cmd/cgo cmd/compile cmd/link: exit status 1

@ianlancetaylor ianlancetaylor added this to the Go1.13 milestone Mar 20, 2019

@jayconrod jayconrod self-assigned this Mar 21, 2019

@jayconrod

This comment has been minimized.

Copy link
Contributor

commented Mar 21, 2019

@ianlancetaylor This happens because modules are on by default in go_bootstrap. We need GOPATH very early to initialize the module cache. The behavior of GOPATH defaulting to $HOME/go comes from go/build.defaultGOPATH: it specifically avoids using GOROOT.

@andybons mentioned a similar error yesterday building the internal toolchain. I'm not sure what the target was, but is it possible to check out the source code somewhere other than $HOME/go? Even if we work around this by creating a temporary GOPATH in make.bash, the toolchain won't work at all until GOPATH is set explicitly.

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor Author

commented Mar 21, 2019

So you are saying that we now require a valid GOPATH in order to do any Go builds at all? Seems slightly ironic since one of the goals of the module system is to get away from GOPATH. But OK. I guess we just need to document this.

@jayconrod

This comment has been minimized.

Copy link
Contributor

commented Mar 21, 2019

Yep, we still need a place to put $GOPATH/bin and $GOPATH/pkg/mod. The former can be set explicitly with GOBIN, but there's no other way to set the latter.

I'll update documentation in make.bash and emit the error earlier in dist.

@jayconrod

This comment has been minimized.

Copy link
Contributor

commented Mar 21, 2019

I take it back. It looks like dist is already setting GOCACHE to an temporary directory within GOROOT in order to avoid depending on anything existing outside GOROOT. We can do the same with GOPATH.

GOPATH may still need to be set to something different than GOROOT after the toolchain is built, but at least building the toolchain won't be any more complicated.

@gopherbot

This comment has been minimized.

Copy link

commented Mar 21, 2019

Change https://golang.org/cl/168697 mentions this issue: cmd/dist: set GOPATH to internal directory during build

@gopherbot gopherbot closed this in 6e7bc02 Mar 25, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.