Skip to content

Commit

Permalink
Add support for parsing Go development versions
Browse files Browse the repository at this point in the history
  • Loading branch information
zakcutner committed Oct 25, 2022
1 parent fe4417d commit f06c8f3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions go/private/sdk.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,13 @@ 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.18.3 linux/amd64". Read the second-to-last argument to
# determine the version.
output_parts = result.stdout.split(" ")
if len(output_parts) < 3 or not output_parts[2].startswith("go"):
if len(output_parts) < 2 or not output_parts[-2].startswith("go"):
fail("Could not parse SDK version from '%s version' output: %s" % (go_binary_path, result.stdout))
version = output_parts[2][len("go"):]
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

0 comments on commit f06c8f3

Please sign in to comment.