diff mbox series

[bug#57680,1/2] guix: Add compression module.

Message ID 20220908153033.7016-1-othacehe@gnu.org
State Accepted
Headers show
Series image: Add tarball support. | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git-branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Mathieu Othacehe Sept. 8, 2022, 3:30 p.m. UTC
Move the compression record to a dedicated module so that it can be used
outside (guix scripts pack) module.

* guix/scripts/pack.scm (<compressor>, %compressors, lookup-compressor): Move
it to ...
* guix/compression.scm: ... this new file.
* Makefile.am (MODULES): Add it.
---
 Makefile.am           |  1 +
 guix/compression.scm  | 69 +++++++++++++++++++++++++++++++++++++++++++
 guix/scripts/pack.scm | 46 ++---------------------------
 3 files changed, 72 insertions(+), 44 deletions(-)
 create mode 100644 guix/compression.scm

Comments

Ludovic Courtès Sept. 24, 2022, 1:50 p.m. UTC | #1
Mathieu Othacehe <othacehe@gnu.org> skribis:

> Move the compression record to a dedicated module so that it can be used
> outside (guix scripts pack) module.
>
> * guix/scripts/pack.scm (<compressor>, %compressors, lookup-compressor): Move
> it to ...
> * guix/compression.scm: ... this new file.
> * Makefile.am (MODULES): Add it.

I’m pretty sure I commented on this patch as part of another series
recently but I can’t find it anymore.

The guts of it is:

  1. (guix compression) sounds like it could just as well be about
     offering an abstraction over guile-{zlib,zstd,lzlib} like that
     currently in (guix utils).  So the name is misleading.

  2. We cannot refer to (gnu …) from (guix …) or, if we really need to
     do so, then that should happen lazily at run time (do not miss
     Josselin’s excellent guided tour at the Ten Years, which included a
     discussion of this! :-)).

Hope that makes sense!

Ludo’.
Mathieu Othacehe Sept. 25, 2022, 7:50 a.m. UTC | #2
Hey,

> I’m pretty sure I commented on this patch as part of another series
> recently but I can’t find it anymore.

Here it was: https://lists.gnu.org/archive/html/guix-devel/2022-09/msg00094.html

>   1. (guix compression) sounds like it could just as well be about
>      offering an abstraction over guile-{zlib,zstd,lzlib} like that
>      currently in (guix utils).  So the name is misleading.

While I agree, I cannot think of another name. Maybe (gnu compressor) as
this is the name of the defined record?

>   2. We cannot refer to (gnu …) from (guix …) or, if we really need to
>      do so, then that should happen lazily at run time (do not miss
>      Josselin’s excellent guided tour at the Ten Years, which included a
>      discussion of this! :-)).

I moved it to (gnu compression) for now. Yeah, I'm polling the 10years
page to be able to watch this presentation among others ;).

Thanks,

Mathieu
diff mbox series

Patch

diff --git a/Makefile.am b/Makefile.am
index 22dcc43f99..65b2ec4612 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -80,6 +80,7 @@  MODULES =					\
   guix/base32.scm				\
   guix/base64.scm				\
   guix/ci.scm					\
+  guix/compression.scm				\
   guix/cpio.scm					\
   guix/cpu.scm					\
   guix/deprecation.scm				\
diff --git a/guix/compression.scm b/guix/compression.scm
new file mode 100644
index 0000000000..10ec4a7cda
--- /dev/null
+++ b/guix/compression.scm
@@ -0,0 +1,69 @@ 
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2022 Mathieu Othacehe <othacehe@gnu.org>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (guix compression)
+  #:use-module (guix gexp)
+  #:use-module (guix ui)
+  #:use-module ((gnu packages compression) #:hide (zip))
+  #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-9)
+  #:use-module (ice-9 match)
+  #:export (compressor
+            compressor?
+            compressor-name
+            compressor-extension
+            compressor-command
+            %compressors
+            lookup-compressor))
+
+;; Type of a compression tool.
+(define-record-type <compressor>
+  (compressor name extension command)
+  compressor?
+  (name       compressor-name)      ;string (e.g., "gzip")
+  (extension  compressor-extension) ;string (e.g., ".lz")
+  (command    compressor-command))  ;gexp (e.g., #~(list "/gnu/store/…/gzip"
+                                    ;                    "-9n" ))
+
+(define %compressors
+  ;; Available compression tools.
+  (list (compressor "gzip"  ".gz"
+                    #~(list #+(file-append gzip "/bin/gzip") "-9n"))
+        (compressor "lzip"  ".lz"
+                    #~(list #+(file-append lzip "/bin/lzip") "-9"))
+        (compressor "xz"    ".xz"
+                    #~(append (list #+(file-append xz "/bin/xz")
+                                    "-e")
+                              (%xz-parallel-args)))
+        (compressor "bzip2" ".bz2"
+                    #~(list #+(file-append bzip2 "/bin/bzip2") "-9"))
+        (compressor "zstd" ".zst"
+                    ;; The default level 3 compresses better than gzip in a
+                    ;; fraction of the time, while the highest level 19
+                    ;; (de)compresses more slowly and worse than xz.
+                    #~(list #+(file-append zstd "/bin/zstd") "-3"))
+        (compressor "none" "" #f)))
+
+(define (lookup-compressor name)
+  "Return the compressor object called NAME.  Error out if it could not be
+found."
+  (or (find (match-lambda
+              (($ <compressor> name*)
+               (string=? name* name)))
+            %compressors)
+      (leave (G_ "~a: compressor not found~%") name)))
diff --git a/guix/scripts/pack.scm b/guix/scripts/pack.scm
index d3ee69840c..0331ec7b04 100644
--- a/guix/scripts/pack.scm
+++ b/guix/scripts/pack.scm
@@ -27,6 +27,7 @@ 
 (define-module (guix scripts pack)
   #:use-module (guix scripts)
   #:use-module (guix ui)
+  #:use-module (guix compression)
   #:use-module (guix gexp)
   #:use-module ((guix build utils) #:select (%xz-parallel-args))
   #:use-module (guix utils)
@@ -61,13 +62,7 @@  (define-module (guix scripts pack)
   #:use-module (srfi srfi-26)
   #:use-module (srfi srfi-37)
   #:use-module (ice-9 match)
-  #:export (compressor?
-            compressor-name
-            compressor-extension
-            compressor-command
-            %compressors
-            lookup-compressor
-            self-contained-tarball
+  #:export (self-contained-tarball
             debian-archive
             docker-image
             squashfs-image
@@ -75,34 +70,6 @@  (define-module (guix scripts pack)
             %formats
             guix-pack))
 
-;; Type of a compression tool.
-(define-record-type <compressor>
-  (compressor name extension command)
-  compressor?
-  (name       compressor-name)      ;string (e.g., "gzip")
-  (extension  compressor-extension) ;string (e.g., ".lz")
-  (command    compressor-command))  ;gexp (e.g., #~(list "/gnu/store/…/gzip"
-                                    ;                    "-9n" ))
-
-(define %compressors
-  ;; Available compression tools.
-  (list (compressor "gzip"  ".gz"
-                    #~(list #+(file-append gzip "/bin/gzip") "-9n"))
-        (compressor "lzip"  ".lz"
-                    #~(list #+(file-append lzip "/bin/lzip") "-9"))
-        (compressor "xz"    ".xz"
-                    #~(append (list #+(file-append xz "/bin/xz")
-                                    "-e")
-                              (%xz-parallel-args)))
-        (compressor "bzip2" ".bz2"
-                    #~(list #+(file-append bzip2 "/bin/bzip2") "-9"))
-        (compressor "zstd" ".zst"
-                    ;; The default level 3 compresses better than gzip in a
-                    ;; fraction of the time, while the highest level 19
-                    ;; (de)compresses more slowly and worse than xz.
-                    #~(list #+(file-append zstd "/bin/zstd") "-3"))
-        (compressor "none" "" #f)))
-
 ;; This one is only for use in this module, so don't put it in %compressors.
 (define bootstrap-xz
   (compressor "bootstrap-xz" ".xz"
@@ -110,15 +77,6 @@  (define bootstrap-xz
                               "-e")
                         (%xz-parallel-args))))
 
-(define (lookup-compressor name)
-  "Return the compressor object called NAME.  Error out if it could not be
-found."
-  (or (find (match-lambda
-              (($ <compressor> name*)
-               (string=? name* name)))
-            %compressors)
-      (leave (G_ "~a: compressor not found~%") name)))
-
 (define not-config?
   ;; Select (guix …) and (gnu …) modules, except (guix config).
   (match-lambda