Commit 93ad7022 authored by Ian Lance Taylor's avatar Ian Lance Taylor

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: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent b83ef36d
...@@ -14,6 +14,7 @@ import ( ...@@ -14,6 +14,7 @@ import (
"cmd/go/internal/search" "cmd/go/internal/search"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"internal/goroot"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
...@@ -30,13 +31,11 @@ func isStandardImportPath(path string) bool { ...@@ -30,13 +31,11 @@ func isStandardImportPath(path string) bool {
func findStandardImportPath(path string) string { func findStandardImportPath(path string) string {
if search.IsStandardImportPath(path) { if search.IsStandardImportPath(path) {
dir := filepath.Join(cfg.GOROOT, "src", path) if goroot.IsStandardPackage(cfg.GOROOT, cfg.BuildContext.Compiler, path) {
if _, err := os.Stat(dir); err == nil { return filepath.Join(cfg.GOROOT, "src", path)
return dir
} }
dir = filepath.Join(cfg.GOROOT, "src/vendor", path) if goroot.IsStandardPackage(cfg.GOROOT, cfg.BuildContext.Compiler, "vendor/"+path) {
if _, err := os.Stat(dir); err == nil { return filepath.Join(cfg.GOROOT, "src/vendor", path)
return dir
} }
} }
return "" return ""
......
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"go/build" "go/build"
"internal/goroot"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
...@@ -60,8 +61,8 @@ func Import(path string) (m module.Version, dir string, err error) { ...@@ -60,8 +61,8 @@ func Import(path string) (m module.Version, dir string, err error) {
if strings.HasPrefix(path, "golang_org/") { if strings.HasPrefix(path, "golang_org/") {
return module.Version{}, filepath.Join(cfg.GOROOT, "src/vendor", path), nil return module.Version{}, filepath.Join(cfg.GOROOT, "src/vendor", path), nil
} }
dir := filepath.Join(cfg.GOROOT, "src", path) if goroot.IsStandardPackage(cfg.GOROOT, cfg.BuildContext.Compiler, path) {
if _, err := os.Stat(dir); err == nil { dir := filepath.Join(cfg.GOROOT, "src", path)
return module.Version{}, dir, nil return module.Version{}, dir, nil
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment