Skip to content

Commit fe23a4f

Browse files
authored
Refactor run_tool (#4459)
Removes the python script, should get equivalent results in the current setup.
1 parent 957599b commit fe23a4f

File tree

2 files changed

+29
-33
lines changed

2 files changed

+29
-33
lines changed

toolchain/install/run_tool.bzl

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,33 @@
44

55
"""Supports running a tool from the install filegroup."""
66

7-
load("@rules_python//python:defs.bzl", "py_binary")
8-
9-
def run_tool(name, tool, data, env):
10-
# TODO: Fix the driver file discovery in order to allow symlinks.
11-
py_binary(
12-
name = name,
13-
main = "run_tool.py",
14-
srcs = ["run_tool.py"],
15-
args = ["$(location {})".format(tool)],
16-
data = [tool] + data,
17-
env = env,
7+
def _run_tool_impl(ctx):
8+
tool_files = ctx.attr.tool.files.to_list()
9+
if len(tool_files) != 1:
10+
fail("Expected 1 tool file, found {0}".format(len(tool_files)))
11+
ctx.actions.symlink(
12+
output = ctx.outputs.executable,
13+
target_file = tool_files[0],
14+
is_executable = True,
1815
)
16+
return [
17+
DefaultInfo(
18+
runfiles = ctx.runfiles(files = ctx.files.data),
19+
),
20+
RunEnvironmentInfo(environment = ctx.attr.env),
21+
]
22+
23+
run_tool = rule(
24+
doc = "Helper for running a tool in a filegroup.",
25+
implementation = _run_tool_impl,
26+
attrs = {
27+
"data": attr.label_list(allow_files = True),
28+
"env": attr.string_dict(),
29+
"tool": attr.label(
30+
allow_single_file = True,
31+
executable = True,
32+
cfg = "target",
33+
),
34+
},
35+
executable = True,
36+
)

toolchain/install/run_tool.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)