Skip to content

Commit 2c66cee

Browse files
committed
fix filename for rc versions
1 parent e6ce326 commit 2c66cee

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

examples/MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ protoc = use_extension("@toolchains_protoc//protoc:extensions.bzl", "protoc")
1919
protoc.toolchain(
2020
google_protobuf = "com_google_protobuf",
2121
# Demonstrate overriding the default version
22-
version = "v28.0",
22+
version = "LATEST",
2323
)
2424
use_repo(protoc, "com_google_protobuf", "toolchains_protoc_hub")
2525

protoc/private/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
2+
load(":prebuilt_protoc_toolchain_test.bzl", "release_version_to_artifact_name_test_suite")
23

34
bzl_library(
45
name = "versions",
56
srcs = ["versions.bzl"],
67
visibility = ["//protoc:__subpackages__"],
78
)
9+
10+
release_version_to_artifact_name_test_suite()

protoc/private/prebuilt_protoc_toolchain.bzl

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,28 @@ GOOGLE_PROTOBUF_DEP_EDGES = {
2222
"wrappers": [],
2323
}
2424

25+
def release_version_to_artifact_name(release_version, platform):
26+
# versions have a "v" prefix like "v28.0"
27+
stripped_version = release_version.removeprefix("v")
28+
29+
# release candidate versions like "v29.0-rc3" have artifact names
30+
# like "protoc-29.0-rc-3-osx-x86_64.zip"
31+
artifact_version = stripped_version.replace("rc", "rc-")
32+
33+
return "{}-{}-{}.zip".format(
34+
"protoc",
35+
artifact_version,
36+
platform,
37+
)
38+
2539
def _prebuilt_protoc_repo_impl(rctx):
2640
release_version = rctx.attr.version
2741
if release_version == "LATEST":
2842
release_version = PROTOC_VERSIONS.keys()[0]
2943

30-
filename = "{}-{}-{}.zip".format(
31-
"protoc",
32-
release_version.removeprefix("v"),
33-
rctx.attr.platform,
44+
filename = release_version_to_artifact_name(
45+
release_version,
46+
rctx.attr.platform
3447
)
3548
url = "https://github.com/protocolbuffers/protobuf/releases/download/{}/{}".format(
3649
release_version,
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""Unit test suite for version-to-artifact-name resolution helper.
2+
3+
Based on the example at https://bazel.build/rules/testing#testing-starlark-utilities
4+
"""
5+
6+
load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest")
7+
load(":prebuilt_protoc_toolchain.bzl", "release_version_to_artifact_name")
8+
load(":versions.bzl", "PROTOC_VERSIONS")
9+
10+
def _release_version_to_artifact_name_test_impl(ctx):
11+
env = unittest.begin(ctx)
12+
count = 0
13+
14+
for release_version in PROTOC_VERSIONS:
15+
artifact_name = release_version_to_artifact_name(release_version, "linux-x86_64")
16+
artifact_dict = PROTOC_VERSIONS[release_version]
17+
# there should be a linux-x86_64 artifact in every release
18+
asserts.true(env, artifact_name in artifact_dict, "'{}' not found for release version '{}'".format(artifact_name, release_version))
19+
count += 1
20+
21+
asserts.true(env, count > 0, "no versions tested")
22+
return unittest.end(env)
23+
24+
release_version_to_artifact_name_test = unittest.make(_release_version_to_artifact_name_test_impl)
25+
26+
def release_version_to_artifact_name_test_suite():
27+
unittest.suite(
28+
"release_version_to_artifact_name_tests",
29+
release_version_to_artifact_name_test,
30+
)

0 commit comments

Comments
 (0)