]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: for get -t and list, look up path in vendor directories
authorIan Lance Taylor <iant@golang.org>
Tue, 21 Jul 2015 20:59:35 +0000 (13:59 -0700)
committerIan Lance Taylor <iant@golang.org>
Wed, 22 Jul 2015 21:16:53 +0000 (21:16 +0000)
This is needed to handle vendor directories correctly.  It was already
done for the regular imports when the package was loaded, but not for
the test-only imports.

It would be nice to do this while loading the package, but that breaks
the code that checks for direct references to vendor packages when
running go test.  This change is relatively contained.

While we're at it, skip "C" test imports in go get.

Fixes #11628.
Fixes #11717.

Change-Id: I9cc308cf45683e3ff905320c2b5cb45db7716846
Reviewed-on: https://go-review.googlesource.com/12488
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/go/get.go
src/cmd/go/list.go
src/cmd/go/vendor_test.go

index 320698ec476bf8ca6604b3d3771a83afb59ba6c7..f331c298e20576cd848d2528f62de2e5b429deae 100644 (file)
@@ -287,10 +287,22 @@ func download(arg string, parent *Package, stk *importStack, getTestDeps bool) {
                if getTestDeps {
                        // Process test dependencies when -t is specified.
                        // (Don't get test dependencies for test dependencies.)
+                       //
+                       // We apply vendoredImportPath here.  It's not
+                       // needed for Imports, because it was done
+                       // while loading the package.
                        for _, path := range p.TestImports {
+                               if path == "C" {
+                                       continue
+                               }
+                               path, _ = vendoredImportPath(p, path)
                                download(path, p, stk, false)
                        }
                        for _, path := range p.XTestImports {
+                               if path == "C" {
+                                       continue
+                               }
+                               path, _ = vendoredImportPath(p, path)
                                download(path, p, stk, false)
                        }
                }
index e500ece4743e8844f114488bb72455e7f1f4e63e..b24444026b9d138b71e94da6cc51109fe94fbed6 100644 (file)
@@ -175,6 +175,18 @@ func runList(cmd *Command, args []string) {
        }
 
        for _, pkg := range load(args) {
+               // We apply vendoredImportPath here for test imports.
+               // It's not needed for regular imports, because it was
+               // done while loading the package.
+               for i, path := range pkg.TestImports {
+                       path, _ = vendoredImportPath(pkg, path)
+                       pkg.TestImports[i] = path
+               }
+               for i, path := range pkg.XTestImports {
+                       path, _ = vendoredImportPath(pkg, path)
+                       pkg.XTestImports[i] = path
+               }
+
                do(pkg)
        }
 }
index 389fd5efb00ca79707f40b3d26de085983d65e81..b99b4f118565894931c3a1891c308f4b45663d95 100644 (file)
@@ -142,3 +142,34 @@ func splitLines(s string) []string {
        }
        return x
 }
+
+func TestVendorGet(t *testing.T) {
+       tg := testgo(t)
+       defer tg.cleanup()
+       tg.tempFile("src/v/m.go", `
+               package main
+               import ("fmt"; "vendor.org/p")
+               func main() {
+                       fmt.Println(p.C)
+               }`)
+       tg.tempFile("src/v/m_test.go", `
+               package main
+               import ("fmt"; "testing"; "vendor.org/p")
+               func TestNothing(t *testing.T) {
+                       fmt.Println(p.C)
+               }`)
+       tg.tempFile("src/v/vendor/vendor.org/p/p.go", `
+               package p
+               const C = 1`)
+       tg.setenv("GOPATH", tg.path("."))
+       tg.setenv("GO15VENDOREXPERIMENT", "1")
+       tg.cd(tg.path("src/v"))
+       tg.run("run", "m.go")
+       tg.run("test")
+       tg.run("list", "-f", "{{.Imports}}")
+       tg.grepStdout("v/vendor/vendor.org/p", "import not in vendor directory")
+       tg.run("list", "-f", "{{.TestImports}}")
+       tg.grepStdout("v/vendor/vendor.org/p", "test import not in vendor directory")
+       tg.run("get")
+       tg.run("get", "-t")
+}