Skip to content

Commit 479e618

Browse files
committed
cli: Improve error handling of patch_rpath
1 parent d8a0c64 commit 479e618

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

cli/cloe_launch/utility.py

+13-17
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def run_cmd(
3232
return result
3333

3434

35-
def patch_rpath(file: Path, rpath: List[str]):
35+
def patch_rpath(file: Path, rpath: List[str]) -> Optional[subprocess.CompletedProcess]:
3636
"""Set the RPATH of an executable or library.
3737
3838
This will fail silently if the file is not an ELF executable.
@@ -41,26 +41,24 @@ def patch_rpath(file: Path, rpath: List[str]):
4141
assert file.exists()
4242

4343
# Get original RPATH of file, or fail.
44+
cmd = ["patchelf", "--print-rpath", str(file)]
4445
result = subprocess.run(
45-
["patchelf", "--print-rpath", str(file)],
46-
stdout=subprocess.PIPE,
47-
stderr=subprocess.PIPE,
48-
check=False,
46+
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=False
4947
)
50-
if result.stderr.decode().strip() == "not an ELF executable":
51-
# Silently ignore binaries that don't apply.
52-
return
48+
if result.returncode != 0:
49+
if result.stderr.decode().strip() == "not an ELF executable":
50+
# Silently ignore binaries that don't apply.
51+
return None
52+
logging.error(f"Error running: {' '.join(cmd)}")
53+
logging.error(result.stderr)
5354
original = result.stdout.decode().strip()
5455
if original != "":
5556
rpath.append(original)
5657

5758
file_arg = str(file)
5859
rpath_arg = ":".join(rpath)
5960
logging.debug(f"Setting RPATH: {file_arg} -> {rpath_arg}")
60-
subprocess.run(
61-
["patchelf", "--set-rpath", rpath_arg, file_arg],
62-
check=True,
63-
)
61+
return run_cmd(["patchelf", "--set-rpath", rpath_arg, file_arg], must_succeed=False)
6462

6563

6664
def find_binary_files(cwd: Optional[Path] = None) -> List[Path]:
@@ -75,12 +73,10 @@ def find_binary_files(cwd: Optional[Path] = None) -> List[Path]:
7573
)
7674
return [Path(x) for x in result.stdout.decode().splitlines()]
7775

76+
7877
def patch_binary_files_rpath(src: Path, rpath: List[str]):
7978
"""Patch RPATH all binary files found in src directory."""
8079
for file in find_binary_files(src):
8180
file = src / file
82-
try:
83-
logging.info(f"Patching RPATH: {file}")
84-
patch_rpath(file, rpath)
85-
except:
86-
logging.warning(f"Error: cannot set RPATH of {file}")
81+
logging.info(f"Patching RPATH: {file}")
82+
patch_rpath(file, rpath)

0 commit comments

Comments
 (0)