diff --git a/lib/private/coreutils_toolchain.bzl b/lib/private/coreutils_toolchain.bzl index 318da6c3d..6db35a97d 100644 --- a/lib/private/coreutils_toolchain.bzl +++ b/lib/private/coreutils_toolchain.bzl @@ -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 # @@ -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=", @@ -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( @@ -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") @@ -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()), }, ) diff --git a/lib/repositories.bzl b/lib/repositories.bzl index 1562438b0..071af4bb3 100644 --- a/lib/repositories.bzl +++ b/lib/repositories.bzl @@ -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") @@ -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 """ @@ -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)) diff --git a/tools/coreutils_mirror_release.sh b/tools/coreutils_mirror_release.sh index 5b3a681ff..1cbec7d86 100755 --- a/tools/coreutils_mirror_release.sh +++ b/tools/coreutils_mirror_release.sh @@ -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