From patchwork Thu Jan 4 16:48:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxim Cournoyer X-Patchwork-Id: 58357 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id BF40627BBEA; Thu, 4 Jan 2024 16:51:44 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, SPF_HELO_PASS autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id B35A927BBE2 for ; Thu, 4 Jan 2024 16:51:43 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rLQvv-0003TH-2P; Thu, 04 Jan 2024 11:51:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rLQvs-0003Sa-AY for guix-patches@gnu.org; Thu, 04 Jan 2024 11:51:00 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rLQvs-0001DK-2h for guix-patches@gnu.org; Thu, 04 Jan 2024 11:51:00 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rLQvv-0005Wk-QU for guix-patches@gnu.org; Thu, 04 Jan 2024 11:51:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#68242] [PATCH 4/5] build: gnu-build-system: Compress man pages with zstd. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 04 Jan 2024 16:51:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68242 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 68242@debbugs.gnu.org Cc: Maxim Cournoyer Received: via spool by 68242-submit@debbugs.gnu.org id=B68242.170438700921148 (code B ref 68242); Thu, 04 Jan 2024 16:51:03 +0000 Received: (at 68242) by debbugs.gnu.org; 4 Jan 2024 16:50:09 +0000 Received: from localhost ([127.0.0.1]:55554 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rLQv2-0005Uz-5t for submit@debbugs.gnu.org; Thu, 04 Jan 2024 11:50:08 -0500 Received: from mail-qv1-xf2d.google.com ([2607:f8b0:4864:20::f2d]:43158) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rLQuy-0005Tg-A6 for 68242@debbugs.gnu.org; Thu, 04 Jan 2024 11:50:04 -0500 Received: by mail-qv1-xf2d.google.com with SMTP id 6a1803df08f44-67f85fe5632so12649646d6.0 for <68242@debbugs.gnu.org>; Thu, 04 Jan 2024 08:50:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704386994; x=1704991794; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=asy7LyZfXPjVW081p0UTEaaCiZmbqSgwvwsjh3Rbp80=; b=Y+sBp/TerG3fCMxebOXIVdPWlIV8fDu43ohG+3h2qbfkOsn8Uk3iFZSbwkEpQqQLAA QT2P7qHfFDwf014+dmbqh+iI6G2upU1co/sZ+wDwvmf0zTYJQY4sYhwkZatGuq5QtvpD eMVy8tPf4FGZD1sGvE24LR6X8fww6R1jQJijm7+11/Iv/e8wAjyFPbufK9VXQPyoVV6a H3zNVX4pcgJtnWA8nY2iIPBxKu8dyeFliP+J8qw3KlXOetBa42WCdPMCgjjCX5sEffwy zQGxkRnKU94ORBvar+S3rEc4fGopNKHvo6XXbFS6TGx+wcc+53SYpItGYk3wHpETyald Ol3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704386994; x=1704991794; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=asy7LyZfXPjVW081p0UTEaaCiZmbqSgwvwsjh3Rbp80=; b=wf/atM5QwDKT2Xk3oRuIvGWpqFzWuFakEaluyy6jdeRhjr0f64CarCAi+jOeuWMSAb 0WBiIWhCfRqG/ian+dn7ybk1zmeQIIdJIOHAdnnmlwIJTbEy40UK0GlRvqvWBJOsdVH6 4QN4NThVMt/Q79rL3x3cFmqWEH3KSUidPwB/3jCbNCc3ehO32GmMfFBgJoBd/vrV0pK/ SaufJydf2SxzYSn3ni/qDic2kZL60VvJhdK4vlzw5uYao6MmHt0USGgPcxT2ZdbbhNCF OCUwfLnpITk1mVU8TCUPZQji5KNji342G7sP+DPFEx39Fv5G5JtDeqTusJsnsQf3qSnr 0kkw== X-Gm-Message-State: AOJu0YxlkiJgULZLp/e+LjxEtDUulbZQM7KWFQ+NnaduF6kSGRC0CvvC MwUYwjUJ5p1+96OWfnXPTbnBHkcCIEeswg== X-Google-Smtp-Source: AGHT+IF+HUbPTlS0d5rHRrCinyQwTwCatMn5AhGtH8zDkpJ/Rn27+EOIfh5Yjxm7oI1po0jExd+Rqw== X-Received: by 2002:a05:6214:21a2:b0:67f:67ca:1181 with SMTP id t2-20020a05621421a200b0067f67ca1181mr1008571qvc.40.1704386994578; Thu, 04 Jan 2024 08:49:54 -0800 (PST) Received: from localhost.localdomain (dsl-10-135-125.b2b2c.ca. [72.10.135.125]) by smtp.gmail.com with ESMTPSA id o2-20020a0cecc2000000b0067aab230ed9sm11854706qvq.21.2024.01.04.08.49.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 08:49:54 -0800 (PST) From: Maxim Cournoyer Date: Thu, 4 Jan 2024 11:48:20 -0500 Message-ID: <6425d5767b4ca53ed6de612c0f77e3d6a872af51.1704386901.git.maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches The aim is to improve the efficiency of computing the man pages database, which must decompress the man pages. Zstd is faster than gzip, especially for decompression, and has a similar compression ratio. * gnu/packages/commencement.scm (%final-inputs): Add zstd. * guix/build/gnu-build-system.scm (compress-documentation) Update doc. : New arguments. : Rename argument to... : ... this. Add an 'extension' argument to the retarget-symlink nested procedure. Use new arguments in nested 'maybe-compress' procedure. Change-Id: Ibaad4658f8e5151633714d263d9198f56d255020 --- gnu/packages/commencement.scm | 3 +- guix/build/gnu-build-system.scm | 73 +++++++++++++++++++++------------ 2 files changed, 49 insertions(+), 27 deletions(-) diff --git a/gnu/packages/commencement.scm b/gnu/packages/commencement.scm index ae1c91f0d0..51c26339ef 100644 --- a/gnu/packages/commencement.scm +++ b/gnu/packages/commencement.scm @@ -3492,7 +3492,8 @@ (define-public %final-inputs (native-inputs (list (if (target-hurd?) glibc-utf8-locales-final/hurd - glibc-utf8-locales-final))))))) + glibc-utf8-locales-final))))) + ("zstd" ,zstd))) ("sed" ,sed-final) ("grep" ,grep-final) ("xz" ,xz-final) diff --git a/guix/build/gnu-build-system.scm b/guix/build/gnu-build-system.scm index 51b8f9acbf..ff9b123ae6 100644 --- a/guix/build/gnu-build-system.scm +++ b/guix/build/gnu-build-system.scm @@ -2,7 +2,7 @@ ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès ;;; Copyright © 2018 Mark H Weaver ;;; Copyright © 2020 Brendan Tildesley -;;; Copyright © 2021 Maxim Cournoyer +;;; Copyright © 2021, 2022 Maxim Cournoyer ;;; ;;; This file is part of GNU Guix. ;;; @@ -644,21 +644,36 @@ (define* (reset-gzip-timestamps #:key outputs #:allow-other-keys) (((names . directories) ...) (for-each process-directory directories)))) -(define* (compress-documentation #:key outputs +(define* (compress-documentation #:key + outputs (compress-documentation? #t) - (documentation-compressor "gzip") - (documentation-compressor-flags + (info-compressor "gzip") + (info-compressor-flags '("--best" "--no-name")) - (compressed-documentation-extension ".gz") + (info-compressor-file-extension ".gz") + (man-compressor (if (which "zstd") + "zstd" + info-compressor)) + (man-compressor-flags + (if (which "zstd") + (list "-19" "--rm" + "--threads" (string->number + (parallel-job-count))) + info-compressor-flags)) + (man-compressor-file-extension + (if (which "zstd") + ".zst" + info-compressor-file-extension)) #:allow-other-keys) - "When COMPRESS-DOCUMENTATION? is true, compress man pages and Info files -found in OUTPUTS using DOCUMENTATION-COMPRESSOR, called with -DOCUMENTATION-COMPRESSOR-FLAGS." - (define (retarget-symlink link) + "When COMPRESS-INFO-MANUALS? is true, compress Info files found in OUTPUTS +using INFO-COMPRESSOR, called with INFO-COMPRESSOR-FLAGS. Similarly, when +COMPRESS-MAN-PAGES? is true, compress man pages files found in OUTPUTS using +MAN-COMPRESSOR, using MAN-COMPRESSOR-FLAGS." + (define (retarget-symlink link extension) (let ((target (readlink link))) (delete-file link) - (symlink (string-append target compressed-documentation-extension) - (string-append link compressed-documentation-extension)))) + (symlink (string-append target extension) + (string-append link extension)))) (define (has-links? file) ;; Return #t if FILE has hard links. @@ -676,23 +691,23 @@ (define* (compress-documentation #:key outputs (symbolic-link? target-absolute)) (lambda args (if (= ENOENT (system-error-errno args)) - (begin - (format (current-error-port) - "The symbolic link '~a' target is missing: '~a'\n" - symlink target-absolute) - #f) + (format (current-error-port) + "The symbolic link '~a' target is missing: '~a'\n" + symlink target-absolute) (apply throw args)))))) - (define (maybe-compress-directory directory regexp) + (define (maybe-compress-directory directory regexp + compressor + compressor-flags + compressor-extension) (when (directory-exists? directory) (match (find-files directory regexp) - (() ;nothing to compress + (() ;nothing to compress #t) - ((files ...) ;one or more files + ((files ...) ;one or more files (format #t "compressing documentation in '~a' with ~s and flags ~s~%" - directory documentation-compressor - documentation-compressor-flags) + directory compressor compressor-flags) (call-with-values (lambda () (partition symbolic-link? files)) @@ -702,20 +717,26 @@ (define* (compress-documentation #:key outputs ;; unchanged ('gzip' would refuse to compress them anyway.) ;; Also, do not retarget symbolic links pointing to other ;; symbolic links, since these are not compressed. - (for-each retarget-symlink + (for-each (cut retarget-symlink <> compressor-extension) (filter (lambda (symlink) (and (not (points-to-symlink? symlink)) (string-match regexp symlink))) symlinks)) - (apply invoke documentation-compressor - (append documentation-compressor-flags + (apply invoke compressor + (append compressor-flags (remove has-links? regular-files))))))))) (define (maybe-compress output) (maybe-compress-directory (string-append output "/share/man") - "\\.[0-9]+$") + "\\.[0-9]+$" + man-compressor + man-compressor-flags + man-compressor-file-extension) (maybe-compress-directory (string-append output "/share/info") - "\\.info(-[0-9]+)?$")) + "\\.info(-[0-9]+)?$" + info-compressor + info-compressor-flags + info-compressor-file-extension)) (if compress-documentation? (match outputs