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: several commands require the build cache but don't use it #39882

Open
mvdan opened this issue Jun 26, 2020 · 6 comments
Open

cmd/go: several commands require the build cache but don't use it #39882

mvdan opened this issue Jun 26, 2020 · 6 comments
Labels
GoCommand cmd/go help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@mvdan
Copy link
Member

mvdan commented Jun 26, 2020

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).

@mvdan
Copy link
Member Author

mvdan commented Jun 26, 2020

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?

@jayconrod
Copy link
Contributor

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.

@jayconrod jayconrod added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 29, 2020
@jayconrod jayconrod added this to the Go1.16 milestone Jun 29, 2020
@jayconrod jayconrod self-assigned this Jun 29, 2020
@gopherbot
Copy link

Change https://golang.org/cl/240548 mentions this issue: cmd/go/internal/modload: don't initialize build cache

@jayconrod
Copy link
Contributor

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.

@jayconrod jayconrod changed the title cmd/go: mod edit always requires the build cache to be writeable cmd/go: several commands require the build cache but don't use it Jun 30, 2020
@jayconrod jayconrod added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. modules labels Jun 30, 2020
@mvdan
Copy link
Member Author

mvdan commented Jun 30, 2020

Neat :) If those other changes would be similarly small enough, perhaps we can label this "help wanted".

gopherbot pushed a commit that referenced this issue Aug 14, 2020
modload.Init initialized the build cache with the intent of providing
a better error message in Go 1.12, when the build cache became
mandatory (in module mode, packages aren't installed outside the build
cache). Unfortunately, this didn't provide a more descriptive error
(the cache calls base.Fatalf with its own message), and it caused
errors for commands that don't use the cache (like 'go mod edit').

This CL removes the cache initialization from modload.Init. The
builder will initialize it when it's needed.

For #39882

Change-Id: Ibc01ae4e59358dcd08a07ffc97bf556514d0366f
Reviewed-on: https://go-review.googlesource.com/c/go/+/240548
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
@jayconrod jayconrod modified the milestones: Go1.16, Go1.17 Jan 6, 2021
@ianlancetaylor
Copy link
Contributor

Are we going to do anything here for 1.17? Thanks.

@jayconrod jayconrod modified the milestones: Go1.17, Backlog May 3, 2021
@jayconrod jayconrod removed their assignment May 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants