Skip to content

Commit

Permalink
extension/src/util: do not use cached go version with GOTOOLCHAIN
Browse files Browse the repository at this point in the history
CL 577095 https://go-review.googlesource.com/c/vscode-go/+/577095
made a change to compute the go version used for tools installation
using `GOTOOLCHAIN=local go version`. However, that's not sufficient.
There is a go version cache (cachedGoVersion) and if the go binary
path is same, getGoVersion uses the cachedGoVersion. But after go1.21
this assumption doesn't hold because the same go binary can return
different go version depending on its toolchain switch mode.

For now, skip caching if getGoVersion is called with non-default
GOTOOLCHAIN param. We use this mode of getGoVersion only during
tool installation, which is supposed to be rare.

For #3168

Change-Id: Id33536d70b74afee592e4a98bd59865e41dbea49
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/583975
Commit-Queue: Hyang-Ah Hana Kim <hyangah@gmail.com>
kokoro-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
  • Loading branch information
hyangah committed May 10, 2024
1 parent f907536 commit 5d8af43
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions extension/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export async function getGoVersion(goBinPath?: string, GOTOOLCHAIN?: string): Pr
if (!goRuntimePath) {
throw error(`unable to locate "go" binary in GOROOT (${getCurrentGoRoot()}) or PATH (${getEnvPath()})`);
}
if (cachedGoBinPath === goRuntimePath && cachedGoVersion) {
if (GOTOOLCHAIN === undefined && cachedGoBinPath === goRuntimePath && cachedGoVersion) {
if (cachedGoVersion.isValid()) {
return Promise.resolve(cachedGoVersion);
}
Expand All @@ -205,7 +205,7 @@ export async function getGoVersion(goBinPath?: string, GOTOOLCHAIN?: string): Pr
} catch (err) {
throw error(`failed to run "${goRuntimePath} version": ${err} cwd: ${cwd}`);
}
if (!goBinPath && !GOTOOLCHAIN) {
if (!goBinPath && GOTOOLCHAIN === undefined) {
// if getGoVersion was called with a given goBinPath or an explicit GOTOOLCHAIN env var, don't cache the result.
cachedGoBinPath = goRuntimePath;
cachedGoVersion = goVersion;
Expand Down

0 comments on commit 5d8af43

Please sign in to comment.