]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: return an early error from queryImport when in vendor mode
authorrohnnyjoy <johnnyroy2718@gmail.com>
Sat, 18 Feb 2023 04:37:17 +0000 (04:37 +0000)
committerGopher Robot <gobot@golang.org>
Wed, 22 Feb 2023 16:11:33 +0000 (16:11 +0000)
The current behavior for -mod=vendor is to let QueryPackages run and
fail from queryImport: "cannot query module due to -mod=vendor".
This has the side effect of allowing "go: finding module for package"
to be printed to stderr. Instead of this, return an error before
running QueryPackages.

Fixes #58417

Change-Id: Idc0ed33d1dd1bd185348da3a18ba8eb2dd225909
GitHub-Last-Rev: dd09deec0afecabd1bffc34cfe66db0a8c124fd9
GitHub-Pull-Request: golang/go#58471
Reviewed-on: https://go-review.googlesource.com/c/go/+/467517
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
src/cmd/go/internal/modload/import.go
src/cmd/go/testdata/script/mod_go_version_missing.txt
src/cmd/go/testdata/script/mod_std_vendor.txt

index 90f2a7401aa9b33e40f3a83be87098cffface0fb..a8b4a2d21fbfc9d8669a9e3ac221eb2b4214c429 100644 (file)
@@ -546,10 +546,12 @@ func queryImport(ctx context.Context, path string, rs *Requirements) (module.Ver
                return module.Version{}, &ImportMissingError{Path: path, isStd: true}
        }
 
-       if cfg.BuildMod == "readonly" && !allowMissingModuleImports {
+       if (cfg.BuildMod == "readonly" || cfg.BuildMod == "vendor") && !allowMissingModuleImports {
                // In readonly mode, we can't write go.mod, so we shouldn't try to look up
                // the module. If readonly mode was enabled explicitly, include that in
                // the error message.
+               // In vendor mode, we cannot use the network or module cache, so we
+               // shouldn't try to look up the module
                var queryErr error
                if cfg.BuildModExplicit {
                        queryErr = fmt.Errorf("import lookup disabled by -mod=%s", cfg.BuildMod)
index f40b48fc7f8ad898dd46da9d64ececed22dc3ce5..e9a8e7291df6279261e7bc44bce1ba7e653d5015 100644 (file)
@@ -27,8 +27,7 @@ cmp go.mod go.mod.orig
 
 ! go list -mod=vendor all
 ! stderr '^go: inconsistent vendoring'
-stderr 'go: finding module for package example.com/badedit'
-stderr 'cannot query module due to -mod=vendor'
+stderr 'cannot find module providing package example.com/badedit: import lookup disabled by -mod=vendor'
 
 # When we set -mod=mod, the go version should be updated immediately,
 # to the current version, converting the requirements from eager to lazy.
index 7e4c210d3c35c907e7df26cc270a1782b06b90c3..ed47542a4e9df51df00feeb08d3d87615817a701 100644 (file)
@@ -22,9 +22,7 @@ cd broken
 ! go build -mod=readonly
 stderr 'disabled by -mod=readonly'
 ! go build -mod=vendor
-stderr 'go: finding module for package golang.org/x/net/http2/hpack'
-stderr 'http.go:5:2: cannot query module due to -mod=vendor'
-
+stderr 'http.go:5:2: cannot find module providing package golang.org/x/net/http2/hpack: import lookup disabled by -mod=vendor'
 
 # ...even if they explicitly use the "cmd/vendor/" or "vendor/" prefix.
 cd ../importcmd