Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions changelog.d/+rpath-empty-path-entry.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`eb-local` RPATH wrappers now search an empty `PATH` entry as the current directory, including a trailing colon, as `execvp` does.
18 changes: 15 additions & 3 deletions src/rpath.zig
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ pub const self_linking = [_][]const u8{ "clang", "clang++", "flang", "flang-new"
pub const marker = ".eb-local-rpath";

/// One script for every name: it runs the next command of its own name on
/// PATH. When that command links, it adds a run path for each absolute
/// PATH. An empty entry is the current directory, including the one a
/// trailing colon names, as execvp searches. When that command links, it
/// adds a run path for each absolute
/// library directory named with -L, and for a compiler driver for each
/// LIBRARY_PATH entry, which EESSI's modules set and the driver passes to
/// the linker; system and compatibility-layer directories are left out, as
Expand All @@ -41,9 +43,19 @@ pub const script =
\\# RPATH wrapper written by eb-local; see `eb-local help`.
\\name=${0##*/}
\\real=
\\IFS=: read -r -a path_dirs <<< "$PATH"
\\# read drops a trailing colon, so an empty entry would disappear. Split
\\# on colons and keep every one. An empty entry is the current directory.
\\# An unset PATH is the default command search path, not the current directory.
\\path_dirs=()
\\if [ -n "${PATH+x}" ]; then _eb_path_rest="${PATH}:"; else _eb_path_rest="/bin:/usr/bin:"; fi
\\while [ -n "$_eb_path_rest" ]; do
\\ path_dirs+=("${_eb_path_rest%%:*}")
\\ _eb_path_rest="${_eb_path_rest#*:}"
\\done
\\unset _eb_path_rest
\\for d in "${path_dirs[@]}"; do
\\ if [ -n "$d" ] && [ ! -e "$d/.eb-local-rpath" ] && [ -f "$d/$name" ] && [ -x "$d/$name" ]; then
\\ [ -n "$d" ] || d=.
\\ if [ ! -e "$d/.eb-local-rpath" ] && [ -f "$d/$name" ] && [ -x "$d/$name" ]; then
\\ real=$d/$name
\\ break
\\ fi
Expand Down
32 changes: 32 additions & 0 deletions tests/test_rpath_wrappers_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,38 @@ def test_hostile_wrapper_destinations_exit_two(self):
self.assertTrue(link.is_symlink())
self.assertFalse(outside.exists())

def _run_wrapper(self, setup_stdout, path, cwd):
script = setup_stdout + "gcc -c foo.c\n"
return subprocess.run(
["/bin/bash", "--noprofile", "--norc", "-c", script],
env={"PATH": path, "LC_ALL": "C.UTF-8", "LANG": "C.UTF-8"},
cwd=cwd,
capture_output=True,
text=True,
)

def test_an_empty_path_entry_is_the_current_directory(self):
got = self.run_cmd(["--for", "gcc"])
self.assertEqual(got.returncode, 0, got.stderr)
cwd_gcc = self.root / "gcc"
cwd_gcc.write_text("#!/bin/sh\nprintf 'from-cwd\\n'\n", encoding="utf-8")
cwd_gcc.chmod(0o755)

# A trailing colon is an empty entry after every other directory.
trailing = self._run_wrapper(got.stdout, "", self.root)
self.assertEqual(trailing.returncode, 0, trailing.stdout + trailing.stderr)
self.assertEqual(trailing.stdout, "from-cwd\n")
self.assertEqual(trailing.stderr, "")

# An empty entry in the middle is the current directory, and it wins
# over a later directory that also has gcc.
self.log.write_text("", encoding="utf-8")
middle = self._run_wrapper(got.stdout, f":{self.bin}", self.root)
self.assertEqual(middle.returncode, 0, middle.stdout + middle.stderr)
self.assertEqual(middle.stdout, "from-cwd\n")
self.assertEqual(middle.stderr, "")
self.assertEqual(self.log.read_text(encoding="utf-8"), "")

def test_tmpfs_enospc_exits_two_and_cleans_wrapper_tree(self):
mnt = hostile_fs.enter_full_tmpfs(self)
if mnt is None:
Expand Down
Loading