Steps to repro:
docker run -i golang:1.15beta1 <<-SCRIPT
set -ex
go version
go env
mkdir /tmp/foo
cd /tmp/foo
go mod init test
go mod edit -go=1.13
HOME= GOCACHE= go mod edit -go=1.14
SCRIPT
I think this should succeed. go mod edit -go=X only has to modify a line in go.mod, it shouldn't require the build cache to exist or be writeable. However, that last command fails:
+ go mod edit -go=1.14
build cache is required, but could not be located: GOCACHE is not defined and neither $XDG_CACHE_HOME nor $HOME are defined
I encountered this while writing some tests, which are run in a temporary directory with a near-empty environment (partly to not pollute the user's $HOME and such).
Err, this is worse than I thought - I can't even do go list -m -json without a writable build cache:
> exec go list -m -json
[stderr]
failed to initialize build cache at /no-home/.cache/go-build: mkdir /no-home: permission denied
What am I missing?
Need to add a test case for go mod edit, but I expect CL 236563 will fix this. The new test covers go list -m and a couple other things.
Change https://golang.org/cl/240548 mentions this issue: cmd/go/internal/modload: don't initialize build cache
CL 236563 fixes a different issue.
I just mailed CL 240548, which should fix this for module commands that don't use the build cache.
There are a number of other commands that probably should work but don't, like go get -d and go list without -export or -compiled. That CL won't fix those, so I'll leave this issue open.
Neat :) If those other changes would be similarly small enough, perhaps we can label this "help wanted".