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

build: spurious missing $GOPATH error #43938

rsc opened this issue Jan 27, 2021 · 3 comments

build: spurious missing $GOPATH error #43938

rsc opened this issue Jan 27, 2021 · 3 comments


Copy link

@rsc rsc commented Jan 27, 2021

make.bash (and friends) should not need GOPATH to be set.
Right now it is being set implicitly, which is good enough.
But if we make it impossible to set implicitly, make.bash fails.
It should not.

$ HOME='' GOPATH='' ./make.bash
missing $GOPATH

/cc @jayconrod @matloob @bcmills

@rsc rsc added the NeedsFix label Jan 27, 2021
@rsc rsc added this to the Go1.17 milestone Jan 27, 2021
Copy link
Contributor Author

@rsc rsc commented Jan 27, 2021

Shorter repro case:

HOME='' GOPATH='' go env
Copy link
Contributor Author

@rsc rsc commented Jan 27, 2021

Another fun fact: run.bat (only!) clears GOPATH, and defaultGOPATH returns an empty string if the default GOPATH comes out the same as GOROOT.

So while I have no problems at all using GOROOT=$HOME/go and GOPATH=$HOME on my Unix systems, if I do the equivalent on Unix, I can't all.bat or run.bat because the cleared GOPATH drops to the default, which comes out equal to my GOROOT, so it gets cleared too, and then we hit the missing $GOPATH fatal error.

The fatal error in cmd/go should still be fixed, but now that there's a non-empty default GOPATH, the clearing in run.bat is misleading at best and can be removed too. I'll do that.

Copy link

@gopherbot gopherbot commented Feb 2, 2021

Change mentions this issue: build: do not clear GOPATH in run.bat

gopherbot pushed a commit that referenced this issue Feb 19, 2021
We used to clear GOPATH in all the build scripts.
Clearing GOPATH is misleading at best, since you just end up
with the default GOPATH (%USERPROFILE%\go on Windows).
Unless that's your GOROOT, in which case you end up with a
fatal error from the go command (#43938).

run.bash changed to setting GOPATH=/dev/null, which has no
clear analogue on Windows.

run.rc still clears GOPATH.

Change them all to set GOPATH to a non-existent directory
/nonexist-gopath or c:\nonexist-gopath.

Change-Id: I51edd66d37ff6a891b0d0541d91ecba97fbbb03d
Trust: Russ Cox <>
Trust: Jason A. Donenfeld <>
Reviewed-by: Cherry Zhang <>
Reviewed-by: Alex Brainman <>
Reviewed-by: Jason A. Donenfeld <>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants