Skip to content

Commit 4177d70

Browse files
evanjsimontoens
authored andcommitted
detect_sdk_version: Support 1.21's new VERSION file format (bazel-contrib#3600)
* detect_sdk_version: Support 1.21's new VERSION file format Go 1.21 changes VERSION to have the Go version on the first line, then include additional key/value pairs on subsequent lines. Right now it only has a "time" key, but may contain others in the future. This changes detect_sdk_version to only take the first line in the file, rather than the entire file. This is necessary to support Go 1.21. I tested this by changing WORKSPACE to use "go1.21rc2". Fixes: ERROR: .../rules_go/WORKSPACE:8:23: fetching go_download_sdk_rule rule //external:go_sdk: Traceback (most recent call last): File ".../rules_go/go/private/sdk.bzl", line 120, column 43, in _go_download_sdk_impl detected_version = _detect_sdk_version(ctx, ".") File ".../rules_go/go/private/sdk.bzl", line 550, column 17, in _detect_sdk_version fail("SDK is version %s, but version %s was expected" % (version, ctx.attr.version)) Error in fail: SDK is version 1.21rc2 time 2023-06-21T02:00:01Z , but version 1.21rc2 was expected * clarify the string manipulation operation
1 parent 9838ee5 commit 4177d70

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

go/private/sdk.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,9 @@ def _detect_sdk_version(ctx, goroot):
426426
version_file_path = goroot + "/VERSION"
427427
if ctx.path(version_file_path).exists:
428428
# VERSION file has version prefixed by go, eg. go1.18.3
429-
version = ctx.read(version_file_path)[2:]
429+
# 1.21: The version is the first line
430+
version_line = ctx.read(version_file_path).splitlines()[0]
431+
version = version_line[2:]
430432
if ctx.attr.version and ctx.attr.version != version:
431433
fail("SDK is version %s, but version %s was expected" % (version, ctx.attr.version))
432434
return version

0 commit comments

Comments
 (0)