1
0
mirror of https://github.com/golang/go synced 2024-09-25 05:20:13 -06:00

cmd/go: use internal/goroot to check for a standard library package

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>
This commit is contained in:
Ian Lance Taylor 2018-09-25 13:01:27 -07:00
parent b83ef36d6a
commit 93ad702251
2 changed files with 8 additions and 8 deletions

View 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 ""

View 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
}
}