Eliminate the workspace repo (#63)
Follow-up to #62: eliminate the need for the `[hub].workspace` repo and instead use the `[hub]` repo directly.
diff --git a/.github/workflows/release_prep.sh b/.github/workflows/release_prep.sh
index 18221fd..89608d2 100755
--- a/.github/workflows/release_prep.sh
+++ b/.github/workflows/release_prep.sh
@@ -64,7 +64,7 @@
)
# required since 0.15.0 to enable only downloading tools used by this workspace
-load("@multitool.workspace//:tools.bzl", "register_tools")
+load("@multitool//:tools.bzl", "register_tools")
register_tools()
\`\`\`
diff --git a/examples/workspace/WORKSPACE.bazel b/examples/workspace/WORKSPACE.bazel
index b94bb8c..1cd1424 100644
--- a/examples/workspace/WORKSPACE.bazel
+++ b/examples/workspace/WORKSPACE.bazel
@@ -9,6 +9,6 @@
lockfile = "//:multitool.lock.json",
)
-load("@multitool.workspace//:tools.bzl", "register_tools")
+load("@multitool//:tools.bzl", "register_tools")
register_tools()
diff --git a/multitool/private/workspace_hub_repo_template/tools.bzl.template b/multitool/private/hub_repo_template/tools.bzl.template
similarity index 100%
rename from multitool/private/workspace_hub_repo_template/tools.bzl.template
rename to multitool/private/hub_repo_template/tools.bzl.template
diff --git a/multitool/private/multitool.bzl b/multitool/private/multitool.bzl
index 7919f4b..c472eac 100644
--- a/multitool/private/multitool.bzl
+++ b/multitool/private/multitool.bzl
@@ -11,13 +11,7 @@
[tool-name]/
BUILD.bazel (export all *_executable files)
[os]_[cpu]_executable (a downloaded file or a symlink to a file in a
- downloaded and extracted archive)
-
- - [hub].workspace:
- Iff not running in bzlmod, a utility for registering the per-tool repos with Bazel.
-
- The structure of this repo is:
- tools.bzl (a file containing one utility method, "register_tools")
+ downloaded and extracted archive)
- [hub]:
This repository holds toolchain definitions for all tools in the provided
@@ -32,6 +26,7 @@
BUILD.bazel (declares the toolchain_type and the executable tool target)
tool.bzl (scaffolding for the tool target and toolchain declarations in toolchains/BUILD.bazel)
toolchain_info.bzl (common scaffolding for toolchain declarations)
+ tools.bzl (a file containing one utility method, "register_tools", to support WORKSPACE users)
(additional BUILD.bazel and a WORKSPACE file are included as required by Bazel)
@@ -160,19 +155,6 @@
templates.tool_tool(rctx, tool_name, "BUILD.bazel", {"{target_filename}": target_filename})
-def _workspace_hub_impl(rctx):
- tools = lockfile.load_defs(rctx, rctx.attr.lockfiles)
- templates.workspace(rctx, "BUILD.bazel", rctx.attr.hub_name, {})
- templates.workspace(rctx, "tools.bzl", rctx.attr.hub_name, tools)
-
-_workspace_hub = repository_rule(
- attrs = {
- "hub_name": attr.string(mandatory = True),
- "lockfiles": attr.label_list(mandatory = True, allow_files = True),
- },
- implementation = _workspace_hub_impl,
-)
-
def _tool_repo_impl(rctx):
_download_extract_tool(rctx, rctx.attr.tool_name, json.decode(rctx.attr.binary))
templates.tool(rctx, "tools/BUILD.bazel")
@@ -226,6 +208,9 @@
"{defines}": "\n".join(defines),
})
+ # workspace compat
+ templates.hub(rctx, "tools.bzl", templates.workspace_substitutions(rctx.attr.name, tools))
+
_multitool_hub = repository_rule(
attrs = {
"lockfiles": attr.label_list(mandatory = True, allow_files = True),
@@ -244,7 +229,6 @@
"""
tools = lockfile.load_defs(module_ctx, lockfiles)
-
for tool_name, tool in lockfile.sorted_defs(tools):
for binary in tool["binaries"]:
tool_repo(
@@ -269,9 +253,4 @@
lockfiles: a list of lockfile labels containing multitool lockfiles
"""
- _workspace_hub(
- name = "{name}.workspace".format(name = name),
- hub_name = name,
- lockfiles = lockfiles,
- )
_multitool_hub(name = name, lockfiles = lockfiles)
diff --git a/multitool/private/templates.bzl b/multitool/private/templates.bzl
index 35319cd..6329e59 100644
--- a/multitool/private/templates.bzl
+++ b/multitool/private/templates.bzl
@@ -6,8 +6,6 @@
_TOOL_TEMPLATE = "//multitool/private:tool_repo_template/{filename}.template"
_TOOL_TOOL_TEMPLATE = "//multitool/private:tool_repo_tool_template/{filename}.template"
-_WORKSPACE_TEMPLATE = "//multitool/private:workspace_hub_repo_template/{filename}.template"
-
def _render_tool(rctx, filename, substitutions = None):
rctx.template(
filename,
@@ -68,19 +66,15 @@
for binary in tool["binaries"]
])
-def _render_workspace(rctx, filename, hub_name, tools):
- rctx.template(
- filename,
- Label(_WORKSPACE_TEMPLATE.format(filename = filename)),
- substitutions = {
- "{tool_repos}": _render_tool_repos(hub_name, tools),
- },
- )
+def _workspace_subs(hub_name, tools):
+ return {
+ "{tool_repos}": _render_tool_repos(hub_name, tools),
+ }
templates = struct(
hub = _render_hub,
hub_tool = _render_hub_tool,
tool = _render_tool,
tool_tool = _render_tool_tool,
- workspace = _render_workspace,
+ workspace_substitutions = _workspace_subs,
)
diff --git a/multitool/private/workspace_hub_repo_template/BUILD.bazel.template b/multitool/private/workspace_hub_repo_template/BUILD.bazel.template
deleted file mode 100644
index 14f9e5b..0000000
--- a/multitool/private/workspace_hub_repo_template/BUILD.bazel.template
+++ /dev/null
@@ -1 +0,0 @@
-# generated by multitool