-
Notifications
You must be signed in to change notification settings - Fork 17.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/go: allow configuring module cache directory with GOMODCACHE
Adds a GOMODCACHE environment variable that's used by cmd/go to determine the location of the module cache. The default value of GOMODCACHE will be GOPATH[0]/pkg/mod, the default location of the module cache before this change. Replace the cmd/go/internal/modfetch.PkgMod variable which previously held the location of the module cache with the new cmd/go/internal/cfg.GOMODCACHE variable, for consistency with many of the other environment variables that affect the behavior of cmd/go. (Most of the changes in this CL are due to moving/renaming the variable.) The value of cfg.GOMODCACHE is now set using a variable initializer. It was previously set in cmd/go/internal/modload.Init. The location of GOPATH/pkg/sumdb is unchanged by this CL. While it was previously determined using the value of PkgMod, it now is determined independently dirctly from the value of GOPATH[0]. Fixes #34527 Change-Id: Id4d31d217b3507d6057c8ef7c52af1a0606603e4 Reviewed-on: https://go-review.googlesource.com/c/go/+/219538 Run-TryBot: Michael Matloob <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
- Loading branch information
Showing
15 changed files
with
115 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Test GOMODCACHE | ||
env GO111MODULE=on | ||
|
||
# Explicitly set GOMODCACHE | ||
env GOMODCACHE=$WORK/modcache | ||
go env GOMODCACHE | ||
stdout $WORK[/\\]modcache | ||
go get -d rsc.io/[email protected] | ||
exists $WORK/modcache/cache/download/rsc.io/quote/@v/v1.0.0.info | ||
grep '{"Version":"v1.0.0","Time":"2018-02-14T00:45:20Z"}' $WORK/modcache/cache/download/rsc.io/quote/@v/v1.0.0.info | ||
|
||
# Ensure GOMODCACHE doesn't affect location of sumdb, but $GOMODCACHE/cache/download/sumdb is still written | ||
exists $GOPATH/pkg/sumdb | ||
! exists $WORK/modcache/sumdb | ||
exists $WORK/modcache/cache/download/sumdb | ||
|
||
# Test that the default GOMODCACHE is $GOPATH[0]/pkg/mod | ||
env GOMODCACHE= | ||
go env GOMODCACHE | ||
stdout $GOPATH[/\\]pkg[/\\]mod | ||
go get -d rsc.io/[email protected] | ||
exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.0.0.info | ||
grep '{"Version":"v1.0.0","Time":"2018-02-14T00:45:20Z"}' $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.0.0.info | ||
|
||
# If neither GOMODCACHE or GOPATH are set, GOPATH defaults to the user's $HOME/go, so GOMODCACHE becomes $HOME/go/pkg/mod | ||
[windows] env USERPROFILE=$WORK/home # Ensure USERPROFILE is a valid path (rather than /no-home/ so we don't run into the logic that "uninfers" GOPATH in cmd/go/main.go | ||
[!windows] env HOME=$WORK/home | ||
env GOMODCACHE= | ||
env GOPATH= | ||
go env GOMODCACHE | ||
stdout $HOME[/\\]go[/\\]pkg[/\\]mod | ||
|
||
# If GOMODCACHE isn't set and GOPATH starts with the path list separator, it's an error. | ||
env GOMODCACHE= | ||
env GOPATH=${:}$WORK/this/is/ignored | ||
! go env GOMODCACHE | ||
stderr 'missing \$GOPATH' | ||
|
||
# If GOMODCACHE isn't set and GOPATH has multiple elements only the first is used. | ||
env GOMODCACHE= | ||
env GOPATH=$WORK/first/path${:}$WORK/this/is/ignored | ||
go env GOMODCACHE | ||
stdout $WORK[/\\]first[/\\]path[/\\]pkg[/\\]mod | ||
|
||
env GOMODCACHE=$WORK/modcache | ||
go mod download rsc.io/[email protected] | ||
exists $WORK/modcache/cache/download/rsc.io/quote/@v/v1.0.0.info | ||
|
||
# Test that the following work even with GO111MODULE=off | ||
env GO111MODULE=off | ||
|
||
# Cleaning modcache | ||
exists $WORK/modcache | ||
env GOMODCACHE=$WORK/modcache | ||
go clean -modcache | ||
! exists $WORK/modcache | ||
|
||
-- go.mod -- | ||
module m |
Oops, something went wrong.