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
Closed
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@ianlancetaylor
Copy link
Contributor

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 NeedsFix The path to resolution is known, but the work has not been done. release-blocker labels Mar 20, 2019
@ianlancetaylor ianlancetaylor added this to the Go1.13 milestone Mar 20, 2019
@jayconrod jayconrod self-assigned this Mar 21, 2019
@jayconrod
Copy link
Contributor

@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
Copy link
Contributor Author

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link

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

@golang golang locked and limited conversation to collaborators Mar 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

No branches or pull requests

3 participants