Skip to content

Commit

Permalink
wrapper: add exemplar target files instead of dirs for @@ldpaths@@
Browse files Browse the repository at this point in the history
Instead of forming LD_LIBRARY_PATH from the dirname of shared libs of
our deps, put in the actual shared library path names, instead. Then,
in the wrapper, when building up LD_LIBRARY_PATH, use bash $(dirname)
to get just the directory component from the resolved $(rlocation) of
the shared lib.

If multiple shared lib deps exist in the same runfiles directory,
it'll just take a single one to avoid repetition in LD_LIBRARY_PATH.

Testing:

    bazel test use_toolchain_test
    bazel run tool:wrapped_tool /dev/stdout $PWD/foo.txt
  • Loading branch information
wade-arista committed Sep 20, 2024
1 parent 6b2c91a commit c8117ce
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions tool/wrapper.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _tool_wrapper_impl(ctx):

for path in file_paths:
if path.endswith(".so") or ".so." in path:
dirs[paths.dirname(path)] = True
dirs.setdefault(paths.dirname(path), []).append(path)

exec_dep_files, exec_path = _resolve_dep_paths(ctx, ctx.attr.executable)
transitive_runfiles.append(exec_dep_files)
Expand All @@ -47,7 +47,7 @@ def _tool_wrapper_impl(ctx):
output = ctx.outputs.out,
substitutions = {
"@@run@@": exec_path[0],
"@@ldpaths@@": shell.array_literal(list(dirs)),
"@@ldpaths@@": shell.array_literal([k[0] for k in dirs.values()]),
},
is_executable = True,
)
Expand Down
2 changes: 1 addition & 1 deletion tool/wrapper.sh.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ do
path=$(rlocation "$p")
if [ -n "$path" ]
then
_add "$path"
_add "$(dirname "$path")"
fi
done
_add "$orig"
Expand Down

0 comments on commit c8117ce

Please sign in to comment.