)
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 {
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
}
--- /dev/null
+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) {}