Skip to content

Commit c63f680

Browse files
committed
Go: Run go version with GOTOOLCHAIN=local
1 parent 76781e5 commit c63f680

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

go/extractor/cli/go-autobuilder/go-autobuilder.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,19 @@ var goVersion = ""
6161
// Returns the current Go version as returned by 'go version', e.g. go1.14.4
6262
func getEnvGoVersion() string {
6363
if goVersion == "" {
64-
gover, err := exec.Command("go", "version").CombinedOutput()
64+
// Since Go 1.21, running 'go version' in a directory with a 'go.mod' file will attempt to
65+
// download the version of Go specified in there. That may either fail or result in us just
66+
// being told what's already in 'go.mod'. Setting 'GOTOOLCHAIN' to 'local' will force it
67+
// to use the local Go toolchain instead.
68+
cmd := exec.Command("go", "version")
69+
cmd.Env = append(os.Environ(), "GOTOOLCHAIN=local")
70+
out, err := cmd.CombinedOutput()
71+
6572
if err != nil {
6673
log.Fatalf("Unable to run the go command, is it installed?\nError: %s", err.Error())
6774
}
68-
goVersion = parseGoVersion(string(gover))
75+
76+
goVersion = parseGoVersion(string(out))
6977
}
7078
return goVersion
7179
}

0 commit comments

Comments
 (0)