]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.11] cmd/go: fix modload response for std-vendored packages
authorRuss Cox <rsc@golang.org>
Tue, 21 Aug 2018 01:25:01 +0000 (21:25 -0400)
committerIan Lance Taylor <iant@golang.org>
Wed, 22 Aug 2018 15:50:27 +0000 (15:50 +0000)
This fixes a failure when using Go 1.11 to build App Engine code.

Change-Id: I008e8cf5ad4c568676d904deddff031a166f2d5d
Reviewed-on: https://go-review.googlesource.com/130138
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
(cherry picked from commit c652a1b9c041a2d359665f01de21b19d53ba5ce5)
Reviewed-on: https://go-review.googlesource.com/130616
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
src/cmd/go/internal/modload/build.go
src/cmd/go/internal/modload/load.go
src/cmd/go/testdata/script/mod_std_vendor.txt [new file with mode: 0644]

index 5893db14aa60c3fd440a7792282cb31a673b9668..cebb802db9fc9f06ae8fb32023ade4c827bc574f 100644 (file)
@@ -25,15 +25,21 @@ var (
 )
 
 func isStandardImportPath(path string) bool {
+       return findStandardImportPath(path) != ""
+}
+
+func findStandardImportPath(path string) string {
        if search.IsStandardImportPath(path) {
-               if _, err := os.Stat(filepath.Join(cfg.GOROOT, "src", path)); err == nil {
-                       return true
+               dir := filepath.Join(cfg.GOROOT, "src", path)
+               if _, err := os.Stat(dir); err == nil {
+                       return dir
                }
-               if _, err := os.Stat(filepath.Join(cfg.GOROOT, "src/vendor", path)); err == nil {
-                       return true
+               dir = filepath.Join(cfg.GOROOT, "src/vendor", path)
+               if _, err := os.Stat(dir); err == nil {
+                       return dir
                }
        }
-       return false
+       return ""
 }
 
 func PackageModuleInfo(pkgpath string) *modinfo.ModulePublic {
index 285daa8f4fcb9521d8565d01e45a1c3422530435..e6340b8bfdcd683c66e84f2313b91177230a84c7 100644 (file)
@@ -399,11 +399,17 @@ func ModuleUsedDirectly(path string) bool {
 func Lookup(path string) (dir, realPath string, err error) {
        pkg, ok := loaded.pkgCache.Get(path).(*loadPkg)
        if !ok {
-               if isStandardImportPath(path) {
-                       dir := filepath.Join(cfg.GOROOT, "src", path)
-                       if _, err := os.Stat(dir); err == nil {
-                               return dir, path, nil
-                       }
+               // The loader should have found all the relevant paths.
+               // There are a few exceptions, though:
+               //      - during go list without -test, the p.Resolve calls to process p.TestImports and p.XTestImports
+               //        end up here to canonicalize the import paths.
+               //      - during any load, non-loaded packages like "unsafe" end up here.
+               //      - during any load, build-injected dependencies like "runtime/cgo" end up here.
+               //      - because we ignore appengine/* in the module loader,
+               //        the dependencies of any actual appengine/* library end up here.
+               dir := findStandardImportPath(path)
+               if dir != "" {
+                       return dir, path, nil
                }
                return "", "", errMissing
        }
diff --git a/src/cmd/go/testdata/script/mod_std_vendor.txt b/src/cmd/go/testdata/script/mod_std_vendor.txt
new file mode 100644 (file)
index 0000000..36d4ffc
--- /dev/null
@@ -0,0 +1,19 @@
+env GO111MODULE=on
+
+go list -f '{{.TestImports}}'
+stdout net/http # from .TestImports
+
+go list -test -f '{{.Deps}}'
+stdout golang_org/x/crypto # dep of .TestImports
+
+-- go.mod --
+module m
+
+-- x.go --
+package x
+
+-- x_test.go --
+package x
+import "testing"
+import _ "net/http"
+func Test(t *testing.T) {}