Fix prerelease (#708)
* fix: use source toolchains for git archive prereleases
* Add comment about "g" prefix
diff --git a/lib/repositories.bzl b/lib/repositories.bzl
index b108961..a1fcb4c 100644
--- a/lib/repositories.bzl
+++ b/lib/repositories.bzl
@@ -10,7 +10,7 @@
load("//lib/private:source_toolchains_repo.bzl", "source_toolchains_repo")
load("//lib/private:tar_toolchain.bzl", "BSDTAR_PLATFORMS", "bsdtar_binary_repo", "tar_toolchains_repo")
load("//lib/private:yq_toolchain.bzl", "YQ_PLATFORMS", "yq_host_alias_repo", "yq_platform_repo", "yq_toolchains_repo", _DEFAULT_YQ_VERSION = "DEFAULT_YQ_VERSION")
-load("//tools:version.bzl", "VERSION")
+load("//tools:version.bzl", "IS_PRERELEASE")
# buildifier: disable=unnamed-macro
def aspect_bazel_lib_dependencies():
@@ -215,7 +215,7 @@
register: whether to call through to native.register_toolchains.
Should be True for WORKSPACE users, but false when used under bzlmod extension
"""
- if VERSION == "0.0.0":
+ if IS_PRERELEASE:
source_toolchains_repo(
name = "%s_toolchains" % name,
toolchain_type = "@aspect_bazel_lib//lib:copy_directory_toolchain_type",
@@ -250,7 +250,7 @@
register: whether to call through to native.register_toolchains.
Should be True for WORKSPACE users, but false when used under bzlmod extension
"""
- if VERSION == "0.0.0":
+ if IS_PRERELEASE:
source_toolchains_repo(
name = "%s_toolchains" % name,
toolchain_type = "@aspect_bazel_lib//lib:copy_to_directory_toolchain_type",
@@ -285,7 +285,7 @@
register: whether to call through to native.register_toolchains.
Should be True for WORKSPACE users, but false when used under bzlmod extension
"""
- if VERSION == "0.0.0":
+ if IS_PRERELEASE:
source_toolchains_repo(
name = "%s_toolchains" % name,
toolchain_type = "@aspect_bazel_lib//lib:expand_template_toolchain_type",
diff --git a/tools/version.bzl b/tools/version.bzl
index 86f9ae4..ad54a4e 100644
--- a/tools/version.bzl
+++ b/tools/version.bzl
@@ -5,3 +5,11 @@
_VERSION_PRIVATE = "$Format:%(describe:tags=true)$"
VERSION = "0.0.0" if _VERSION_PRIVATE.startswith("$Format") else _VERSION_PRIVATE.replace("v", "", 1)
+
+# Whether bazel-lib is a pre-release, and therefore has no release artifacts to download.
+# NB: When GitHub runs `git archive` to serve a source archive file,
+# it honors our .gitattributes and stamps this file, e.g.
+# _VERSION_PRIVATE = "v2.0.3-7-g57bfe2c1"
+# From https://git-scm.com/docs/git-describe:
+# > The "g" prefix stands for "git"
+IS_PRERELEASE = VERSION == "0.0.0" or VERSION.find("g") >= 0