Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not download non-local binaries #12

Closed
wants to merge 8 commits into from
Closed
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: 23 additions & 0 deletions multitool/private/multitool.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@ def _check(condition, message):
if not condition:
fail(message)

def _match_os(rctx, os):
# rctx.os.name takes values from Java system property `os.name`
if os == "macos" and rctx.os.name.startswith("mac"):
return True
if os == "linux" and rctx.os.name.lower() == "linux":
return True
return False

def _match_cpu(rctx, cpu):
# rctx.os.arch takes values from Java system property `os.arch`
if cpu == "x86_64" and rctx.os.arch in ["x86_64", "amd64"]:
return True
if cpu == "arm64" and rctx.os.arch == "aarch64":
return True
return False

def _match_local(rctx, os, cpu):
"Returns True iff os and cpu match local environment"
return _match_os(rctx, os) and _match_cpu(rctx, cpu)

def _multitool_hub_impl(rctx):
tools = {}
for lockfile in rctx.attr.lockfiles:
Expand All @@ -43,6 +63,9 @@ def _multitool_hub_impl(rctx):
_check(binary["os"] in ["linux", "macos"], "Unknown os '{os}'".format(os = binary["os"]))
_check(binary["cpu"] in ["x86_64", "arm64"], "Unknown cpu '{cpu}'".format(cpu = binary["cpu"]))

if not _match_local(rctx, binary["os"], binary["cpu"]):
continue

target_executable = "tools/{tool_name}/{os}_{cpu}_executable".format(
tool_name = tool_name,
cpu = binary["cpu"],
Expand Down
Loading