Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions multitool/private/multitool.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ def _extension(os):
return ""

def _download_extract_tool(rctx, tool_name, binary):
reproducible = True

target_filename = "{os}_{cpu}_executable{ext}".format(
cpu = binary["cpu"],
os = binary["os"],
Expand Down Expand Up @@ -116,12 +118,15 @@ def _download_extract_tool(rctx, tool_name, binary):
))
rctx.symlink(archive_file, target_executable)
elif binary["kind"] == "pkg":
# Binaries of kind "pkg" behave differently depending on the presence of pkgutil.
reproducible = False

# Check if pkgutil is on the path, and if not fail silently.
# repository rules execute irrespective of platform/OS, so this
# check is required for `pkg_archive` to not fail on Linux.
pkgutil_cmd = rctx.which("pkgutil")
if not pkgutil_cmd:
return
return reproducible

archive_path = "tools/{tool_name}/{os}_{cpu}_pkg".format(
tool_name = tool_name,
Expand Down Expand Up @@ -155,11 +160,19 @@ def _download_extract_tool(rctx, tool_name, binary):

templates.tool_tool(rctx, tool_name, "BUILD.bazel", {"{target_filename}": target_filename})

return reproducible

def _tool_repo_impl(rctx):
_download_extract_tool(rctx, rctx.attr.tool_name, json.decode(rctx.attr.binary))
reproducible = _download_extract_tool(rctx, rctx.attr.tool_name, json.decode(rctx.attr.binary))
templates.tool(rctx, "tools/BUILD.bazel")
templates.tool(rctx, "BUILD.bazel")

# Bazel <8.3.0 lacks rctx.repo_metadata
if not hasattr(rctx, "repo_metadata"):
return None

return rctx.repo_metadata(reproducible = reproducible)

tool_repo = repository_rule(
attrs = {
"tool_name": attr.string(),
Expand Down Expand Up @@ -211,6 +224,12 @@ def _multitool_hub_impl(rctx):
# workspace compat & list of all tools
templates.hub(rctx, "tools.bzl", templates.tools_substitutions(rctx.attr.name, tools))

# Bazel <8.3.0 lacks rctx.repo_metadata
if not hasattr(rctx, "repo_metadata"):
return None

return rctx.repo_metadata(reproducible = True)

_multitool_hub = repository_rule(
attrs = {
"lockfiles": attr.label_list(mandatory = True, allow_files = True),
Expand Down