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 <tim.burke@gmail.com>
Change-Id: I153752bdb0c42e5ebdd7f3450d8caed0e5a302fa
This commit is contained in:
Tim Burke
2025-06-02 15:02:45 -07:00
parent 37e19268e8
commit 59445aa361

View File

@@ -73,24 +73,19 @@ def locate_library(name, missing_ok=False):
for d in libpath.split(':'): for d in libpath.split(':'):
cmd.extend(['-L', d.rstrip('/')]) cmd.extend(['-L', d.rstrip('/')])
cmd.extend(['-o', os.devnull, '-l%s' % name]) cmd.extend(['-o', os.devnull, '-l%s' % name])
try: p = subprocess.run(cmd, capture_output=True, text=True)
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, # Note that we don't expect the command to exit cleanly; we just want
stderr=subprocess.PIPE, # to see what got loaded
universal_newlines=True) res = re.search(expr, p.stdout)
out, _ = p.communicate() if res:
except subprocess.CalledProcessError: return os.path.realpath(res.group(0))
pass
else:
if hasattr(os, 'fsdecode'):
out = os.fsdecode(out)
res = re.search(expr, out)
if res:
return os.path.realpath(res.group(0))
if missing_ok: if missing_ok:
return None 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): def build_wheel(src_dir):