-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: add GOMODCACHE #34527
Comments
One unfortunate side of this proposal is that An alternative idea is to eventually re-define An alternative partial solution to point 2 is to stop explicitly declaring |
Thanks for making this proposal. I briefly recall conversations in the past that we might want to move the module cache out of $GOPATH/pkg eventually, but it's helpful to have something more actionable open. I would like to see the module cache to not be in GOPATH in the future. If it's viable, I think a better outcome is if we can do this without adding configuration. That may not be viable. |
I think we have multiple options if moving the module download cache is an option. For example:
Both of these options put the expensive and cheap caches in the same place by default, though. If we want to properly separate the moduel cache from the build cache, here's another idea:
|
CC @jayconrod |
Adding a Moving the default location of the module cache seems more disruptive. Should we have some logic that checks if |
I think if we're happy with adding an env var, we shouldn't worry about moving the default location right now. I only replied to that point to show some thoughts that might be helpful in the long term, if we do want to move it at some point. |
I found myself wanting a
Of course there is a workaround by creating a dummy |
Please don't move the default location of the download cache into GOCACHE. I understand why this would seem surprising at first, but cached compilation resuilts and cached downloaded source code are a bit different. The build cache ($GOCACHE, defaulting to $HOME/.cache/go-build) is for storing recent compilation results, so that if you need to do that exact compilation again, you can just reuse the file. The build cache holds entries that are like "if you run this exact compiler on these exact inputs. this is the output you'd get." If the answer is not in the cache, your build uses a little more CPU to run the compiler nstead of reusing the output. But you are guaranteed to be able to run the compiler instead, since you have the exact inputs and the compiler binary (or else you couldn't even look up the answer in the cache). The module cache ($GOPATH/src/mod, defaulting to $HOME/go/src/mod) is for storing downloaded source code, so that every build does not redownload the same code and does not require the network or the original code to be available. The module cache holds entries that are like "if you need to download mymodule@v1.2.3, here are the files you'd get." If the answer is not in the cache, you have to go out to the network. Maybe you don't have a network right now. Maybe the code has been deleted. It's not anywhere near guaranteed that you can redownload the sources and also get the same result. Hopefully you can, but it's not an absolute certainty like for the build cache. (The go.sum file will detect if you get a different answer on re-download, but knowing you got the wrong bits doesn't help you make progress on actually building your code. Also these paths end up in file-line information in binaries, so they show up in stack traces, and the like and feed into tools like text editors or debuggers that don't necessarily know how to trigger the right cache refresh.) I expect there are cron jobs or other tools that clean $HOME/.cache periodically. If part of the build cache got deleted, it would be no big deal, so it's fine to store the build cache there. But if downloaded source code got deleted unasked, I think that would potentially be quite surprising and problematic in various ways. That's why we store the source code in $GOPATH/src/mod, to keep it away from more expendable data. |
Adding GOMODCACHE seems fine to me, and @jayconrod said that too. @bcmills? |
Just to echo @rsc and my earlier comment: adding |
Agreed: a The non-parallel naming with |
As a quick drive-by thought, if we want to fix the inconsistency with |
An other value of |
Why not call it |
@h12w because everywhere in the docs it's called |
A module cache directory/path is a module directory/path. The word |
Since we can't use |
What @aofei said. We don't do |
I talked to @bcmills, @jayconrod, and @matloob (the team working on the go command) two weeks ago about this, but I forgot to summarize here. I think we all agree about the following. We should add GOMODCACHE, defaulting to GOPATH/pkg/mod. Setting it would redirect all current accesses in GOPATH/pkg/mod to GOMODCACHE instead. We should not move GOPATH/pkg/sumdb, nor make it controlled by GOMODCACHE. The module cache is just that: a cache. If the module cache is removed, it can safely be refilled by redownloading. During the redownloading, all the bits will be reverified using the checksum database, The one thing that makes all of this safe is the single file GOPATH/pkg/sumdb/sum.golang.org/latest. It contains the single hash that all of this other verification relies upon. It cannot be deleted without giving all that up. It therefore does not belong in the module cache next to all the deletable things. (That's why it's not.) CI/CD systems that want to point GOMODCACHE at a different directory should not need to worry about GOPATH/pkg/sumdb. As long as the repo being built has a complete go.sum, the go command will not do anything with the checksum database. I believe |
Based on the discussion above, it sounds like this is a likely accept. |
No change in consensus, so accepted. |
Change https://golang.org/cl/230537 mentions this issue: |
For #36568 For #34527 Change-Id: Ieea4b4a7644e9c957f48d08d2e172e39b571502f Reviewed-on: https://go-review.googlesource.com/c/go/+/230537 Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
For golang#36568 For golang#34527 Change-Id: Ieea4b4a7644e9c957f48d08d2e172e39b571502f Reviewed-on: https://go-review.googlesource.com/c/go/+/230537 Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
Change https://golang.org/cl/241275 mentions this issue: |
Updates #34527 Fixes #40089 Change-Id: Ie9c8573536e5c31e874d755f4d888ffc805b796f Reviewed-on: https://go-review.googlesource.com/c/go/+/241275 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
In Go 1.15 there's separate environment variable to control the cache locaiton: golang/go#34527, but as we're on Go 1.14 yet, we use compatible approach with `GOPATH/pkg` being cached across all Go-related build steps. This speeds up `go mod download` a lot when only some module dependencies got changed. Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
In Go 1.15 there's separate environment variable to control the cache locaiton: golang/go#34527, but as we're on Go 1.14 yet, we use compatible approach with `GOPATH/pkg` being cached across all Go-related build steps. This speeds up `go mod download` a lot when only some module dependencies got changed. Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
Summary
Add
GOMODCACHE
to control where the module download cache lives. Its default can continue to beGOPATH[0]/pkg/mod
, and the variable would be very similar and consistent withGOCACHE
.Description
The module download cache has lived in
GOPATH[0]/pkg/mod/
since it first appeared. It's understandable why it doesn't live underGOCACHE
, where the build cache is located; builds are generally fast and reliable if one has the source, but downloading a module from the internet isn't nearly as reliable.I also understand why it was put under
GOPATH
; until recently, it was the only persistent directory that Go made use of. That only changed in the last release, with the addition ofos.UserConfigDir()+"/go/env"
forgo env -w
.However, there's no way to configure where the module download cache is located. For example, this is useful in CI environments to place the build and module download caches somewhere that's persisted between builds.
The only way to store the download cache elsewhere is to move
GOPATH
entirely. This has several disadvantages:GOPATH
contains much more. For many users, it still contains code. For almost everyone, it also contains the installed binaries, unless they've setGOBIN
. It's too big of a knob to just change the location of the module download cache.Many environments explicitly set
GOPATH
, such as thegolang:1.13
image, meaning that we can't simplygo env -w GOPATH=/custom/path
just like we could withGOCACHE
. This makes the module download cache harder to deal with than the build cache, for no apparent reason.GOPATH
's future is uncertain; it might contain more in the future, or it might go away entirely. Relying on it to set the module download cache location is not a good long-term plan.This idea first came up in #31283, which was closed by its author. I left a comment there a while ago, but thought it would be better to open a new proposal.
The text was updated successfully, but these errors were encountered: