aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2018-06-01 15:47:29 -0400
committerRuss Cox <rsc@golang.org>2018-06-04 16:21:11 +0000
commit91f0e20ecbff8c7744c7b8a7a6a4582a3bfef5a2 (patch)
tree241c9ca9861c879f6c19bf16396bfab3f779e88c
parent05604d7450b7cfcd946762039ee46e9ab85297d6 (diff)
downloadgo-91f0e20ecbff8c7744c7b8a7a6a4582a3bfef5a2.tar.gz
go-91f0e20ecbff8c7744c7b8a7a6a4582a3bfef5a2.zip
[release-branch.go1.9] cmd/go: fix 'go get' compatibility for direct download of vgo-aware module
CL 109340 added “minimal module-awareness for legacy operation.” One part of that is reinterpreting imports inside code trees with go.mod files as using semantic import versioning, and converting them back to legacy import paths by stripping the major version element (for example, interpreting import "x.com/foo/v2/bar" as import "x.com/foo/bar"). This rewrite was not being applied during "go get", with the effect that once you had the target code downloaded already, everything was fine, but it didn't download and build successfully the first time. Fixes #25687. Cherry-pick fixes #25691. Change-Id: I3e122efdc8fd9a0a4e66f5aa3e6a99f90c7df779 Reviewed-on: https://go-review.googlesource.com/115797 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-on: https://go-review.googlesource.com/116175
-rw-r--r--src/cmd/go/internal/get/get.go8
-rw-r--r--src/cmd/go/internal/load/pkg.go9
-rw-r--r--src/cmd/go/vendor_test.go44
3 files changed, 55 insertions, 6 deletions
diff --git a/src/cmd/go/internal/get/get.go b/src/cmd/go/internal/get/get.go
index 54460ec38f..6495576ab4 100644
--- a/src/cmd/go/internal/get/get.go
+++ b/src/cmd/go/internal/get/get.go
@@ -218,7 +218,7 @@ func download(arg string, parent *load.Package, stk *load.ImportStack, mode int)
if parent == nil {
return load.LoadPackage(path, stk)
}
- return load.LoadImport(path, parent.Dir, parent, stk, nil, mode)
+ return load.LoadImport(path, parent.Dir, parent, stk, nil, mode|load.ResolveModule)
}
p := load1(arg, mode)
@@ -347,12 +347,12 @@ func download(arg string, parent *load.Package, stk *load.ImportStack, mode int)
base.Errorf("%s", err)
continue
}
- // If this is a test import, apply vendor lookup now.
- // We cannot pass useVendor to download, because
+ // If this is a test import, apply module and vendor lookup now.
+ // We cannot pass ResolveImport to download, because
// download does caching based on the value of path,
// so it must be the fully qualified path already.
if i >= len(p.Imports) {
- path = load.VendoredImportPath(p, path)
+ path = load.ResolveImportPath(p, path)
}
download(path, p, stk, 0)
}
diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go
index de3f5b8fa2..873abe07a0 100644
--- a/src/cmd/go/internal/load/pkg.go
+++ b/src/cmd/go/internal/load/pkg.go
@@ -395,7 +395,11 @@ const (
// disallowVendor will reject direct use of paths containing /vendor/.
ResolveImport = 1 << iota
- // getTestDeps is for download (part of "go get") and indicates
+ // ResolveModule is for download (part of "go get") and indicates
+ // that the module adjustment should be done, but not vendor adjustment.
+ ResolveModule
+
+ // GetTestDeps is for download (part of "go get") and indicates
// that test dependencies should be fetched too.
GetTestDeps
)
@@ -425,6 +429,9 @@ func LoadImport(path, srcDir string, parent *Package, stk *ImportStack, importPo
// The code is also needed in a few other places anyway.
path = ResolveImportPath(parent, path)
importPath = path
+ } else if mode&ResolveModule != 0 {
+ path = ModuleImportPath(parent, path)
+ importPath = path
}
p := packageCache[importPath]
diff --git a/src/cmd/go/vendor_test.go b/src/cmd/go/vendor_test.go
index d68e4f94fe..c394365d9f 100644
--- a/src/cmd/go/vendor_test.go
+++ b/src/cmd/go/vendor_test.go
@@ -10,6 +10,7 @@ import (
"bytes"
"fmt"
"internal/testenv"
+ "os"
"path/filepath"
"regexp"
"strings"
@@ -351,10 +352,51 @@ func TestModLegacyGet(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.makeTempdir()
- tg.setenv("GOPATH", tg.path("."))
+ tg.setenv("GOPATH", tg.path("d1"))
tg.run("get", "vcs-test.golang.org/git/modlegacy1-old.git/p1")
tg.run("list", "-f", "{{.Deps}}", "vcs-test.golang.org/git/modlegacy1-old.git/p1")
tg.grepStdout("new.git/p2", "old/p1 should depend on new/p2")
tg.grepStdoutNot("new.git/v2/p2", "old/p1 should NOT depend on new/v2/p2")
tg.run("build", "vcs-test.golang.org/git/modlegacy1-old.git/p1", "vcs-test.golang.org/git/modlegacy1-new.git/p1")
+
+ tg.setenv("GOPATH", tg.path("d2"))
+
+ tg.must(os.RemoveAll(tg.path("d2")))
+ tg.run("get", "github.com/rsc/vgotest5")
+ tg.run("get", "github.com/rsc/vgotest4")
+ tg.run("get", "github.com/myitcv/vgo_example_compat")
+
+ if testing.Short() {
+ return
+ }
+
+ tg.must(os.RemoveAll(tg.path("d2")))
+ tg.run("get", "github.com/rsc/vgotest4")
+ tg.run("get", "github.com/rsc/vgotest5")
+ tg.run("get", "github.com/myitcv/vgo_example_compat")
+
+ tg.must(os.RemoveAll(tg.path("d2")))
+ tg.run("get", "github.com/rsc/vgotest4", "github.com/rsc/vgotest5")
+ tg.run("get", "github.com/myitcv/vgo_example_compat")
+
+ tg.must(os.RemoveAll(tg.path("d2")))
+ tg.run("get", "github.com/rsc/vgotest5", "github.com/rsc/vgotest4")
+ tg.run("get", "github.com/myitcv/vgo_example_compat")
+
+ tg.must(os.RemoveAll(tg.path("d2")))
+ tg.run("get", "github.com/myitcv/vgo_example_compat")
+ tg.run("get", "github.com/rsc/vgotest4", "github.com/rsc/vgotest5")
+
+ pkgs := []string{"github.com/myitcv/vgo_example_compat", "github.com/rsc/vgotest4", "github.com/rsc/vgotest5"}
+ for i := 0; i < 3; i++ {
+ for j := 0; j < 3; j++ {
+ for k := 0; k < 3; k++ {
+ if i == j || i == k || k == j {
+ continue
+ }
+ tg.must(os.RemoveAll(tg.path("d2")))
+ tg.run("get", pkgs[i], pkgs[j], pkgs[k])
+ }
+ }
+ }
}