Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add fallback_version to register_coreutils_toolchains #850

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
33 changes: 26 additions & 7 deletions lib/private/coreutils_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ COREUTILS_PLATFORMS = {
}

DEFAULT_COREUTILS_VERSION = "0.0.26"
DEFAULT_FALLBACK_COREUTILS_VERSION = "0.0.23"

# https://github.com/uutils/coreutils/releases
#
Expand All @@ -50,10 +51,6 @@ COREUTILS_VERSIONS = {
"filename": "coreutils-0.0.26-aarch64-unknown-linux-musl.tar.gz",
"sha256": "sha256-9zGLFOMDjUDbraDY/hrE5zFJ0O+QYrvx2wHk3Gw3q/A=",
},
"darwin_amd64": {
"filename": "coreutils-0.0.23-x86_64-apple-darwin.tar.gz",
"sha256": "sha256-SswetVAuK/hMK1r9uBvNnKj5JpSgD0bzkbsHTxOabCo=",
},
"windows_amd64": {
"filename": "coreutils-0.0.26-x86_64-pc-windows-msvc.zip",
"sha256": "sha256-6qPkqxQZM4XBBBJ80t1uvzfZiz0gBeT/zoCdfqOO3uk=",
Expand All @@ -63,6 +60,24 @@ COREUTILS_VERSIONS = {
"sha256": "sha256-QpGVp3wmHqpt5Brd/bdj7pyMQNftcihOtaRI8z2uhp0=",
},
},
"0.0.23": {
"darwin_arm64": {
"filename": "coreutils-0.0.23-aarch64-apple-darwin.tar.gz",
"sha256": "sha256-KP90sjKxtXDbLC+o5f4+gQnvP3Tr7O0RopME4g9QF5E=",
},
"darwin_amd64": {
"filename": "coreutils-0.0.23-x86_64-apple-darwin.tar.gz",
"sha256": "sha256-SswetVAuK/hMK1r9uBvNnKj5JpSgD0bzkbsHTxOabCo=",
},
"windows_amd64": {
"filename": "coreutils-0.0.23-x86_64-pc-windows-msvc.zip",
"sha256": "sha256-aglIj5JvFGLm2ABwRzWAsZRTTD3X444V3GxHM9pGJS4=",
},
"linux_amd64": {
"filename": "coreutils-0.0.23-x86_64-unknown-linux-musl.tar.gz",
"sha256": "sha256-lZvDYhmmvsETKeJCJBsC4wYblJ2CRvqAVCs62UC1TdM=",
},
},
}

CoreUtilsInfo = provider(
Expand Down Expand Up @@ -175,15 +190,18 @@ coreutils_toolchains_repo = repository_rule(
def _coreutils_platform_repo_impl(rctx):
is_windows = rctx.attr.platform.startswith("windows_")
platform = rctx.attr.platform
filename = COREUTILS_VERSIONS[rctx.attr.version][platform]["filename"]
version = rctx.attr.version
if platform not in COREUTILS_VERSIONS[version]:
version = rctx.attr.fallback_version
filename = COREUTILS_VERSIONS[version][platform]["filename"]
url = "https://github.com/uutils/coreutils/releases/download/{}/{}".format(
rctx.attr.version,
version,
filename,
)
rctx.download_and_extract(
url = url,
stripPrefix = filename.replace(".zip", "").replace(".tar.gz", ""),
integrity = COREUTILS_VERSIONS[rctx.attr.version][platform]["sha256"],
integrity = COREUTILS_VERSIONS[version][platform]["sha256"],
)
build_content = """# @generated by @aspect_bazel_lib//lib/private:coreutils_toolchain.bzl
load("@aspect_bazel_lib//lib/private:coreutils_toolchain.bzl", "coreutils_toolchain")
Expand All @@ -199,6 +217,7 @@ coreutils_platform_repo = repository_rule(
doc = "Fetch external tools needed for coreutils toolchain",
attrs = {
"version": attr.string(mandatory = True, values = COREUTILS_VERSIONS.keys()),
"fallback_version": attr.string(mandatory = True, values = COREUTILS_VERSIONS.keys()),
"platform": attr.string(mandatory = True, values = COREUTILS_PLATFORMS.keys()),
},
)
7 changes: 5 additions & 2 deletions lib/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ load("//lib:utils.bzl", http_archive = "maybe_http_archive")
load("//lib/private:bats_toolchain.bzl", "BATS_ASSERT_VERSIONS", "BATS_CORE_TEMPLATE", "BATS_CORE_VERSIONS", "BATS_FILE_VERSIONS", "BATS_LIBRARY_TEMPLATE", "BATS_SUPPORT_VERSIONS")
load("//lib/private:copy_directory_toolchain.bzl", "COPY_DIRECTORY_PLATFORMS", "copy_directory_platform_repo", "copy_directory_toolchains_repo")
load("//lib/private:copy_to_directory_toolchain.bzl", "COPY_TO_DIRECTORY_PLATFORMS", "copy_to_directory_platform_repo", "copy_to_directory_toolchains_repo")
load("//lib/private:coreutils_toolchain.bzl", "COREUTILS_PLATFORMS", "coreutils_platform_repo", "coreutils_toolchains_repo", _DEFAULT_COREUTILS_VERSION = "DEFAULT_COREUTILS_VERSION")
load("//lib/private:coreutils_toolchain.bzl", "COREUTILS_PLATFORMS", "coreutils_platform_repo", "coreutils_toolchains_repo", _DEFAULT_COREUTILS_VERSION = "DEFAULT_COREUTILS_VERSION", _DEFAULT_FALLBACK_COREUTILS_VERSION = "DEFAULT_FALLBACK_COREUTILS_VERSION")
load("//lib/private:expand_template_toolchain.bzl", "EXPAND_TEMPLATE_PLATFORMS", "expand_template_platform_repo", "expand_template_toolchains_repo")
load("//lib/private:jq_toolchain.bzl", "JQ_PLATFORMS", "jq_host_alias_repo", "jq_platform_repo", "jq_toolchains_repo", _DEFAULT_JQ_VERSION = "DEFAULT_JQ_VERSION")
load("//lib/private:source_toolchains_repo.bzl", "source_toolchains_repo")
Expand Down Expand Up @@ -205,13 +205,15 @@ def register_bats_toolchains(

DEFAULT_COREUTILS_REPOSITORY = "coreutils"
DEFAULT_COREUTILS_VERSION = _DEFAULT_COREUTILS_VERSION
DEFAULT_FALLBACK_COREUTILS_VERSION = _DEFAULT_FALLBACK_COREUTILS_VERSION

def register_coreutils_toolchains(name = DEFAULT_COREUTILS_REPOSITORY, version = DEFAULT_COREUTILS_VERSION, register = True):
def register_coreutils_toolchains(name = DEFAULT_COREUTILS_REPOSITORY, version = DEFAULT_COREUTILS_VERSION, fallback_version = DEFAULT_FALLBACK_COREUTILS_VERSION, register = True):
"""Registers coreutils toolchain and repositories

Args:
name: override the prefix for the generated toolchain repositories
version: the version of coreutils to execute (see https://github.com/uutils/coreutils/releases)
fallback_version: the version of coreutils to execute (see https://github.com/uutils/coreutils/releases) only valid if {version}/{platform} not exist
register: whether to call through to native.register_toolchains.
Should be True for WORKSPACE users, but false when used under bzlmod extension
"""
Expand All @@ -220,6 +222,7 @@ def register_coreutils_toolchains(name = DEFAULT_COREUTILS_REPOSITORY, version =
name = "%s_%s" % (name, platform),
platform = platform,
version = version,
fallback_version = fallback_version,
)
if register:
native.register_toolchains("@%s_toolchains//:%s_toolchain" % (name, platform))
Expand Down
2 changes: 1 addition & 1 deletion tools/coreutils_mirror_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ JQ_FILTER='map({
}) | from_entries
'

INFO="$(curl --silent -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/uutils/coreutils/releases?per_page=1 | jq "$JQ_FILTER")"
INFO="$(curl --silent -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/uutils/coreutils/releases?per_page=${1:-1}" | jq "$JQ_FILTER")"

for VERSION in $(jq -r 'keys | join("\n")' <<<$INFO); do
for PLATFORM in $(jq -r ".[\"$VERSION\"] | keys | join(\"\n\")" <<<$INFO); do
Expand Down
Loading