Skip to content
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: Better determine Go versions in Go 1.21+ #14194

Closed
wants to merge 8 commits into from

Conversation

mbg
Copy link
Member

@mbg mbg commented Sep 12, 2023

Summary

In Go 1.21 and above, go commands will try to download the version of Go that is specified in the go.mod file. This means that running e.g. go version in a folder with a go.mod file won't actually return the version of the Go tools installed on the system, but will instead cause them to try and download the version specified in go.mod and then invoke the downloaded toolchain's version command.

We now work around this by invoking go version outside of the working directory in a location where we assume no go.mod file is present, as this will cause the go tool to print its own version. with GOTOOLCHAIN=local (thanks @smowton!)

We further lay some groundwork for understanding the new Go version format and toolchain directives.

The newer-go-version-needed test / diagnostic essentially no longer applies to Go 1.21 and above. We do not currently have the test infrastructure to test with multiple system versions of Go in place, so I have removed the expected diagnostic output.

@mbg mbg added the Go label Sep 12, 2023
@mbg mbg requested a review from smowton September 12, 2023 19:33
@mbg mbg self-assigned this Sep 12, 2023
@mbg mbg requested a review from a team as a code owner September 12, 2023 19:33
@mbg
Copy link
Member Author

mbg commented Sep 12, 2023

Test failures are expected until the internal PR is merged, I think.

@mbg mbg force-pushed the mbg/go/1.21-toolchain-handling branch from a308622 to 406e2b8 Compare September 13, 2023 12:24
smowton
smowton previously approved these changes Sep 13, 2023
owen-mc
owen-mc previously approved these changes Sep 20, 2023
@mbg mbg marked this pull request as draft September 22, 2023 13:50
@mbg mbg changed the base branch from rc/3.11 to main September 22, 2023 13:54
@mbg mbg dismissed owen-mc’s stale review September 22, 2023 13:54

The base branch was changed.

@mbg mbg force-pushed the mbg/go/1.21-toolchain-handling branch from afae037 to 67a2bfd Compare September 22, 2023 13:54
@mbg mbg marked this pull request as ready for review September 22, 2023 14:46
owen-mc
owen-mc previously approved these changes Sep 26, 2023
mbg added 8 commits October 6, 2023 11:44
Refactors `tryReadGoDirective` to return this instead of a pair.
This will make it easier to return multiple versions.
- Use a version that is accepted by Go tooling
- Run is no longer successful with Go 1.21
We allow them, but don't do anything with them yet.
@mbg
Copy link
Member Author

mbg commented May 1, 2024

Closing this PR since most of the changes have made their way into the autobuilder elsewhere since. I opened #16375 for the more tolerant version regex. Better handling of toolchain versions is still required.

@mbg mbg closed this May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants