From bb48152dd26ddd1d7a36a2b65759b81dfdfe8f65 Mon Sep 17 00:00:00 2001 From: Philipp Stephani Date: Tue, 9 Jan 2024 15:46:50 +0100 Subject: [PATCH] Factor out workaround for https://github.com/bazelbuild/bazel/issues/15916 --- MODULE.bazel.lock | 6 +++--- elisp/repositories.bzl | 8 ++------ examples/ext/MODULE.bazel.lock | 4 ++-- private/repositories.bzl | 17 +++++++++++++++++ 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 42e6c18f..70c1ef96 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -1757,7 +1757,7 @@ "moduleExtensions": { "//elisp:extensions.bzl%elisp": { "general": { - "bzlTransitiveDigest": "K3o5acmeGmC9bbITLl3P9/mCvLalqbpYIyGBII/4gMA=", + "bzlTransitiveDigest": "RX7ciNZJ3uB9b1Rk+XeUHh+hWe4al3H+BL1HH4bWGLc=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { @@ -1781,7 +1781,7 @@ }, "//private:extensions.bzl%non_module_deps": { "general": { - "bzlTransitiveDigest": "+ujkSHA9D5KZX/YVsxoLIPa/JtvlyD94AcKWGY/iUc0=", + "bzlTransitiveDigest": "1QAEK6o89cAls+iWYyftZl4I2kMPeCEGAd06Qcg+YN4=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { @@ -1839,7 +1839,7 @@ }, "//private:extensions.bzl%non_module_dev_deps": { "general": { - "bzlTransitiveDigest": "+ujkSHA9D5KZX/YVsxoLIPa/JtvlyD94AcKWGY/iUc0=", + "bzlTransitiveDigest": "1QAEK6o89cAls+iWYyftZl4I2kMPeCEGAd06Qcg+YN4=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { diff --git a/elisp/repositories.bzl b/elisp/repositories.bzl index 5b2ea27c..388038f3 100644 --- a/elisp/repositories.bzl +++ b/elisp/repositories.bzl @@ -16,7 +16,7 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") -load("//private:repositories.bzl", "HTTP_ARCHIVE_ATTRS", "HTTP_ARCHIVE_DOC", "non_module_deps") +load("//private:repositories.bzl", "HTTP_ARCHIVE_ATTRS", "HTTP_ARCHIVE_DOC", "label_str", "non_module_deps") def rules_elisp_dependencies(): """Installs necessary dependencies for Emacs Lisp rules. @@ -100,10 +100,6 @@ def _elisp_http_archive_impl(repository_ctx): integrity = repository_ctx.attr.integrity or fail("missing archive checksum"), stripPrefix = repository_ctx.attr.strip_prefix, ) - defs_bzl = str(repository_ctx.attr._defs_bzl) - if not defs_bzl.startswith("@"): - # Work around https://github.com/bazelbuild/bazel/issues/15916. - defs_bzl = "@" + defs_bzl repository_ctx.template( "WORKSPACE.bazel", Label("//elisp:WORKSPACE.template"), @@ -116,7 +112,7 @@ def _elisp_http_archive_impl(repository_ctx): "BUILD.bazel", Label("//elisp:BUILD.template"), { - "[[defs_bzl]]": repr(defs_bzl), + "[[defs_bzl]]": repr(label_str(repository_ctx.attr._defs_bzl)), "[[exclude]]": repr(repository_ctx.attr.exclude), }, executable = False, diff --git a/examples/ext/MODULE.bazel.lock b/examples/ext/MODULE.bazel.lock index 8b800faf..db96fe8a 100644 --- a/examples/ext/MODULE.bazel.lock +++ b/examples/ext/MODULE.bazel.lock @@ -1308,7 +1308,7 @@ }, "@@phst_rules_elisp~override//elisp:extensions.bzl%elisp": { "general": { - "bzlTransitiveDigest": "K3o5acmeGmC9bbITLl3P9/mCvLalqbpYIyGBII/4gMA=", + "bzlTransitiveDigest": "RX7ciNZJ3uB9b1Rk+XeUHh+hWe4al3H+BL1HH4bWGLc=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { @@ -1332,7 +1332,7 @@ }, "@@phst_rules_elisp~override//private:extensions.bzl%non_module_deps": { "general": { - "bzlTransitiveDigest": "+ujkSHA9D5KZX/YVsxoLIPa/JtvlyD94AcKWGY/iUc0=", + "bzlTransitiveDigest": "1QAEK6o89cAls+iWYyftZl4I2kMPeCEGAd06Qcg+YN4=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { diff --git a/private/repositories.bzl b/private/repositories.bzl index 05b34050..c75e6bb5 100644 --- a/private/repositories.bzl +++ b/private/repositories.bzl @@ -70,6 +70,23 @@ def non_module_dev_deps(): ) _bazel_version(name = "phst_rules_elisp_bazel_version") +def label_str(label): + """Return a unique string form of a label. + + Args: + label: a Label object + + Returns: + a string representing an absolute form of the label + """ + + # TODO: Replace with plain ‘str’ once we drop support for Bazel 5. + ret = str(label) + if not ret.startswith("@"): + # Work around https://github.com/bazelbuild/bazel/issues/15916. + ret = "@" + ret + return ret + def _toolchains_impl(repository_ctx): windows = repository_ctx.os.name.startswith("windows") target = Label("//elisp:windows-toolchains.BUILD" if windows else "//elisp:unix-toolchains.BUILD")