From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id oFchN42XAWA6KQAA0tVLHw (envelope-from ) for ; Fri, 15 Jan 2021 13:24:29 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id KDIEM42XAWDhfgAAbx9fmQ (envelope-from ) for ; Fri, 15 Jan 2021 13:24:29 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 306A19403AA for ; Fri, 15 Jan 2021 13:24:26 +0000 (UTC) Received: from localhost ([::1]:45930 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l0P5U-0008Ie-Vh for larch@yhetil.org; Fri, 15 Jan 2021 08:24:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39372) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l0OyX-0003qD-9t for guix-patches@gnu.org; Fri, 15 Jan 2021 08:17:14 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:56806) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l0OyM-0001mP-1C for guix-patches@gnu.org; Fri, 15 Jan 2021 08:17:06 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l0OyL-000182-Tc for guix-patches@gnu.org; Fri, 15 Jan 2021 08:17:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#45891] [PATCH] packages: 'patch-and-repack' returns a directory when given a directory. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 15 Jan 2021 13:17:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 45891 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 45891@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.16107165654269 (code B ref -1); Fri, 15 Jan 2021 13:17:01 +0000 Received: (at submit) by debbugs.gnu.org; 15 Jan 2021 13:16:05 +0000 Received: from localhost ([127.0.0.1]:40119 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l0OxR-00016l-7I for submit@debbugs.gnu.org; Fri, 15 Jan 2021 08:16:05 -0500 Received: from lists.gnu.org ([209.51.188.17]:57658) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l0OxO-00016B-HN for submit@debbugs.gnu.org; Fri, 15 Jan 2021 08:16:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39146) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l0OxN-0003Gu-FI for guix-patches@gnu.org; Fri, 15 Jan 2021 08:16:02 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]:56790) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l0OxM-0001KD-JT; Fri, 15 Jan 2021 08:16:00 -0500 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=38924 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1l0OxH-0005Ou-1A; Fri, 15 Jan 2021 08:15:57 -0500 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Fri, 15 Jan 2021 14:15:48 +0100 Message-Id: <20210115131548.8792-1-ludo@gnu.org> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -1.86 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: 306A19403AA X-Spam-Score: -1.86 X-Migadu-Scanner: scn1.migadu.com X-TUID: 1jhdfM03T4M9 Previously, 'patch-and-repack' would always create a tar.xz archive as a result, even if the input was a directory (a checkout). This change reduces gratuitous CPU and storage overhead. * guix/packages.scm (patch-and-repack)[tarxz-name]: Remove 'checkout?' case. [build](repack): New procedure, with "tar" invocation formerly at the top level. If SOURCE is a directory, call 'copy-recursively'; otherwise, call 'repack'. Change NAME to ORIGINAL-FILE-NAME when it matches 'checkout?'. --- guix/packages.scm | 65 ++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 29 deletions(-) Hi! This change is a followup to a recent IRC discussion: it makes ‘patch-and-repack’ preserve the “directoriness” of its input. It conflicts with other changes Maxim posted at , though that could be addressed. Thoughts? Ludo’. diff --git a/guix/packages.scm b/guix/packages.scm index 4caaa9cb79..cd2cded9ee 100644 --- a/guix/packages.scm +++ b/guix/packages.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès +;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès ;;; Copyright © 2014, 2015, 2017, 2018 Mark H Weaver ;;; Copyright © 2015 Eric Bavier ;;; Copyright © 2016 Alex Kost @@ -635,11 +635,9 @@ specifies modules in scope when evaluating SNIPPET." (define (tarxz-name file-name) ;; Return a '.tar.xz' file name based on FILE-NAME. - (let ((base (cond ((numeric-extension? file-name) - original-file-name) - ((checkout? file-name) - (string-drop-right file-name 9)) - (else (file-sans-extension file-name))))) + (let ((base (if (numeric-extension? file-name) + original-file-name + (file-sans-extension file-name)))) (string-append base (if (equal? (file-extension base) "tar") ".xz" @@ -689,6 +687,29 @@ specifies modules in scope when evaluating SNIPPET." (lambda (name) (not (member name '("." ".."))))))) + (define (repack directory output) + ;; Write to OUTPUT a compressed tarball containing DIRECTORY. + (unless tar-supports-sort? + (call-with-output-file ".file_list" + (lambda (port) + (for-each (lambda (name) + (format port "~a~%" name)) + (find-files directory + #:directories? #t + #:fail-on-error? #t))))) + + (apply invoke #+(file-append tar "/bin/tar") + "cvfa" output + ;; Avoid non-determinism in the archive. Set the mtime + ;; to 1 as is the case in the store (software like gzip + ;; behaves differently when it stumbles upon mtime = 0). + "--mtime=@1" + "--owner=root:0" "--group=root:0" + (if tar-supports-sort? + `("--sort=name" ,directory) + '("--no-recursion" + "--files-from=.file_list")))) + ;; Encoding/decoding errors shouldn't be silent. (fluid-set! %default-port-conversion-strategy 'error) @@ -742,30 +763,16 @@ specifies modules in scope when evaluating SNIPPET." (chdir "..") - (unless tar-supports-sort? - (call-with-output-file ".file_list" - (lambda (port) - (for-each (lambda (name) - (format port "~a~%" name)) - (find-files directory - #:directories? #t - #:fail-on-error? #t))))) - (apply invoke - (string-append #+tar "/bin/tar") - "cvfa" #$output - ;; Avoid non-determinism in the archive. Set the mtime - ;; to 1 as is the case in the store (software like gzip - ;; behaves differently when it stumbles upon mtime = 0). - "--mtime=@1" - "--owner=root:0" - "--group=root:0" - (if tar-supports-sort? - `("--sort=name" - ,directory) - '("--no-recursion" - "--files-from=.file_list"))))))) + ;; If SOURCE is a directory (such as a checkout), return a + ;; directory. Otherwise create a tarball. + (if (file-is-directory? #+source) + (copy-recursively directory #$output + #:log (%make-void-port "w")) + (repack directory #$output)))))) - (let ((name (tarxz-name original-file-name))) + (let ((name (if (checkout? original-file-name) + original-file-name + (tarxz-name original-file-name)))) (gexp->derivation name build #:graft? #f #:system system -- 2.30.0