From 59a8d2c174ac47bc5bafb76b311ee2adc5c31bbf Mon Sep 17 00:00:00 2001 From: Zhongpeng Lin Date: Fri, 30 Sep 2022 14:14:07 -0700 Subject: [PATCH] Use top level VERSION file when it exists (#3309) --- go/private/sdk.bzl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/go/private/sdk.bzl b/go/private/sdk.bzl index 9a092e12c3..8a5342b693 100644 --- a/go/private/sdk.bzl +++ b/go/private/sdk.bzl @@ -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: