diff options
author | Bryan C. Mills <bcmills@google.com> | 2023-07-13 10:12:33 -0400 |
---|---|---|
committer | Gopher Robot <gobot@golang.org> | 2023-07-13 16:44:24 +0000 |
commit | b88bd917b8dd8aabc471b1de41b3ee8c0d6eeabe (patch) | |
tree | d52d9093aa2fdcae999da1ac3ef7e00e0315a23e | |
parent | d4f0d896a6856e3d6fc64d0e0714645844c59aa0 (diff) | |
download | go-b88bd917b8dd8aabc471b1de41b3ee8c0d6eeabe.tar.gz go-b88bd917b8dd8aabc471b1de41b3ee8c0d6eeabe.zip |
cmd/go/internal/modfetch: always allow Stat for the current toolchain to succeed
This fixes a failure mode observed in TestScript/gotoolchain_version
when building go1.21rc3.
Updates #61259.
Change-Id: Ifb14a5b94b687adea7a26c1155591e3ae75b7a62
Reviewed-on: https://go-review.googlesource.com/c/go/+/509217
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
-rw-r--r-- | src/cmd/go/internal/modfetch/toolchain.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/cmd/go/internal/modfetch/toolchain.go b/src/cmd/go/internal/modfetch/toolchain.go index 1669ab92e7..0d7cfcfe7d 100644 --- a/src/cmd/go/internal/modfetch/toolchain.go +++ b/src/cmd/go/internal/modfetch/toolchain.go @@ -98,13 +98,23 @@ func (r *toolchainRepo) Stat(ctx context.Context, rev string) (*RevInfo, error) if !gover.IsValid(v) { return nil, fmt.Errorf("invalid %s version %s", r.path, rev) } + // If we're asking about "go" (not "toolchain"), pretend to have // all earlier Go versions available without network access: // we will provide those ourselves, at least in GOTOOLCHAIN=auto mode. if r.path == "go" && gover.Compare(v, gover.Local()) <= 0 { return &RevInfo{Version: prefix + v}, nil } + + // Similarly, if we're asking about *exactly* the current toolchain, + // we don't need to access the network to know that it exists. + if r.path == "toolchain" && v == gover.Local() { + return &RevInfo{Version: prefix + v}, nil + } + if gover.IsLang(v) { + // We can only use a language (development) version if the current toolchain + // implements that version, and the two checks above have ruled that out. return nil, fmt.Errorf("go language version %s is not a toolchain version", rev) } |