aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modload/load.go
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2019-03-12 09:27:27 -0400
committerBryan C. Mills <bcmills@google.com>2019-03-12 20:10:13 +0000
commitf54b8909ac93637159e2661f25aef5e61e8cd8fc (patch)
treea016a380f3b1b836a26dd5a2874c004aff4d15f0 /src/cmd/go/internal/modload/load.go
parent718fdd7b48d2a20c5a84a7b516ed29c98d61e359 (diff)
downloadgo-f54b8909ac93637159e2661f25aef5e61e8cd8fc.tar.gz
go-f54b8909ac93637159e2661f25aef5e61e8cd8fc.zip
cmd/go/internal/modload: treat a 'std' module outside GOROOT/src as an ordinary module
Fixes #30756 Change-Id: I046d43df56faac8fc09d53dc1e87a014dd6d530b Reviewed-on: https://go-review.googlesource.com/c/go/+/167080 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
Diffstat (limited to 'src/cmd/go/internal/modload/load.go')
-rw-r--r--src/cmd/go/internal/modload/load.go34
1 files changed, 15 insertions, 19 deletions
diff --git a/src/cmd/go/internal/modload/load.go b/src/cmd/go/internal/modload/load.go
index 205754546c..33b53052d8 100644
--- a/src/cmd/go/internal/modload/load.go
+++ b/src/cmd/go/internal/modload/load.go
@@ -111,7 +111,7 @@ func ImportPaths(patterns []string) []*search.Match {
if strings.HasPrefix(suffix, "/vendor/") {
// TODO getmode vendor check
pkg = strings.TrimPrefix(suffix, "/vendor/")
- } else if Target.Path == "std" {
+ } else if targetInGorootSrc && Target.Path == "std" {
// Don't add the prefix "std/" to packages in the "std" module.
// It's the one module path that isn't a prefix of its packages.
pkg = strings.TrimPrefix(suffix, "/")
@@ -270,14 +270,14 @@ func DirImportPath(dir string) string {
}
if dir == modRoot {
- return Target.Path
+ return targetPrefix
}
if strings.HasPrefix(dir, modRoot+string(filepath.Separator)) {
suffix := filepath.ToSlash(dir[len(modRoot):])
if strings.HasPrefix(suffix, "/vendor/") {
return strings.TrimPrefix(suffix, "/vendor/")
}
- return Target.Path + suffix
+ return targetPrefix + suffix
}
return "."
}
@@ -474,14 +474,10 @@ func newLoader() *loader {
ld.tags = imports.Tags()
ld.testRoots = LoadTests
- switch Target.Path {
- case "std", "cmd":
- // Inside the "std" and "cmd" modules, we prefer to use the vendor directory
- // unless the command explicitly changes the module graph.
- // TODO(golang.org/issue/30240): Remove this special case.
- if cfg.CmdName != "get" && !strings.HasPrefix(cfg.CmdName, "mod ") {
- ld.forceStdVendor = true
- }
+ // Inside the "std" and "cmd" modules, we prefer to use the vendor directory
+ // unless the command explicitly changes the module graph.
+ if !targetInGorootSrc || (cfg.CmdName != "get" && !strings.HasPrefix(cfg.CmdName, "mod ")) {
+ ld.forceStdVendor = true
}
return ld
@@ -680,13 +676,14 @@ func (ld *loader) stdVendor(parentPath, path string) string {
return path
}
- if str.HasPathPrefix(parentPath, "cmd") && (Target.Path != "cmd" || ld.forceStdVendor) {
- vendorPath := pathpkg.Join("cmd", "vendor", path)
- if _, err := os.Stat(filepath.Join(cfg.GOROOTsrc, filepath.FromSlash(vendorPath))); err == nil {
- return vendorPath
+ if str.HasPathPrefix(parentPath, "cmd") {
+ if ld.forceStdVendor || Target.Path != "cmd" {
+ vendorPath := pathpkg.Join("cmd", "vendor", path)
+ if _, err := os.Stat(filepath.Join(cfg.GOROOTsrc, filepath.FromSlash(vendorPath))); err == nil {
+ return vendorPath
+ }
}
- }
- if Target.Path != "std" || ld.forceStdVendor {
+ } else if ld.forceStdVendor || Target.Path != "std" {
vendorPath := pathpkg.Join("vendor", path)
if _, err := os.Stat(filepath.Join(cfg.GOROOTsrc, filepath.FromSlash(vendorPath))); err == nil {
return vendorPath
@@ -987,8 +984,7 @@ func (r *mvsReqs) required(mod module.Version) ([]module.Version, error) {
return vendorList, nil
}
- switch Target.Path {
- case "std", "cmd":
+ if targetInGorootSrc {
// When inside "std" or "cmd", only fetch and read go.mod files if we're
// explicitly running a command that can change the module graph. If we have
// to resolve a new dependency, we might pick the wrong version, but 'go mod