Skip to content

Commit 958952c

Browse files
committed
Allow set_runpath to accept multiple RUNPATHs
Also place output files in a subdirectory named after the rule to avoid collisions when multiple set_runpath rules process files with the same basename. CMK-29405 Change-Id: I72d123cbc89def9da8d4b9f69afbfe337f170fa0
1 parent ce64f42 commit 958952c

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

bazel/rules/patchelf.bzl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@
33
def _set_runpath_impl(ctx):
44
"""Patches ELF files with the given RUNPATH."""
55
patchelf = ctx.executable._patchelf
6+
rpath = ":".join(ctx.attr.rpaths)
67
outputs = []
78
for src in ctx.files.srcs:
8-
out = ctx.actions.declare_file(src.basename)
9+
out = ctx.actions.declare_file(ctx.label.name + "/" + src.basename)
910
ctx.actions.run(
1011
outputs = [out],
1112
inputs = [src],
1213
executable = patchelf,
1314
arguments = [
1415
"--set-rpath",
15-
ctx.attr.rpath,
16+
rpath,
1617
"--output",
1718
out.path,
1819
src.path,
1920
],
2021
mnemonic = "SetRunpath",
21-
progress_message = "Patching %s with RUNPATH %s" % (src.basename, ctx.attr.rpath),
22+
progress_message = "Patching %s with RUNPATH %s" % (src.basename, rpath),
2223
)
2324
outputs.append(out)
2425

@@ -27,9 +28,9 @@ def _set_runpath_impl(ctx):
2728
set_runpath = rule(
2829
implementation = _set_runpath_impl,
2930
attrs = {
30-
"rpath": attr.string(
31-
default = "${ORIGIN}",
32-
doc = "RUNPATH to set. Defaults to ${ORIGIN}.",
31+
"rpaths": attr.string_list(
32+
default = ["${ORIGIN}"],
33+
doc = "RUNPATH entries to set, joined with ':'. Defaults to ['${ORIGIN}'].",
3334
),
3435
"srcs": attr.label_list(
3536
allow_files = True,

0 commit comments

Comments
 (0)