libmakepkg: strip - parallelize stripping of files

Perform file stripping in parallel where possible. Hardlinks remain
processed one at a time due to reproducibility issues.

Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Vasiliy Stelmachenok 2024-12-24 20:04:34 +10:00 committed by Allan McRae
parent dbde37aafb
commit 02b35b9155
2 changed files with 24 additions and 3 deletions

View file

@ -190,9 +190,27 @@ tidy_strip() {
mkdir -p "$dbgdir" "$dbgsrc"
fi
while IFS= read -rd '' binary ; do
process_file_stripping "$binary"
done < <(find . -type f -perm -u+w -links 1 -print0 2>/dev/null)
_parallel_stripper() {
# Inherit traps in subshell to perform cleanup after an interrupt
set -E
(
local jobs binary
while IFS= read -rd '' binary ; do
# Be sure to keep the number of concurrently running processes less
# than limit value to prevent an accidental fork bomb.
jobs=($(jobs -p))
(( ${#jobs[@]} >= $NPROC )) && wait -n "${jobs[@]}"
process_file_stripping "$binary" &
done < <(find . -type f -perm -u+w -links 1 -print0 2>/dev/null)
# Wait for all jobs to complete
wait
)
set +E
}
_parallel_stripper
# hardlinks only need processed once, but need additional links in debug packages
declare -A hardlinks

View file

@ -106,6 +106,9 @@ trap_exit() {
fi
[[ -n $srclinks ]] && rm -rf "$srclinks"
# Kill all child processes so that they are not left orphaned upon exit.
[[ -n "$(jobs -p)" ]] && kill "$(jobs -p)" 2>/dev/null
# unset the trap for this signal, and then call the default handler
trap -- "$signal"
kill "-$signal" "$$"