codeql
codeql copied to clipboard
Go: Use `toolchain` directives for version selection if available, and add tests
Context
In Go 1.21, the Go team started making a distinction between language and toolchain versions. Historically, the Go version is declared with a go
directive in a go.mod
file, or a go.work
file. Since Go 1.21, go
directives are used to declare the language version. A new toolchain
directive may be used to explicitly declare the toolchain version. For backwards compatibility, if there is no toolchain
directive, the language version is used as the toolchain version. In the Go autobuilder, we have numerous places where we try to determine the "version" of Go that is in use, should be installed, etc. Here, we are mainly interested in the toolchain version.
What this PR addresses
So far, we have mainly been looking at go
directives in go.mod
files, and recently go.work
files, for this. However, if a toolchain
directive is present in either type of file, then this determines the toolchain version. We have not been considering this and this PR addresses that shortcoming by modifying the autobuilder to check for the presence of toolchain
directives when determining the version that is in use.
This PR also adds a number of tests for the functions involved in this process.
How to review
Best reviewed commit-by-commit.