Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions protoc/private/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load(":prebuilt_protoc_toolchain_test.bzl", "release_version_to_artifact_name_test_suite")

bzl_library(
name = "versions",
srcs = ["versions.bzl"],
visibility = ["//protoc:__subpackages__"],
)

release_version_to_artifact_name_test_suite()
19 changes: 16 additions & 3 deletions protoc/private/prebuilt_protoc_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,27 @@ GOOGLE_PROTOBUF_DEP_EDGES = {
"wrappers": [],
}

def release_version_to_artifact_name(release_version, platform):
# versions have a "v" prefix like "v28.0"
stripped_version = release_version.removeprefix("v")

# release candidate versions like "v29.0-rc3" have artifact names
# like "protoc-29.0-rc-3-osx-x86_64.zip"
artifact_version = stripped_version.replace("rc", "rc-")

return "{}-{}-{}.zip".format(
"protoc",
artifact_version,
platform,
)

def _prebuilt_protoc_repo_impl(rctx):
release_version = rctx.attr.version
if release_version == "LATEST":
release_version = PROTOC_VERSIONS.keys()[0]

filename = "{}-{}-{}.zip".format(
"protoc",
release_version.removeprefix("v"),
filename = release_version_to_artifact_name(
release_version,
rctx.attr.platform,
)
url = "https://github.com/protocolbuffers/protobuf/releases/download/{}/{}".format(
Expand Down
31 changes: 31 additions & 0 deletions protoc/private/prebuilt_protoc_toolchain_test.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Unit test suite for version-to-artifact-name resolution helper.

Based on the example at https://bazel.build/rules/testing#testing-starlark-utilities
"""

load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest")
load(":prebuilt_protoc_toolchain.bzl", "release_version_to_artifact_name")
load(":versions.bzl", "PROTOC_VERSIONS")

def _release_version_to_artifact_name_test_impl(ctx):
env = unittest.begin(ctx)
count = 0

for release_version in PROTOC_VERSIONS:
artifact_name = release_version_to_artifact_name(release_version, "linux-x86_64")
artifact_dict = PROTOC_VERSIONS[release_version]

# there should be a linux-x86_64 artifact in every release
asserts.true(env, artifact_name in artifact_dict, "'{}' not found for release version '{}'".format(artifact_name, release_version))
count += 1

asserts.true(env, count > 0, "no versions tested")
return unittest.end(env)

release_version_to_artifact_name_test = unittest.make(_release_version_to_artifact_name_test_impl)

def release_version_to_artifact_name_test_suite():
unittest.suite(
"release_version_to_artifact_name_tests",
release_version_to_artifact_name_test,
)
Loading