]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: use internal/goroot to check for a standard library package
authorIan Lance Taylor <iant@golang.org>
Tue, 25 Sep 2018 20:01:27 +0000 (13:01 -0700)
committerIan Lance Taylor <iant@golang.org>
Tue, 25 Sep 2018 22:07:55 +0000 (22:07 +0000)
Change-Id: I739728f976162a0b8425a93666e3694d967dceb7
Reviewed-on: https://go-review.googlesource.com/137436
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/go/internal/modload/build.go
src/cmd/go/internal/modload/import.go

index 06636c4f4ff4277900030763458b1b9e5f3b4a50..acee4a91e7ce3e93d18ff9836b498525e937dc9e 100644 (file)
@@ -14,6 +14,7 @@ import (
        "cmd/go/internal/search"
        "encoding/hex"
        "fmt"
+       "internal/goroot"
        "os"
        "path/filepath"
        "strings"
@@ -30,13 +31,11 @@ func isStandardImportPath(path string) bool {
 
 func findStandardImportPath(path string) string {
        if search.IsStandardImportPath(path) {
-               dir := filepath.Join(cfg.GOROOT, "src", path)
-               if _, err := os.Stat(dir); err == nil {
-                       return dir
+               if goroot.IsStandardPackage(cfg.GOROOT, cfg.BuildContext.Compiler, path) {
+                       return filepath.Join(cfg.GOROOT, "src", path)
                }
-               dir = filepath.Join(cfg.GOROOT, "src/vendor", path)
-               if _, err := os.Stat(dir); err == nil {
-                       return dir
+               if goroot.IsStandardPackage(cfg.GOROOT, cfg.BuildContext.Compiler, "vendor/"+path) {
+                       return filepath.Join(cfg.GOROOT, "src/vendor", path)
                }
        }
        return ""
index 12d9407f6e6966bcf40d9d9896abfcd0894f3a98..44c2a2372670b5c50eb008db4a8b6769d0ec0481 100644 (file)
@@ -9,6 +9,7 @@ import (
        "errors"
        "fmt"
        "go/build"
+       "internal/goroot"
        "os"
        "path/filepath"
        "strings"
@@ -60,8 +61,8 @@ func Import(path string) (m module.Version, dir string, err error) {
                if strings.HasPrefix(path, "golang_org/") {
                        return module.Version{}, filepath.Join(cfg.GOROOT, "src/vendor", path), nil
                }
-               dir := filepath.Join(cfg.GOROOT, "src", path)
-               if _, err := os.Stat(dir); err == nil {
+               if goroot.IsStandardPackage(cfg.GOROOT, cfg.BuildContext.Compiler, path) {
+                       dir := filepath.Join(cfg.GOROOT, "src", path)
                        return module.Version{}, dir, nil
                }
        }