Skip to content

Commit

Permalink
building: process_collected_binary: warn on strip/upx failures
Browse files Browse the repository at this point in the history
If calling `strip` or `upx` in `process_collected_binary` fails
for whatever reason, display a warning and captured stdout/stderr.
The failure is still considered non-fatal (warning instead of an
error), but it should be visible to the user.
  • Loading branch information
rokm committed Feb 7, 2024
1 parent 8904600 commit 08e2ee5
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions PyInstaller/building/utils.py
Expand Up @@ -237,7 +237,22 @@ def process_collected_binary(

cmd = ["strip", *strip_options, cached_name]
logger.info("Executing: %s", " ".join(cmd))
subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
try:
p = subprocess.run(
cmd,
stdin=subprocess.DEVNULL,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
check=True,
errors='ignore',
encoding='utf-8',
)
logger.debug("Output from strip command:\n%s", p.stdout)
except subprocess.CalledProcessError as e:
logger.warning("Failed to run strip on %r!", cached_name, exc_info=True)
logger.warning("Output from strip command:\n%s", e.stdout)
except Exception:
logger.warning("Failed to run strip on %r!", cached_name, exc_info=True)

# Apply UPX
if use_upx:
Expand All @@ -260,7 +275,22 @@ def process_collected_binary(

cmd = [upx_exe, *upx_options, cached_name]
logger.info("Executing: %s", " ".join(cmd))
subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
try:
p = subprocess.run(
cmd,
stdin=subprocess.DEVNULL,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
check=True,
errors='ignore',
encoding='utf-8',
)
logger.debug("Output from upx command:\n%s", p.stdout)
except subprocess.CalledProcessError as e:
logger.warning("Failed to upx strip on %r!", cached_name, exc_info=True)
logger.warning("Output from upx command:\n%s", e.stdout)
except Exception:
logger.warning("Failed to run upx on %r!", cached_name, exc_info=True)

# On macOS, we need to modify the given binary's paths to the dependent libraries, in order to ensure they are
# relocatable and always refer to location within the frozen application. Specifically, we make all dependent
Expand Down

0 comments on commit 08e2ee5

Please sign in to comment.