Skip to content

Commit b8f42d7

Browse files
committed
cmd/go: move module cache from $GOPATH/src/mod to $GOPATH/pkg/mod
Using $GOPATH/src/mod confuses too many tools. $GOPATH/pkg/mod seems better for now. It's also next to dep's cache, $GOPATH/pkg/dep. If we do eliminate GOPATH/pkg for holding .a files (#4719) then we could still keep it around for pkg/mod. (Or we could move the module cache again then.) Fixes #26401. Fixes #26635. Change-Id: I18f7da216ed9f490eded3c00d837fb086ae5b6a4 Reviewed-on: https://go-review.googlesource.com/126755 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Rob Pike <r@golang.org>
1 parent 27e546b commit b8f42d7

18 files changed

+120
-101
lines changed

src/cmd/go/alldocs.go

+65-46
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/go/internal/clean/clean.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ func runClean(cmd *base.Command, args []string) {
153153
}
154154

155155
if cleanModcache {
156-
if modfetch.SrcMod == "" {
156+
if modfetch.PkgMod == "" {
157157
base.Fatalf("go clean -modcache: no module cache")
158158
}
159-
if err := removeAll(modfetch.SrcMod); err != nil {
159+
if err := removeAll(modfetch.PkgMod); err != nil {
160160
base.Errorf("go clean -modcache: %v", err)
161161
}
162162
}

src/cmd/go/internal/help/helpdoc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ See https://golang.org/doc/code.html for an example.
377377
GOPATH and Modules
378378
379379
When using modules, GOPATH is no longer used for resolving imports.
380-
However, it is still used to store downloaded source code (in GOPATH/src/mod)
380+
However, it is still used to store downloaded source code (in GOPATH/pkg/mod)
381381
and compiled commands (in GOPATH/bin).
382382
383383
Internal Directories

src/cmd/go/internal/load/pkg.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ func LoadImport(path, srcDir string, parent *Package, stk *ImportStack, importPo
434434

435435
if strings.HasPrefix(path, "mod/") {
436436
// Paths beginning with "mod/" might accidentally
437-
// look in the module cache directory tree in $GOPATH/src/mod/.
437+
// look in the module cache directory tree in $GOPATH/pkg/mod/.
438438
// This prefix is owned by the Go core for possible use in the
439439
// standard library (since it does not begin with a domain name),
440440
// so it's OK to disallow entirely.

src/cmd/go/internal/modconv/convert_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func testMain(m *testing.M) int {
3939
log.Fatal(err)
4040
}
4141
defer os.RemoveAll(dir)
42-
modfetch.SrcMod = filepath.Join(dir, "src/mod")
42+
modfetch.PkgMod = filepath.Join(dir, "pkg/mod")
4343
codehost.WorkRoot = filepath.Join(dir, "codework")
4444

4545
return m.Run()

src/cmd/go/internal/modfetch/cache.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ import (
2222

2323
var QuietLookup bool // do not print about lookups
2424

25-
var SrcMod string // $GOPATH/src/mod; set by package modload
25+
var PkgMod string // $GOPATH/pkg/mod; set by package modload
2626

2727
func cacheDir(path string) (string, error) {
28-
if SrcMod == "" {
29-
return "", fmt.Errorf("internal error: modfetch.SrcMod not set")
28+
if PkgMod == "" {
29+
return "", fmt.Errorf("internal error: modfetch.PkgMod not set")
3030
}
3131
enc, err := module.EncodePath(path)
3232
if err != nil {
3333
return "", err
3434
}
35-
return filepath.Join(SrcMod, "cache/download", enc, "/@v"), nil
35+
return filepath.Join(PkgMod, "cache/download", enc, "/@v"), nil
3636
}
3737

3838
func CachePath(m module.Version, suffix string) (string, error) {
@@ -54,8 +54,8 @@ func CachePath(m module.Version, suffix string) (string, error) {
5454
}
5555

5656
func DownloadDir(m module.Version) (string, error) {
57-
if SrcMod == "" {
58-
return "", fmt.Errorf("internal error: modfetch.SrcMod not set")
57+
if PkgMod == "" {
58+
return "", fmt.Errorf("internal error: modfetch.PkgMod not set")
5959
}
6060
enc, err := module.EncodePath(m.Path)
6161
if err != nil {
@@ -71,7 +71,7 @@ func DownloadDir(m module.Version) (string, error) {
7171
if err != nil {
7272
return "", err
7373
}
74-
return filepath.Join(SrcMod, enc+"@"+encVer), nil
74+
return filepath.Join(PkgMod, enc+"@"+encVer), nil
7575
}
7676

7777
// A cachingRepo is a cache around an underlying Repo,
@@ -287,7 +287,7 @@ func readDiskStat(path, rev string) (file string, info *RevInfo, err error) {
287287
// just to find out about a commit we already know about
288288
// (and have cached under its pseudo-version).
289289
func readDiskStatByHash(path, rev string) (file string, info *RevInfo, err error) {
290-
if SrcMod == "" {
290+
if PkgMod == "" {
291291
// Do not download to current directory.
292292
return "", nil, errNotCached
293293
}

src/cmd/go/internal/modfetch/fetch.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ var downloadCache par.Cache
2828
// local download cache and returns the name of the directory
2929
// corresponding to the root of the module's file tree.
3030
func Download(mod module.Version) (dir string, err error) {
31-
if SrcMod == "" {
31+
if PkgMod == "" {
3232
// Do not download to current directory.
33-
return "", fmt.Errorf("missing modfetch.SrcMod")
33+
return "", fmt.Errorf("missing modfetch.PkgMod")
3434
}
3535

3636
// The par.Cache here avoids duplicate work but also
@@ -53,7 +53,7 @@ func Download(mod module.Version) (dir string, err error) {
5353
if _, err := os.Stat(zipfile); err == nil {
5454
// Use it.
5555
// This should only happen if the mod/cache directory is preinitialized
56-
// or if src/mod/path was removed but not src/mod/cache/download.
56+
// or if pkg/mod/path was removed but not pkg/mod/cache/download.
5757
fmt.Fprintf(os.Stderr, "go: extracting %s %s\n", mod.Path, mod.Version)
5858
} else {
5959
if err := os.MkdirAll(filepath.Dir(zipfile), 0777); err != nil {
@@ -200,7 +200,7 @@ func readGoSum(file string, data []byte) {
200200

201201
// checkSum checks the given module's checksum.
202202
func checkSum(mod module.Version) {
203-
if SrcMod == "" {
203+
if PkgMod == "" {
204204
// Do not use current directory.
205205
return
206206
}
@@ -264,7 +264,7 @@ func checkOneSum(mod module.Version, h string) {
264264
// Sum returns the checksum for the downloaded copy of the given module,
265265
// if present in the download cache.
266266
func Sum(mod module.Version) string {
267-
if SrcMod == "" {
267+
if PkgMod == "" {
268268
// Do not use current directory.
269269
return ""
270270
}

src/cmd/go/internal/modfetch/proxy.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ archive.
7777
7878
Even when downloading directly from version control systems,
7979
the go command synthesizes explicit info, mod, and zip files
80-
and stores them in its local cache, $GOPATH/src/mod/cache/download,
80+
and stores them in its local cache, $GOPATH/pkg/mod/cache/download,
8181
the same as if it had downloaded them directly from a proxy.
8282
The cache layout is the same as the proxy URL space, so
83-
serving $GOPATH/src/mod/cache/download at (or copying it to)
83+
serving $GOPATH/pkg/mod/cache/download at (or copying it to)
8484
https://example.com/proxy would let other users access those
8585
cached module versions with GOPROXY=https://example.com/proxy.
8686
`,

src/cmd/go/internal/modload/help.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ GOPATH/src and itself contains a go.mod file or is below a directory
5050
containing a go.mod file.
5151
5252
In module-aware mode, GOPATH no longer defines the meaning of imports
53-
during a build, but it still stores downloaded dependencies (in GOPATH/src/mod)
53+
during a build, but it still stores downloaded dependencies (in GOPATH/pkg/mod)
5454
and installed commands (in GOPATH/bin, unless GOBIN is set).
5555
5656
Defining a module

0 commit comments

Comments
 (0)