} else if path := pathInModuleCache(dir); path != "" {
pkg = path
} else {
+ pkg = ""
if !iterating {
base.Errorf("go: directory %s outside available modules", base.ShortPath(dir))
}
+ }
+ info, err := os.Stat(dir)
+ if err != nil || !info.IsDir() {
+ // If the directory does not exist,
+ // don't turn it into an import path
+ // that will trigger a lookup.
pkg = ""
+ if !iterating {
+ if err != nil {
+ base.Errorf("go: no such directory %v", m.Pattern)
+ } else {
+ base.Errorf("go: %s is not a directory", m.Pattern)
+ }
+ }
}
m.Pkgs[i] = pkg
}
stdout ^m/y$
! stdout ^m/y/z
+# non-existent directory should not prompt lookups
+! go build -mod=readonly example.com/nonexist
+stderr 'import lookup disabled'
+
+! go build -mod=readonly ./nonexist
+! stderr 'import lookup disabled'
+stderr '^go: no such directory ./nonexist'
+
+! go build -mod=readonly ./go.mod
+! stderr 'import lookup disabled'
+stderr '^go: ./go.mod is not a directory'
+
-- x/go.mod --
module m
stdout ^math$
go list -f '{{.ImportPath}}' .
stdout ^x$
+! go list -f '{{.ImportPath}}' $GOPATH/pkg/mod/rsc.io/quote@v1.5.2
+stderr '^go: no such directory.*quote@v1.5.2'
+go mod download rsc.io/quote@v1.5.2
go list -f '{{.ImportPath}}' $GOPATH/pkg/mod/rsc.io/quote@v1.5.2
stdout '^rsc.io/quote$'
go list -f '{{.ImportPath}}' $GOPATH/pkg/mod/rsc.io/sampler@v1.3.0
stdout '^rsc.io/sampler$'
-go get rsc.io/sampler@v1.3.1
+go get -d rsc.io/sampler@v1.3.1
go list -f '{{.ImportPath}}' $GOPATH/pkg/mod/rsc.io/sampler@v1.3.1
stdout '^rsc.io/sampler$'
! go list -f '{{.ImportPath}}' $GOPATH/pkg/mod/rsc.io/sampler@v1.3.0