Skip to content

Commit d15421d

Browse files
fix(profiling): harden heap-gotter stash before auditwheel repair
Info-ZIP path globs silently failed to remove libdd_heap_gotter from the wheel, so auditwheel still hit iter_versions and skipped S3 upload. Stash/remove/verify with pure Python and fail closed if the cdylib remains.
1 parent 4bbefac commit d15421d

1 file changed

Lines changed: 32 additions & 7 deletions

File tree

.gitlab/scripts/build-wheel-helpers.sh

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,17 +156,42 @@ PY
156156
# parser. --exclude does not help: it only drops a SONAME from dependency
157157
# grafting, while repair still parses every ELF listed in the wheel's RECORD.
158158
# So the cdylib has to leave the wheel entirely and be reinserted after.
159+
# Use pure-Python stash/remove (Info-ZIP path globs are unreliable here).
159160
GOTTER_STASH_DIR="${WORK_DIR}/heap_gotter_stash"
160-
GOTTER_PATTERN='*libdd_heap_gotter*.so'
161-
if unzip -l "${BUILT_WHEEL_FILE}" | grep -q 'libdd_heap_gotter.*\.so$'; then
162-
mkdir -p "${GOTTER_STASH_DIR}"
163-
unzip -q "${BUILT_WHEEL_FILE}" "${GOTTER_PATTERN}" -d "${GOTTER_STASH_DIR}"
164-
uv run --no-project scripts/zip_filter.py "${BUILT_WHEEL_FILE}" "${GOTTER_PATTERN}"
165-
fi
161+
mkdir -p "${GOTTER_STASH_DIR}"
162+
BUILT_WHEEL_FILE="${BUILT_WHEEL_FILE}" GOTTER_STASH_DIR="${GOTTER_STASH_DIR}" \
163+
uv run --no-project python - <<'PY'
164+
import os
165+
import zipfile
166+
from pathlib import Path
167+
168+
import subprocess
169+
import sys
170+
171+
wheel = Path(os.environ["BUILT_WHEEL_FILE"])
172+
stash = Path(os.environ["GOTTER_STASH_DIR"])
173+
marker = "libdd_heap_gotter"
174+
with zipfile.ZipFile(wheel, "r") as zf:
175+
gotter = [n for n in zf.namelist() if marker in Path(n).name and n.endswith(".so")]
176+
for name in gotter:
177+
dest = stash / name
178+
dest.parent.mkdir(parents=True, exist_ok=True)
179+
dest.write_bytes(zf.read(name))
180+
print(f"Stashed heap-gotter cdylib: {name}")
181+
if gotter:
182+
# Remove via zip_filter so RECORD stays consistent.
183+
patterns = [f"*{marker}*.so", f"*/{marker}*.so"]
184+
subprocess.check_call([sys.executable, "scripts/zip_filter.py", str(wheel), *patterns])
185+
with zipfile.ZipFile(wheel, "r") as zf:
186+
leftover = [n for n in zf.namelist() if marker in Path(n).name and n.endswith(".so")]
187+
if leftover:
188+
raise SystemExit(f"heap-gotter still in wheel before auditwheel: {leftover}")
189+
print(f"heap-gotter stash count before auditwheel: {len(gotter)}")
190+
PY
166191

167192
auditwheel repair -w "${TMP_WHEEL_DIR}" "${BUILT_WHEEL_FILE}"
168193

169-
if [[ -d "${GOTTER_STASH_DIR}" ]]; then
194+
if find "${GOTTER_STASH_DIR}" -name 'libdd_heap_gotter*.so' 2>/dev/null | grep -q .; then
170195
REPAIRED_WHEEL_FILE=$(ls "${TMP_WHEEL_DIR}"/*.whl | head -n 1)
171196
GOTTER_STASH_DIR="${GOTTER_STASH_DIR}" REPAIRED_WHEEL_FILE="${REPAIRED_WHEEL_FILE}" \
172197
uv run --no-project python - <<'PY'

0 commit comments

Comments
 (0)