MCPcopy
hub / github.com/pyinstaller/pyinstaller / process_collected_binary

Function process_collected_binary

PyInstaller/building/utils.py:107–353  ·  view source on GitHub ↗

Process the collected binary using strip or UPX (or both), and apply any platform-specific processing. On macOS, this rewrites the library paths in the headers, and (re-)signs the binary. On-disk cache is used to avoid processing the same binary with same options over and over. In

(
    src_name,
    dest_name,
    use_strip=False,
    use_upx=False,
    upx_exclude=None,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
    strict_arch_validation=False
)

Source from the content-addressed store, hash-verified

105
106
107def process_collected_binary(
108 src_name,
109 dest_name,
110 use_strip=False,
111 use_upx=False,
112 upx_exclude=None,
113 target_arch=None,
114 codesign_identity=None,
115 entitlements_file=None,
116 strict_arch_validation=False
117):
118 """
119 Process the collected binary using strip or UPX (or both), and apply any platform-specific processing. On macOS,
120 this rewrites the library paths in the headers, and (re-)signs the binary. On-disk cache is used to avoid processing
121 the same binary with same options over and over.
122
123 In addition to given arguments, this function also uses CONF['cachedir'] and CONF['upx_dir'].
124 """
125 from PyInstaller.config import CONF
126
127 # We need to use cache in the following scenarios:
128 # * extra binary processing due to use of `strip` or `upx`
129 # * building on macOS, where we need to rewrite library paths in binaries' headers and (re-)sign the binaries.
130 if not use_strip and not use_upx and not is_darwin:
131 return src_name
132
133 # Match against provided UPX exclude patterns.
134 upx_exclude = upx_exclude or []
135 if use_upx:
136 src_path = pathlib.PurePath(src_name)
137 for upx_exclude_entry in upx_exclude:
138 # pathlib.PurePath.match() matches from right to left, and supports * wildcard, but does not support the
139 # "**" syntax for directory recursion. Case sensitivity follows the OS default.
140 if src_path.match(upx_exclude_entry):
141 logger.info("Disabling UPX for %s due to match in exclude pattern: %s", src_name, upx_exclude_entry)
142 use_upx = False
143 break
144
145 # Additional automatic disablement rules for UPX and strip.
146
147 # On Windows, avoid using UPX with binaries that have control flow guard (CFG) enabled.
148 if use_upx and is_win and versioninfo.pefile_check_control_flow_guard(src_name):
149 logger.info('Disabling UPX for %s due to CFG!', src_name)
150 use_upx = False
151
152 # Avoid using UPX with Qt plugins, as it strips the data required by the Qt plugin loader.
153 if use_upx and misc.is_file_qt_plugin(src_name):
154 logger.info('Disabling UPX for %s due to it being a Qt plugin!', src_name)
155 use_upx = False
156
157 # On linux, if a binary has an accompanying HMAC or CHK file, avoid modifying it in any way.
158 if (use_upx or use_strip) and is_linux:
159 src_path = pathlib.Path(src_name)
160 hmac_path = src_path.with_name(f".{src_path.name}.hmac")
161 chk_path = src_path.with_suffix(".chk")
162 if hmac_path.is_file():
163 logger.info('Disabling UPX and/or strip for %s due to accompanying .hmac file!', src_name)
164 use_upx = use_strip = False

Callers 3

assembleMethod · 0.90
assembleMethod · 0.90
assembleMethod · 0.90

Calls 7

_compute_file_digestFunction · 0.85
matchMethod · 0.80
infoMethod · 0.80
readMethod · 0.80
chmodMethod · 0.80
runMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…