Commit b8f42d74 authored by Russ Cox's avatar Russ Cox

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: default avatarBryan C. Mills <bcmills@google.com>
Reviewed-by: default avatarRob Pike <r@golang.org>
parent 27e546be
...@@ -130,8 +130,6 @@ ...@@ -130,8 +130,6 @@
// arguments to pass on each gccgo compiler/linker invocation. // arguments to pass on each gccgo compiler/linker invocation.
// -gcflags '[pattern=]arg list' // -gcflags '[pattern=]arg list'
// arguments to pass on each go tool compile invocation. // arguments to pass on each go tool compile invocation.
// -getmode mode
// module download mode to use. See 'go help modules' for more.
// -installsuffix suffix // -installsuffix suffix
// a suffix to use in the name of the package installation directory, // a suffix to use in the name of the package installation directory,
// in order to keep output separate from default builds. // in order to keep output separate from default builds.
...@@ -144,6 +142,9 @@ ...@@ -144,6 +142,9 @@
// -linkshared // -linkshared
// link against shared libraries previously created with // link against shared libraries previously created with
// -buildmode=shared. // -buildmode=shared.
// -mod mode
// module download mode to use: readonly, release, or vendor.
// See 'go help modules' for more.
// -pkgdir dir // -pkgdir dir
// install and load all packages from dir instead of the usual locations. // install and load all packages from dir instead of the usual locations.
// For example, when building with a non-standard configuration, // For example, when building with a non-standard configuration,
...@@ -642,8 +643,9 @@ ...@@ -642,8 +643,9 @@
// //
// // Source files // // Source files
// GoFiles []string // .go source files (excluding CgoFiles, TestGoFiles, XTestGoFiles) // GoFiles []string // .go source files (excluding CgoFiles, TestGoFiles, XTestGoFiles)
// CgoFiles []string // .go sources files that import "C" // CgoFiles []string // .go source files that import "C"
// IgnoredGoFiles []string // .go sources ignored due to build constraints // CompiledGoFiles []string // .go files presented to compiler (when using -compiled)
// IgnoredGoFiles []string // .go source files ignored due to build constraints
// CFiles []string // .c source files // CFiles []string // .c source files
// CXXFiles []string // .cc, .cxx and .cpp source files // CXXFiles []string // .cc, .cxx and .cpp source files
// MFiles []string // .m source files // MFiles []string // .m source files
...@@ -717,9 +719,10 @@ ...@@ -717,9 +719,10 @@
// The -json flag causes the package data to be printed in JSON format // The -json flag causes the package data to be printed in JSON format
// instead of using the template format. // instead of using the template format.
// //
// The -cgo flag causes list to set CgoFiles not to the original *.go files // The -compiled flag causes list to set CompiledGoFiles to the Go source
// importing "C" but instead to the translated files generated by the cgo // files presented to the compiler. Typically this means that it repeats
// command. // the files listed in GoFiles and then also adds the Go code generated
// by processing CgoFiles and SwigFiles.
// //
// The -deps flag causes list to iterate over not just the named packages // The -deps flag causes list to iterate over not just the named packages
// but also all their dependencies. It visits them in a depth-first post-order // but also all their dependencies. It visits them in a depth-first post-order
...@@ -740,6 +743,9 @@ ...@@ -740,6 +743,9 @@
// The -export flag causes list to set the Export field to the name of a // The -export flag causes list to set the Export field to the name of a
// file containing up-to-date export information for the given package. // file containing up-to-date export information for the given package.
// //
// The -find flag causes list to identify the named packages but not
// resolve their dependencies: the Imports and Deps lists will be empty.
//
// The -test flag causes list to report not only the named packages // The -test flag causes list to report not only the named packages
// but also their test binaries (for packages with tests), to convey to // but also their test binaries (for packages with tests), to convey to
// source code analysis tools exactly how test binaries are constructed. // source code analysis tools exactly how test binaries are constructed.
...@@ -759,8 +765,8 @@ ...@@ -759,8 +765,8 @@
// //
// By default, the lists GoFiles, CgoFiles, and so on hold names of files in Dir // By default, the lists GoFiles, CgoFiles, and so on hold names of files in Dir
// (that is, paths relative to Dir, not absolute paths). // (that is, paths relative to Dir, not absolute paths).
// The extra entries added by the -cgo and -test flags are absolute paths // The generated files added when using the -compiled and -test flags
// referring to cached copies of generated Go source files. // are absolute paths referring to cached copies of generated Go source files.
// Although they are Go source files, the paths may not end in ".go". // Although they are Go source files, the paths may not end in ".go".
// //
// The -m flag causes list to list modules instead of packages. // The -m flag causes list to list modules instead of packages.
...@@ -896,8 +902,6 @@ ...@@ -896,8 +902,6 @@
// //
// The -module flag changes the module's path (the go.mod file's module line). // The -module flag changes the module's path (the go.mod file's module line).
// //
// The -go flag changes the minimum required version of Go listed in go.mod.
//
// The -require=path@version and -droprequire=path flags // The -require=path@version and -droprequire=path flags
// add and drop a requirement on the given module path and version. // add and drop a requirement on the given module path and version.
// Note that -require overrides any existing requirements on path. // Note that -require overrides any existing requirements on path.
...@@ -910,12 +914,12 @@ ...@@ -910,12 +914,12 @@
// add and drop an exclusion for the given module path and version. // add and drop an exclusion for the given module path and version.
// Note that -exclude=path@version is a no-op if that exclusion already exists. // Note that -exclude=path@version is a no-op if that exclusion already exists.
// //
// The -replace=old@v=new@w and -dropreplace=old@v flags // The -replace=old[@v]=new[@v] and -dropreplace=old[@v] flags
// add and drop a replacement of the given module path and version pair. // add and drop a replacement of the given module path and version pair.
// If the @v in old@v is omitted, the replacement applies to all versions // If the @v in old@v is omitted, the replacement applies to all versions
// with the old module path. If the @v in new@v is omitted, the // with the old module path. If the @v in new@v is omitted, the new path
// new path should be a directory on the local system, not a module path. // should be a local module root directory, not a module path.
// Note that -replace overrides any existing replacements for old@v. // Note that -replace overrides any existing replacements for old[@v].
// //
// The -require, -droprequire, -exclude, -dropexclude, -replace, // The -require, -droprequire, -exclude, -dropexclude, -replace,
// and -dropreplace editing flags may be repeated, and the changes // and -dropreplace editing flags may be repeated, and the changes
...@@ -989,10 +993,12 @@ ...@@ -989,10 +993,12 @@
// perhaps D v1.2.4 or D v1.3.0. // perhaps D v1.2.4 or D v1.3.0.
// //
// Finally, fix removes redundant or misleading requirements. // Finally, fix removes redundant or misleading requirements.
// For example, if A v1.0.0 itself requires B v1.2.0 and C v1.0.0, // For example, if A v1.0.0 itself requires B v1.2.0 and C v1.0.0, then go.mod's
// then go.mod's requirement of B v1.0.0 is misleading (superseded // requirement of B v1.0.0 is misleading (superseded by A's need for v1.2.0),
// by B's need for v1.2.0), and its requirement of C v1.0.0 is redundant // and its requirement of C v1.0.0 is redundant (implied by A's need for the
// (implied by B's need for the same version), so both will be removed. // same version), so both will be removed. If module M contains packages
// that directly import packages from B or C, then the requirements will be
// kept but updated to the actual versions being used.
// //
// Although fix runs the fix-up operation in isolation, the fix-up also // Although fix runs the fix-up operation in isolation, the fix-up also
// runs automatically any time a go command uses the module graph, // runs automatically any time a go command uses the module graph,
...@@ -1396,8 +1402,9 @@ ...@@ -1396,8 +1402,9 @@
// information for reuse in future builds. // information for reuse in future builds.
// GOFLAGS // GOFLAGS
// A space-separated list of -flag=value settings to apply // A space-separated list of -flag=value settings to apply
// to go commands by default (when the given flag is known by // to go commands by default, when the given flag is known by
// the current command). // the current command. Flags listed on the command-line
// are applied after this list and therefore override it.
// GOOS // GOOS
// The operating system for which to compile code. // The operating system for which to compile code.
// Examples are linux, darwin, windows, netbsd. // Examples are linux, darwin, windows, netbsd.
...@@ -1611,7 +1618,7 @@ ...@@ -1611,7 +1618,7 @@
// GOPATH and Modules // GOPATH and Modules
// //
// When using modules, GOPATH is no longer used for resolving imports. // When using modules, GOPATH is no longer used for resolving imports.
// However, it is still used to store downloaded source code (in GOPATH/src/mod) // However, it is still used to store downloaded source code (in GOPATH/pkg/mod)
// and compiled commands (in GOPATH/bin). // and compiled commands (in GOPATH/bin).
// //
// Internal Directories // Internal Directories
...@@ -1700,11 +1707,14 @@ ...@@ -1700,11 +1707,14 @@
// Module proxy protocol // Module proxy protocol
// //
// The go command by default downloads modules from version control systems // The go command by default downloads modules from version control systems
// directly, just as 'go get' always has. If the GOPROXY environment variable // directly, just as 'go get' always has. The GOPROXY environment variable allows
// is set to the URL of a module proxy, the go command will instead fetch // further control over the download source. GOPROXY being unset, the empty string,
// all modules from that proxy. No matter the source of the modules, downloaded // or the string "direct" corresponds to the default direct connection to version
// modules must match existing entries in go.sum (see 'go help modules' for // control systems. Setting GOPROXY to "off" disallows downloading modules from
// discussion of verification). // any source. Otherwise, if GOPROXY is expected to be the URL of a module proxy,
// in which case the go command will fetch all modules from that proxy.
// No matter the source of the modules, downloaded modules must match existing
// entries in go.sum (see 'go help modules' for discussion of verification).
// //
// A Go module proxy is any web server that can respond to GET requests for // A Go module proxy is any web server that can respond to GET requests for
// URLs of a specified form. The requests have no query parameters, so even // URLs of a specified form. The requests have no query parameters, so even
...@@ -1749,10 +1759,10 @@ ...@@ -1749,10 +1759,10 @@
// //
// Even when downloading directly from version control systems, // Even when downloading directly from version control systems,
// the go command synthesizes explicit info, mod, and zip files // the go command synthesizes explicit info, mod, and zip files
// and stores them in its local cache, $GOPATH/src/mod/cache/download, // and stores them in its local cache, $GOPATH/pkg/mod/cache/download,
// the same as if it had downloaded them directly from a proxy. // the same as if it had downloaded them directly from a proxy.
// The cache layout is the same as the proxy URL space, so // The cache layout is the same as the proxy URL space, so
// serving $GOPATH/src/mod/cache/download at (or copying it to) // serving $GOPATH/pkg/mod/cache/download at (or copying it to)
// https://example.com/proxy would let other users access those // https://example.com/proxy would let other users access those
// cached module versions with GOPROXY=https://example.com/proxy. // cached module versions with GOPROXY=https://example.com/proxy.
// //
...@@ -1953,12 +1963,12 @@ ...@@ -1953,12 +1963,12 @@
// Modules replace the old GOPATH-based approach to specifying // Modules replace the old GOPATH-based approach to specifying
// which source files are used in a given build. // which source files are used in a given build.
// //
// Experimental module support // Preliminary module support
// //
// Go 1.11 includes experimental support for Go modules, // Go 1.11 includes preliminary support for Go modules,
// including a new module-aware 'go get' command. // including a new module-aware 'go get' command.
// We intend to keep revising this support, while preserving compatibility, // We intend to keep revising this support, while preserving compatibility,
// until it can be declared official (no longer experimental), // until it can be declared official (no longer preliminary),
// and then at a later point we may remove support for work // and then at a later point we may remove support for work
// in GOPATH and the old 'go get' command. // in GOPATH and the old 'go get' command.
// //
...@@ -1983,7 +1993,7 @@ ...@@ -1983,7 +1993,7 @@
// containing a go.mod file. // containing a go.mod file.
// //
// In module-aware mode, GOPATH no longer defines the meaning of imports // In module-aware mode, GOPATH no longer defines the meaning of imports
// during a build, but it still stores downloaded dependencies (in GOPATH/src/mod) // during a build, but it still stores downloaded dependencies (in GOPATH/pkg/mod)
// and installed commands (in GOPATH/bin, unless GOBIN is set). // and installed commands (in GOPATH/bin, unless GOBIN is set).
// //
// Defining a module // Defining a module
...@@ -2106,6 +2116,15 @@ ...@@ -2106,6 +2116,15 @@
// The 'go mod' command provides other functionality for use in maintaining // The 'go mod' command provides other functionality for use in maintaining
// and understanding modules and go.mod files. See 'go help mod'. // and understanding modules and go.mod files. See 'go help mod'.
// //
// The -mod build flag provides additional control over updating and use of go.mod.
// If invoked with -mod=readonly, the go command disables its automatic updates
// of go.mod as described above and fails if any changes are needed. This setting
// is most useful to check that go.mod does not need any updates, such as in a
// continuous integration and testing system.
// If invoked with -mod=vendor, the go command assumes that the vendor
// directory holds the correct copies of dependencies and ignores
// the dependency descriptions in go.mod.
//
// Pseudo-versions // Pseudo-versions
// //
// The go.mod file and the go command more generally use semantic versions as // The go.mod file and the go command more generally use semantic versions as
...@@ -2296,7 +2315,7 @@ ...@@ -2296,7 +2315,7 @@
// //
// To build using the main module's top-level vendor directory to satisfy // To build using the main module's top-level vendor directory to satisfy
// dependencies (disabling use of the usual network sources and local // dependencies (disabling use of the usual network sources and local
// caches), use 'go build -getmode=vendor'. Note that only the main module's // caches), use 'go build -mod=vendor'. Note that only the main module's
// top-level vendor directory is used; vendor directories in other locations // top-level vendor directory is used; vendor directories in other locations
// are still ignored. // are still ignored.
// //
......
...@@ -153,10 +153,10 @@ func runClean(cmd *base.Command, args []string) { ...@@ -153,10 +153,10 @@ func runClean(cmd *base.Command, args []string) {
} }
if cleanModcache { if cleanModcache {
if modfetch.SrcMod == "" { if modfetch.PkgMod == "" {
base.Fatalf("go clean -modcache: no module cache") base.Fatalf("go clean -modcache: no module cache")
} }
if err := removeAll(modfetch.SrcMod); err != nil { if err := removeAll(modfetch.PkgMod); err != nil {
base.Errorf("go clean -modcache: %v", err) base.Errorf("go clean -modcache: %v", err)
} }
} }
......
...@@ -377,7 +377,7 @@ See https://golang.org/doc/code.html for an example. ...@@ -377,7 +377,7 @@ See https://golang.org/doc/code.html for an example.
GOPATH and Modules GOPATH and Modules
When using modules, GOPATH is no longer used for resolving imports. When using modules, GOPATH is no longer used for resolving imports.
However, it is still used to store downloaded source code (in GOPATH/src/mod) However, it is still used to store downloaded source code (in GOPATH/pkg/mod)
and compiled commands (in GOPATH/bin). and compiled commands (in GOPATH/bin).
Internal Directories Internal Directories
......
...@@ -434,7 +434,7 @@ func LoadImport(path, srcDir string, parent *Package, stk *ImportStack, importPo ...@@ -434,7 +434,7 @@ func LoadImport(path, srcDir string, parent *Package, stk *ImportStack, importPo
if strings.HasPrefix(path, "mod/") { if strings.HasPrefix(path, "mod/") {
// Paths beginning with "mod/" might accidentally // Paths beginning with "mod/" might accidentally
// look in the module cache directory tree in $GOPATH/src/mod/. // look in the module cache directory tree in $GOPATH/pkg/mod/.
// This prefix is owned by the Go core for possible use in the // This prefix is owned by the Go core for possible use in the
// standard library (since it does not begin with a domain name), // standard library (since it does not begin with a domain name),
// so it's OK to disallow entirely. // so it's OK to disallow entirely.
......
...@@ -39,7 +39,7 @@ func testMain(m *testing.M) int { ...@@ -39,7 +39,7 @@ func testMain(m *testing.M) int {
log.Fatal(err) log.Fatal(err)
} }
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
modfetch.SrcMod = filepath.Join(dir, "src/mod") modfetch.PkgMod = filepath.Join(dir, "pkg/mod")
codehost.WorkRoot = filepath.Join(dir, "codework") codehost.WorkRoot = filepath.Join(dir, "codework")
return m.Run() return m.Run()
......
...@@ -22,17 +22,17 @@ import ( ...@@ -22,17 +22,17 @@ import (
var QuietLookup bool // do not print about lookups var QuietLookup bool // do not print about lookups
var SrcMod string // $GOPATH/src/mod; set by package modload var PkgMod string // $GOPATH/pkg/mod; set by package modload
func cacheDir(path string) (string, error) { func cacheDir(path string) (string, error) {
if SrcMod == "" { if PkgMod == "" {
return "", fmt.Errorf("internal error: modfetch.SrcMod not set") return "", fmt.Errorf("internal error: modfetch.PkgMod not set")
} }
enc, err := module.EncodePath(path) enc, err := module.EncodePath(path)
if err != nil { if err != nil {
return "", err return "", err
} }
return filepath.Join(SrcMod, "cache/download", enc, "/@v"), nil return filepath.Join(PkgMod, "cache/download", enc, "/@v"), nil
} }
func CachePath(m module.Version, suffix string) (string, error) { func CachePath(m module.Version, suffix string) (string, error) {
...@@ -54,8 +54,8 @@ func CachePath(m module.Version, suffix string) (string, error) { ...@@ -54,8 +54,8 @@ func CachePath(m module.Version, suffix string) (string, error) {
} }
func DownloadDir(m module.Version) (string, error) { func DownloadDir(m module.Version) (string, error) {
if SrcMod == "" { if PkgMod == "" {
return "", fmt.Errorf("internal error: modfetch.SrcMod not set") return "", fmt.Errorf("internal error: modfetch.PkgMod not set")
} }
enc, err := module.EncodePath(m.Path) enc, err := module.EncodePath(m.Path)
if err != nil { if err != nil {
...@@ -71,7 +71,7 @@ func DownloadDir(m module.Version) (string, error) { ...@@ -71,7 +71,7 @@ func DownloadDir(m module.Version) (string, error) {
if err != nil { if err != nil {
return "", err return "", err
} }
return filepath.Join(SrcMod, enc+"@"+encVer), nil return filepath.Join(PkgMod, enc+"@"+encVer), nil
} }
// A cachingRepo is a cache around an underlying Repo, // A cachingRepo is a cache around an underlying Repo,
...@@ -287,7 +287,7 @@ func readDiskStat(path, rev string) (file string, info *RevInfo, err error) { ...@@ -287,7 +287,7 @@ func readDiskStat(path, rev string) (file string, info *RevInfo, err error) {
// just to find out about a commit we already know about // just to find out about a commit we already know about
// (and have cached under its pseudo-version). // (and have cached under its pseudo-version).
func readDiskStatByHash(path, rev string) (file string, info *RevInfo, err error) { func readDiskStatByHash(path, rev string) (file string, info *RevInfo, err error) {
if SrcMod == "" { if PkgMod == "" {
// Do not download to current directory. // Do not download to current directory.
return "", nil, errNotCached return "", nil, errNotCached
} }
......
...@@ -28,9 +28,9 @@ var downloadCache par.Cache ...@@ -28,9 +28,9 @@ var downloadCache par.Cache
// local download cache and returns the name of the directory // local download cache and returns the name of the directory
// corresponding to the root of the module's file tree. // corresponding to the root of the module's file tree.
func Download(mod module.Version) (dir string, err error) { func Download(mod module.Version) (dir string, err error) {
if SrcMod == "" { if PkgMod == "" {
// Do not download to current directory. // Do not download to current directory.
return "", fmt.Errorf("missing modfetch.SrcMod") return "", fmt.Errorf("missing modfetch.PkgMod")
} }
// The par.Cache here avoids duplicate work but also // The par.Cache here avoids duplicate work but also
...@@ -53,7 +53,7 @@ func Download(mod module.Version) (dir string, err error) { ...@@ -53,7 +53,7 @@ func Download(mod module.Version) (dir string, err error) {
if _, err := os.Stat(zipfile); err == nil { if _, err := os.Stat(zipfile); err == nil {
// Use it. // Use it.
// This should only happen if the mod/cache directory is preinitialized // This should only happen if the mod/cache directory is preinitialized
// or if src/mod/path was removed but not src/mod/cache/download. // or if pkg/mod/path was removed but not pkg/mod/cache/download.
fmt.Fprintf(os.Stderr, "go: extracting %s %s\n", mod.Path, mod.Version) fmt.Fprintf(os.Stderr, "go: extracting %s %s\n", mod.Path, mod.Version)
} else { } else {
if err := os.MkdirAll(filepath.Dir(zipfile), 0777); err != nil { if err := os.MkdirAll(filepath.Dir(zipfile), 0777); err != nil {
...@@ -200,7 +200,7 @@ func readGoSum(file string, data []byte) { ...@@ -200,7 +200,7 @@ func readGoSum(file string, data []byte) {
// checkSum checks the given module's checksum. // checkSum checks the given module's checksum.
func checkSum(mod module.Version) { func checkSum(mod module.Version) {
if SrcMod == "" { if PkgMod == "" {
// Do not use current directory. // Do not use current directory.
return return
} }
...@@ -264,7 +264,7 @@ func checkOneSum(mod module.Version, h string) { ...@@ -264,7 +264,7 @@ func checkOneSum(mod module.Version, h string) {
// Sum returns the checksum for the downloaded copy of the given module, // Sum returns the checksum for the downloaded copy of the given module,
// if present in the download cache. // if present in the download cache.
func Sum(mod module.Version) string { func Sum(mod module.Version) string {
if SrcMod == "" { if PkgMod == "" {
// Do not use current directory. // Do not use current directory.
return "" return ""
} }
......
...@@ -77,10 +77,10 @@ archive. ...@@ -77,10 +77,10 @@ archive.
Even when downloading directly from version control systems, Even when downloading directly from version control systems,
the go command synthesizes explicit info, mod, and zip files the go command synthesizes explicit info, mod, and zip files
and stores them in its local cache, $GOPATH/src/mod/cache/download, and stores them in its local cache, $GOPATH/pkg/mod/cache/download,
the same as if it had downloaded them directly from a proxy. the same as if it had downloaded them directly from a proxy.
The cache layout is the same as the proxy URL space, so The cache layout is the same as the proxy URL space, so
serving $GOPATH/src/mod/cache/download at (or copying it to) serving $GOPATH/pkg/mod/cache/download at (or copying it to)
https://example.com/proxy would let other users access those https://example.com/proxy would let other users access those
cached module versions with GOPROXY=https://example.com/proxy. cached module versions with GOPROXY=https://example.com/proxy.
`, `,
......
...@@ -50,7 +50,7 @@ GOPATH/src and itself contains a go.mod file or is below a directory ...@@ -50,7 +50,7 @@ GOPATH/src and itself contains a go.mod file or is below a directory
containing a go.mod file. containing a go.mod file.
In module-aware mode, GOPATH no longer defines the meaning of imports In module-aware mode, GOPATH no longer defines the meaning of imports
during a build, but it still stores downloaded dependencies (in GOPATH/src/mod) during a build, but it still stores downloaded dependencies (in GOPATH/pkg/mod)
and installed commands (in GOPATH/bin, unless GOBIN is set). and installed commands (in GOPATH/bin, unless GOBIN is set).
Defining a module Defining a module
......
...@@ -170,9 +170,9 @@ func Init() { ...@@ -170,9 +170,9 @@ func Init() {
func init() { func init() {
load.ModInit = Init load.ModInit = Init
// Set modfetch.SrcMod unconditionally, so that go clean -modcache can run even without modules enabled. // Set modfetch.PkgMod unconditionally, so that go clean -modcache can run even without modules enabled.
if list := filepath.SplitList(cfg.BuildContext.GOPATH); len(list) > 0 && list[0] != "" { if list := filepath.SplitList(cfg.BuildContext.GOPATH); len(list) > 0 && list[0] != "" {
modfetch.SrcMod = filepath.Join(list[0], "src/mod") modfetch.PkgMod = filepath.Join(list[0], "pkg/mod")
} }
} }
...@@ -233,17 +233,17 @@ func InitMod() { ...@@ -233,17 +233,17 @@ func InitMod() {
base.Fatalf("$GOPATH/go.mod exists but should not") base.Fatalf("$GOPATH/go.mod exists but should not")
} }
srcV := filepath.Join(list[0], "src/v") oldSrcMod := filepath.Join(list[0], "src/mod")
srcMod := filepath.Join(list[0], "src/mod") pkgMod := filepath.Join(list[0], "pkg/mod")
infoV, errV := os.Stat(srcV) infoOld, errOld := os.Stat(oldSrcMod)
_, errMod := os.Stat(srcMod) _, errMod := os.Stat(pkgMod)
if errV == nil && infoV.IsDir() && errMod != nil && os.IsNotExist(errMod) { if errOld == nil && infoOld.IsDir() && errMod != nil && os.IsNotExist(errMod) {
os.Rename(srcV, srcMod) os.Rename(oldSrcMod, pkgMod)
} }
modfetch.SrcMod = srcMod modfetch.PkgMod = pkgMod
modfetch.GoSumFile = filepath.Join(ModRoot, "go.sum") modfetch.GoSumFile = filepath.Join(ModRoot, "go.sum")
codehost.WorkRoot = filepath.Join(srcMod, "cache/vcs") codehost.WorkRoot = filepath.Join(pkgMod, "cache/vcs")
if CmdModInit { if CmdModInit {
// Running go mod init: do legacy module conversion // Running go mod init: do legacy module conversion
......
...@@ -29,7 +29,7 @@ func testMain(m *testing.M) int { ...@@ -29,7 +29,7 @@ func testMain(m *testing.M) int {
log.Fatal(err) log.Fatal(err)
} }
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
modfetch.SrcMod = filepath.Join(dir, "src/mod") modfetch.PkgMod = filepath.Join(dir, "pkg/mod")
codehost.WorkRoot = filepath.Join(dir, "codework") codehost.WorkRoot = filepath.Join(dir, "codework")
return m.Run() return m.Run()
} }
......
...@@ -97,13 +97,13 @@ func main() { ...@@ -97,13 +97,13 @@ func main() {
continue continue
} }
path, vers, dir := f[0], f[1], f[2] path, vers, dir := f[0], f[1], f[2]
mod, err := ioutil.ReadFile(filepath.Join(gopath, "src/mod/cache/download", path, "@v", vers+".mod")) mod, err := ioutil.ReadFile(filepath.Join(gopath, "pkg/mod/cache/download", path, "@v", vers+".mod"))
if err != nil { if err != nil {
log.Printf("%s: %v", arg, err) log.Printf("%s: %v", arg, err)
exitCode = 1 exitCode = 1
continue continue
} }
info, err := ioutil.ReadFile(filepath.Join(gopath, "src/mod/cache/download", path, "@v", vers+".info")) info, err := ioutil.ReadFile(filepath.Join(gopath, "pkg/mod/cache/download", path, "@v", vers+".info"))
if err != nil { if err != nil {
log.Printf("%s: %v", arg, err) log.Printf("%s: %v", arg, err)
exitCode = 1 exitCode = 1
......
...@@ -6,16 +6,16 @@ go mod edit -fmt ...@@ -6,16 +6,16 @@ go mod edit -fmt
go list -mod=readonly go list -mod=readonly
env GOPROXY=file:///nonexist env GOPROXY=file:///nonexist
go list go list
grep v1.5.1 $GOPATH/src/mod/cache/download/rsc.io/quote/@v/list grep v1.5.1 $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/list
# Use download cache as file:/// proxy. # Use download cache as file:/// proxy.
[windows] stop # TODO: file://$WORK puts backslashes in the URL [windows] stop # TODO: file://$WORK puts backslashes in the URL
env GOPATH=$WORK/gopath2 env GOPATH=$WORK/gopath2
env GOPROXY=file:///nonexist env GOPROXY=file:///nonexist
! go list ! go list
env GOPROXY=file://$WORK/gopath1/src/mod/cache/download env GOPROXY=file://$WORK/gopath1/pkg/mod/cache/download
go list go list
grep v1.5.1 $GOPATH/src/mod/cache/download/rsc.io/quote/@v/list grep v1.5.1 $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/list
-- $WORK/x/go.mod -- -- $WORK/x/go.mod --
module x module x
......
# Test that GOPATH/src/mod is excluded # Test that GOPATH/pkg/mod is excluded
env GO111MODULE=off env GO111MODULE=off
! go list mod/foo ! go list mod/foo
stderr 'disallowed import path' stderr 'disallowed import path'
......
...@@ -10,12 +10,12 @@ go list -f '{{.Dir}}' rsc.io/quote ...@@ -10,12 +10,12 @@ go list -f '{{.Dir}}' rsc.io/quote
stdout '.*mod[\\/]rsc.io[\\/]quote@v1.5.2$' stdout '.*mod[\\/]rsc.io[\\/]quote@v1.5.2$'
# downloaded dependencies are read-only # downloaded dependencies are read-only
exists -readonly $GOPATH/src/mod/rsc.io/quote@v1.5.2 exists -readonly $GOPATH/pkg/mod/rsc.io/quote@v1.5.2
exists -readonly $GOPATH/src/mod/rsc.io/quote@v1.5.2/buggy exists -readonly $GOPATH/pkg/mod/rsc.io/quote@v1.5.2/buggy
# go clean -modcache can delete read-only dependencies # go clean -modcache can delete read-only dependencies
go clean -modcache go clean -modcache
! exists $GOPATH/src/mod/rsc.io/quote@v1.5.2 ! exists $GOPATH/pkg/mod/rsc.io/quote@v1.5.2
# list {{.Dir}} shows replaced directories # list {{.Dir}} shows replaced directories
cp go.mod2 go.mod cp go.mod2 go.mod
......
...@@ -9,14 +9,14 @@ go list -f '{{.ImportPath}}' $GOROOT/src/math ...@@ -9,14 +9,14 @@ go list -f '{{.ImportPath}}' $GOROOT/src/math
stdout ^math$ stdout ^math$
go list -f '{{.ImportPath}}' . go list -f '{{.ImportPath}}' .
stdout ^x$ stdout ^x$
go list -f '{{.ImportPath}}' $GOPATH/src/mod/rsc.io/quote@v1.5.2 go list -f '{{.ImportPath}}' $GOPATH/pkg/mod/rsc.io/quote@v1.5.2
stdout '^rsc.io/quote$' stdout '^rsc.io/quote$'
go list -f '{{.ImportPath}}' $GOPATH/src/mod/rsc.io/sampler@v1.3.0 go list -f '{{.ImportPath}}' $GOPATH/pkg/mod/rsc.io/sampler@v1.3.0
stdout '^rsc.io/sampler$' stdout '^rsc.io/sampler$'
go get rsc.io/sampler@v1.3.1 go get rsc.io/sampler@v1.3.1
go list -f '{{.ImportPath}}' $GOPATH/src/mod/rsc.io/sampler@v1.3.1 go list -f '{{.ImportPath}}' $GOPATH/pkg/mod/rsc.io/sampler@v1.3.1
stdout '^rsc.io/sampler$' stdout '^rsc.io/sampler$'
! go list -f '{{.ImportPath}}' $GOPATH/src/mod/rsc.io/sampler@v1.3.0 ! go list -f '{{.ImportPath}}' $GOPATH/pkg/mod/rsc.io/sampler@v1.3.0
stderr 'outside available modules' stderr 'outside available modules'
-- go.mod -- -- go.mod --
......
...@@ -2,25 +2,25 @@ env GO111MODULE=on ...@@ -2,25 +2,25 @@ env GO111MODULE=on
# initial standalone module should use no downloaded modules # initial standalone module should use no downloaded modules
go list -deps -f {{.Dir}} go list -deps -f {{.Dir}}
! stdout 'src[\\/]mod' ! stdout 'pkg[\\/]mod'
# v2 import should use a downloaded module # v2 import should use a downloaded module
# both without an explicit go.mod entry ... # both without an explicit go.mod entry ...
cp tmp/use_v2.go x.go cp tmp/use_v2.go x.go
go list -deps -f {{.Dir}} go list -deps -f {{.Dir}}
stdout 'src[\\/]mod[\\/]rsc.io[\\/]quote[\\/]v2@v2.0.1$' stdout 'pkg[\\/]mod[\\/]rsc.io[\\/]quote[\\/]v2@v2.0.1$'
# ... and with one ... # ... and with one ...
cp tmp/use_v2.mod go.mod cp tmp/use_v2.mod go.mod
go list -deps -f {{.Dir}} go list -deps -f {{.Dir}}
stdout 'src[\\/]mod[\\/]rsc.io[\\/]quote[\\/]v2@v2.0.1$' stdout 'pkg[\\/]mod[\\/]rsc.io[\\/]quote[\\/]v2@v2.0.1$'
# ... and even if there is a v2 module in a subdirectory. # ... and even if there is a v2 module in a subdirectory.
mkdir v2 mkdir v2
cp x.go v2/x.go cp x.go v2/x.go
cp tmp/v2.mod v2/go.mod cp tmp/v2.mod v2/go.mod
go list -deps -f {{.Dir}} go list -deps -f {{.Dir}}
stdout 'src[\\/]mod[\\/]rsc.io[\\/]quote[\\/]v2@v2.0.1$' stdout 'pkg[\\/]mod[\\/]rsc.io[\\/]quote[\\/]v2@v2.0.1$'
-- go.mod -- -- go.mod --
module rsc.io/quote module rsc.io/quote
......
...@@ -3,12 +3,12 @@ env GO111MODULE=on ...@@ -3,12 +3,12 @@ env GO111MODULE=on
# With good go.sum, verify succeeds by avoiding download. # With good go.sum, verify succeeds by avoiding download.
cp go.sum.good go.sum cp go.sum.good go.sum
go mod verify go mod verify
! exists $GOPATH/src/mod/cache/download/rsc.io/quote/@v/v1.1.0.zip ! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.1.0.zip
# With bad go.sum, verify succeeds by avoiding download. # With bad go.sum, verify succeeds by avoiding download.
cp go.sum.bad go.sum cp go.sum.bad go.sum
go mod verify go mod verify
! exists $GOPATH/src/mod/cache/download/rsc.io/quote/@v/v1.1.0.zip ! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.1.0.zip
# With bad go.sum, sync (which must download) fails. # With bad go.sum, sync (which must download) fails.
# Even if the bad sum is in the old legacy go.modverify file. # Even if the bad sum is in the old legacy go.modverify file.
...@@ -16,14 +16,14 @@ rm go.sum ...@@ -16,14 +16,14 @@ rm go.sum
cp go.sum.bad go.modverify cp go.sum.bad go.modverify
! go mod tidy ! go mod tidy
stderr 'checksum mismatch' stderr 'checksum mismatch'
! exists $GOPATH/src/mod/cache/download/rsc.io/quote/@v/v1.1.0.zip ! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.1.0.zip
# With good go.sum, sync works (and moves go.modverify to go.sum). # With good go.sum, sync works (and moves go.modverify to go.sum).
rm go.sum rm go.sum
cp go.sum.good go.modverify cp go.sum.good go.modverify
go mod tidy go mod tidy
exists $GOPATH/src/mod/cache/download/rsc.io/quote/@v/v1.1.0.zip exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.1.0.zip
exists $GOPATH/src/mod/rsc.io/quote@v1.1.0/quote.go exists $GOPATH/pkg/mod/rsc.io/quote@v1.1.0/quote.go
! exists go.modverify ! exists go.modverify
# go.sum should have the new checksum for go.mod # go.sum should have the new checksum for go.mod
...@@ -50,7 +50,7 @@ grep '^rsc.io/quote v1.1.0/go.mod ' go.sum ...@@ -50,7 +50,7 @@ grep '^rsc.io/quote v1.1.0/go.mod ' go.sum
grep '^rsc.io/quote v1.1.0 ' go.sum grep '^rsc.io/quote v1.1.0 ' go.sum
# sync should ignore missing ziphash; verify should not # sync should ignore missing ziphash; verify should not
rm $GOPATH/src/mod/cache/download/rsc.io/quote/@v/v1.1.0.ziphash rm $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.1.0.ziphash
go mod tidy go mod tidy
! go mod verify ! go mod verify
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment