-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Go: Use toolchain
directives for version selection if available, and add tests
#16453
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Broadly fine. I think you should add a few more comments to make it easier to reason about what strings have what prefixes. In the definitions of any structs that have a field containing a go version, add a comment after the field definition giving an example value, so that it's obvious what prefix is expected.
@owen-mc I addressed your comments, but I also realised that the first batch of changes in this PR meant that In retrospect, maybe it would be better to introduce a new type that's a wrapper around |
// A value indicating whether a version string was found | ||
// A value indicating whether a version string was found. | ||
// If this value is `true`, then `Version` is a valid semantic version. | ||
// IF this value is `false`, then `Version` is the empty string. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// IF this value is `false`, then `Version` is the empty string. | |
// If this value is `false`, then `Version` is the empty string. |
Replaced by #16703 |
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 ago.mod
file, or ago.work
file. Since Go 1.21,go
directives are used to declare the language version. A newtoolchain
directive may be used to explicitly declare the toolchain version. For backwards compatibility, if there is notoolchain
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 ingo.mod
files, and recentlygo.work
files, for this. However, if atoolchain
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 oftoolchain
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.