Skip to content

Commit 4b5a236

Browse files
committed
Short circuit for buildmod vendor
1 parent bd5de19 commit 4b5a236

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/cmd/go/internal/modload/import.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -546,10 +546,12 @@ func queryImport(ctx context.Context, path string, rs *Requirements) (module.Ver
546546
return module.Version{}, &ImportMissingError{Path: path, isStd: true}
547547
}
548548

549-
if cfg.BuildMod == "readonly" && !allowMissingModuleImports {
549+
if (cfg.BuildMod == "readonly" || cfg.BuildMod == "vendor") && !allowMissingModuleImports {
550550
// In readonly mode, we can't write go.mod, so we shouldn't try to look up
551551
// the module. If readonly mode was enabled explicitly, include that in
552552
// the error message.
553+
// In vendor mode, we cannot use the network or module cache, so we
554+
// shouldn't try to look up the module
553555
var queryErr error
554556
if cfg.BuildModExplicit {
555557
queryErr = fmt.Errorf("import lookup disabled by -mod=%s", cfg.BuildMod)

src/cmd/go/testdata/script/mod_go_version_missing.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ cmp go.mod go.mod.orig
2727

2828
! go list -mod=vendor all
2929
! stderr '^go: inconsistent vendoring'
30-
stderr 'go: finding module for package example.com/badedit'
31-
stderr 'cannot query module due to -mod=vendor'
30+
stderr 'cannot find module providing package example.com/badedit: import lookup disabled by -mod=vendor'
3231

3332
# When we set -mod=mod, the go version should be updated immediately,
3433
# to the current version, converting the requirements from eager to lazy.

src/cmd/go/testdata/script/mod_std_vendor.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ cd broken
2222
! go build -mod=readonly
2323
stderr 'disabled by -mod=readonly'
2424
! go build -mod=vendor
25-
stderr 'go: finding module for package golang.org/x/net/http2/hpack'
26-
stderr 'http.go:5:2: cannot query module due to -mod=vendor'
25+
stderr 'http.go:5:2: cannot find module providing package golang.org/x/net/http2/hpack: import lookup disabled by -mod=vendor'
2726

2827

2928
# ...even if they explicitly use the "cmd/vendor/" or "vendor/" prefix.

0 commit comments

Comments
 (0)