Skip to content

Commit 8c227cf

Browse files
committed
fix(bundle): use process substitution to fix silent pipefail in bundle_all_deps
With 'set -euo pipefail', ldd|grep|awk|while fails silently when grep finds no '=> /' lines (libs with only linux-vdso/ld-linux deps). The pipeline's while loop also runs in a subshell, so queue+= updates were lost and the QUEUE_FILE workaround was needed. Switch to process substitution (< <(... || true)): - '|| true' suppresses grep exit-1 on zero matches - while body runs in the current shell so queue+= propagates directly - QUEUE_FILE and its trap are no longer needed Also add explicit error messages to patchelf calls so failures are visible in CI logs instead of being swallowed by set -e. Made-with: Cursor
1 parent 5b711b7 commit 8c227cf

1 file changed

Lines changed: 14 additions & 16 deletions

File tree

scripts/bundle-libmpv-linux.sh

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,18 @@ SYSTEM_LIBS_RE+="|libdbus|libsystemd|libfontconfig|libfreetype"
7373
# bundle_all_deps: recursively resolve and copy dependencies to a fixpoint.
7474
# Uses the bundle dir itself as the visited set — if a .so already exists
7575
# there, it's been processed and won't be traversed again.
76+
#
77+
# Uses process substitution (< <(...)) instead of a pipeline so that:
78+
# 1. The while loop body runs in the current shell — queue+= propagates.
79+
# 2. "|| true" after the process substitution suppresses grep exit-1 when a
80+
# lib has no "=> /" lines (e.g. only linux-vdso / ld-linux deps), which
81+
# would otherwise trigger set -euo pipefail and kill the script silently.
7682
bundle_all_deps() {
7783
local queue=("$@")
7884
while [[ ${#queue[@]} -gt 0 ]]; do
7985
local lib="${queue[0]}"
8086
queue=("${queue[@]:1}")
81-
ldd "$lib" 2>/dev/null | grep "=> /" | awk '{print $3}' | while read -r dep; do
87+
while IFS= read -r dep; do
8288
local basename_dep
8389
basename_dep=$(basename "$dep")
8490
if echo "$basename_dep" | grep -qE "$SYSTEM_LIBS_RE"; then
@@ -87,29 +93,21 @@ bundle_all_deps() {
8793
if [[ ! -f "$BUNDLE_DIR/$basename_dep" ]]; then
8894
cp "$dep" "$BUNDLE_DIR/"
8995
echo " bundled: $basename_dep"
90-
# Append to queue file so the outer loop picks it up
91-
echo "$BUNDLE_DIR/$basename_dep" >> "$QUEUE_FILE"
96+
queue+=("$BUNDLE_DIR/$basename_dep")
9297
fi
93-
done
94-
# Read any newly discovered libs back into the queue
95-
if [[ -f "$QUEUE_FILE" ]]; then
96-
while IFS= read -r newlib; do
97-
queue+=("$newlib")
98-
done < "$QUEUE_FILE"
99-
rm -f "$QUEUE_FILE"
100-
fi
98+
done < <(ldd "$lib" 2>/dev/null | grep "=> /" | awk '{print $3}' || true)
10199
done
102100
}
103101

104-
QUEUE_FILE=$(mktemp)
105-
trap 'rm -f "$QUEUE_FILE"' EXIT
106-
107102
# Bundle libmpv and all transitive dependencies
108103
bundle_all_deps "$LIBMPV_PATH"
109104

110105
# Set RPATH so the binary and all bundled libs find co-located libs
111-
patchelf --set-rpath '$ORIGIN' "$BINARY"
112-
patchelf --set-rpath '$ORIGIN' "$BUNDLE_DIR/libmpv.so"
106+
echo " Setting RPATH on binary..."
107+
patchelf --set-rpath '$ORIGIN' "$BINARY" \
108+
|| { echo "Error: patchelf --set-rpath failed on $BINARY"; exit 1; }
109+
patchelf --set-rpath '$ORIGIN' "$BUNDLE_DIR/libmpv.so" \
110+
|| { echo "Error: patchelf --set-rpath failed on $BUNDLE_DIR/libmpv.so"; exit 1; }
113111

114112
# Also set RPATH on all bundled .so files so they can find each other
115113
for so in "$BUNDLE_DIR"/*.so*; do

0 commit comments

Comments
 (0)