Skip to content

Commit

Permalink
Use top level VERSION file when it exists (#3309)
Browse files Browse the repository at this point in the history
  • Loading branch information
linzhp authored Sep 30, 2022
1 parent 3e0fcc4 commit 59a8d2c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions go/private/sdk.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,15 @@ def _detect_sdk_platform(ctx, goroot):
return platforms[0]

def _detect_sdk_version(ctx, goroot):
version_file_path = goroot + "/VERSION"
if ctx.path(version_file_path).exists:
version_contents = ctx.read(version_file_path)

# VERSION file has version prefixed by go, eg. go1.18.3
return version_contents[2:]

# The top-level VERSION file does not exist in all Go SDK distributions, e.g. those shipped by Debian or Fedora.
# Falling back to running "go version"
go_binary_path = goroot + "/bin/go"
result = ctx.execute([go_binary_path, "version"])
if result.return_code != 0:
Expand Down

0 comments on commit 59a8d2c

Please sign in to comment.