From 59445aa3615e9848805ebac278cb5f4f45479cbc Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Mon, 2 Jun 2025 15:02:45 -0700 Subject: [PATCH] Clean up subprocess-running in pack_wheel.py There were a couple issues: - CalledProcessError would never be raised, as we were using a Popen object directly. This led to confusion, especially if one tried to refactor it so we *could* raise CalledProcessError, as we don't expect the command to exit zero. - If the ld command didn't produce a useful path, we got very little feedback; no stderr, no return code, not even the command that was run. Signed-off-by: Tim Burke Change-Id: I153752bdb0c42e5ebdd7f3450d8caed0e5a302fa --- pack_wheel.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/pack_wheel.py b/pack_wheel.py index 98d4823..b8e2273 100644 --- a/pack_wheel.py +++ b/pack_wheel.py @@ -73,24 +73,19 @@ def locate_library(name, missing_ok=False): for d in libpath.split(':'): cmd.extend(['-L', d.rstrip('/')]) cmd.extend(['-o', os.devnull, '-l%s' % name]) - try: - p = subprocess.Popen(cmd, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - universal_newlines=True) - out, _ = p.communicate() - except subprocess.CalledProcessError: - pass - else: - if hasattr(os, 'fsdecode'): - out = os.fsdecode(out) - res = re.search(expr, out) - if res: - return os.path.realpath(res.group(0)) + p = subprocess.run(cmd, capture_output=True, text=True) + # Note that we don't expect the command to exit cleanly; we just want + # to see what got loaded + res = re.search(expr, p.stdout) + if res: + return os.path.realpath(res.group(0)) if missing_ok: return None - raise RuntimeError('Failed to locate %s (checked %s)' % (name, libpath)) + print(f'{" ".join(cmd)!r} failed with status {p.returncode}:') + print(f'\x1b[31m{p.stderr}\x1b[0m', end='') + raise RuntimeError(f'Failed to locate {name}') def build_wheel(src_dir):