From 8d022c6c7c575843dec6b9e2c8383ddcb2d23823 Mon Sep 17 00:00:00 2001 From: DavHau Date: Wed, 14 May 2025 09:51:58 +0700 Subject: [PATCH] compress-man-pages: optimize, use multiple cores Decreases the time spent on gzipping man pages. Decreases the number of processes launched per file from 2 to 1. Launches multiple processes in parallel via xargs -P. The behavior of the hook is unchanged. gzip -f is now needed to retain the behavior of compressing hardlinkgs. Previously '-f' was not needed because gzip compressed to stdout. It removes the check checking if gzip failed, because there os no reason it should ever fail. Even if it fails we probably want to fix the issue instead of silently not gzipping. This check has been introduced via c06046e5ef1b2f0a5b0fe243b72a257eaa9033ad. No comment was given on why it would be necessary. --- pkgs/build-support/setup-hooks/compress-man-pages.sh | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/pkgs/build-support/setup-hooks/compress-man-pages.sh b/pkgs/build-support/setup-hooks/compress-man-pages.sh index 0d8a76558026..26059b7d9401 100644 --- a/pkgs/build-support/setup-hooks/compress-man-pages.sh +++ b/pkgs/build-support/setup-hooks/compress-man-pages.sh @@ -9,15 +9,9 @@ compressManPages() { echo "gzipping man pages under $dir/share/man/" # Compress all uncompressed manpages. Don't follow symlinks, etc. + # gzip -f is needed to not error out on hard links. find "$dir"/share/man/ -type f -a '!' -regex '.*\.\(bz2\|gz\|xz\)$' -print0 \ - | while IFS= read -r -d $'\0' f - do - if gzip -c -n "$f" > "$f".gz; then - rm "$f" - else - rm "$f".gz - fi - done + | xargs -0 -n1 -P "$NIX_BUILD_CORES" gzip -f # Point symlinks to compressed manpages. find "$dir"/share/man/ -type l -a '!' -regex '.*\.\(bz2\|gz\|xz\)$' -print0 \