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

Add support for parsing Go development versions #3333

Merged
merged 1 commit into from
Oct 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions go/private/sdk.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,21 @@ def _detect_sdk_version(ctx, goroot):
if result.return_code != 0:
fail("Could not detect SDK version: '%s version' exited with exit code %d" % (go_binary_path, result.return_code))

# go version output is of the form "go version go1.18.3 linux/amd64"
# go version output is of the form "go version go1.18.3 linux/amd64" or "go
# version devel go1.19-fd1b5904ae Tue Mar 22 21:38:10 2022 +0000
# linux/amd64". See the following links for how this output is generated:
# - https://github.com/golang/go/blob/2bdb5c57f1efcbddab536028d053798e35de6226/src/cmd/go/internal/version/version.go#L75
# - https://github.com/golang/go/blob/2bdb5c57f1efcbddab536028d053798e35de6226/src/cmd/dist/build.go#L333
#
# Read the third word, or the fourth word if the third word is "devel", to
# find the version number.
output_parts = result.stdout.split(" ")
if len(output_parts) < 3 or not output_parts[2].startswith("go"):
if len(output_parts) > 2 and output_parts[2].startswith("go"):
version = output_parts[2][len("go"):]
if len(output_parts) > 3 and output_parts[2] == "devel" and output_parts[3].startswith("go"):
version = output_parts[3][len("go"):]
else:
fail("Could not parse SDK version from '%s version' output: %s" % (go_binary_path, result.stdout))
version = output_parts[2][len("go"):]
if _parse_version(version) == None:
fail("Could not parse SDK version from '%s version' output: %s" % (go_binary_path, result.stdout))
return version
Expand Down