Skip to content

Commit

Permalink
Factor out workaround for bazelbuild/bazel#15916
Browse files Browse the repository at this point in the history
  • Loading branch information
phst committed Jan 9, 2024
1 parent c45508f commit bb48152
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
6 changes: 3 additions & 3 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions elisp/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"),
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions examples/ext/MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions private/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit bb48152

Please sign in to comment.