import: Enable recursive import for texlive packages.
authorRicardo Wurmus <rekado@elephly.net>
Tue, 19 Jul 2022 21:44:11 +0000 (23:44 +0200)
committerRicardo Wurmus <rekado@elephly.net>
Tue, 19 Jul 2022 21:49:42 +0000 (23:49 +0200)
* guix/import/texlive.scm (tlpdb->package): Add VERSION argument; include
explicit version field in output.
(texlive->guix-package): Set default value for VERSION argument; adjust call
of tlpdb->package.
(texlive-recursive-import): Accept REPO and VERSION keyword arguments.
* guix/import/utils.scm (package->definition): Add a clause to deal with
output from tlpdb->package.
* guix/scripts/import/texlive.scm (%options): Add "recursive" option.
(guix-import-texlive): Honor "recursive" option.
* doc/guix.texi (Using TeX and LaTeX): Mention "recursive" option.

doc/guix.texi
guix/import/texlive.scm
guix/import/utils.scm
guix/scripts/import/texlive.scm

index d8a3d2e..3c5864e 100644 (file)
@@ -40965,6 +40965,16 @@ package, you can try and import it (@pxref{Invoking guix import}):
 guix import texlive @var{package}
 @end example
 
+Additional options include:
+
+@table @code
+@item --recursive
+@itemx -r
+Traverse the dependency graph of the given upstream package recursively
+and generate package expressions for all those packages that are not yet
+in Guix.
+@end table
+
 @quotation Note
 @TeX{} Live packaging is still very much work in progress, but you can
 help!  @xref{Contributing}, for more information.
index c741555..116bd1f 100644 (file)
@@ -246,7 +246,7 @@ of those files are returned that are unexpectedly installed."
                           ;; entries with the same prefix.
                           (lambda (x y) (every equal? x y)))))
 
-(define (tlpdb->package name package-database)
+(define (tlpdb->package name version package-database)
   (and-let* ((data (assoc-ref package-database name))
              (dirs (files->directories
                     (map (lambda (dir)
@@ -255,7 +255,9 @@ of those files are returned that are unexpectedly installed."
                                  (or (assoc-ref data 'runfiles) (list))
                                  (or (assoc-ref data 'srcfiles) (list))))))
              (name (guix-name name))
-             (version (number->string %texlive-revision))
+             ;; TODO: we're ignoring the VERSION argument because that
+             ;; information is distributed across %texlive-tag and
+             ;; %texlive-revision.
              (ref (svn-multi-reference
                    (url (string-append "svn://www.tug.org/texlive/tags/"
                                        %texlive-tag "/Master/texmf-dist"))
@@ -276,6 +278,9 @@ of those files are returned that are unexpectedly installed."
                        (force-output port)
                        (get-hash))))
                   ,@(if (assoc-ref data 'srcfiles) '() '(#:trivial? #true))))
+        ;; package->definition in (guix import utils) expects to see a
+        ;; version field.
+        (version ,version)
         ,@(or (and=> (assoc-ref data 'depend)
                      (lambda (inputs)
                        `((propagated-inputs
@@ -297,13 +302,18 @@ of those files are returned that are unexpectedly installed."
 
 (define texlive->guix-package
   (memoize
-   (lambda* (name #:key repo version (package-database tlpdb))
+   (lambda* (name #:key
+                  repo
+                  (version (number->string %texlive-revision))
+                  (package-database tlpdb))
      "Find the metadata for NAME in the tlpdb and return the `package'
 s-expression corresponding to that package, or #f on failure."
-     (tlpdb->package name (package-database)))))
+     (tlpdb->package name version (package-database)))))
 
-(define (texlive-recursive-import name)
+(define* (texlive-recursive-import name #:key repo version)
   (recursive-import name
+                    #:repo repo
+                    #:version version
                     #:repo->guix-package texlive->guix-package
                     #:guix-name guix-name))
 
index 26eebfe..668b8c8 100644 (file)
@@ -341,6 +341,8 @@ APPEND-VERSION?/string is a string, append this string."
   (match guix-package
     ((or
       ('package ('name name) ('version version) . rest)
+      ('package ('inherit ('simple-texlive-package name . _))
+                ('version version) . rest)
       ('let _ ('package ('name name) ('version version) . rest)))
 
      `(define-public ,(string->symbol
index c5dcc07..203386e 100644 (file)
   #:use-module (guix utils)
   #:use-module (guix scripts)
   #:use-module (guix import texlive)
+  #:use-module (guix import utils)
   #:use-module (guix scripts import)
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-11)
   #:use-module (srfi srfi-37)
   #:use-module (srfi srfi-41)
+  #:use-module (srfi srfi-71)
   #:use-module (ice-9 match)
   #:use-module (ice-9 format)
   #:export (guix-import-texlive))
@@ -58,6 +60,9 @@ Import and convert the Texlive package for PACKAGE-NAME.\n"))
          (option '(#\V "version") #f #f
                  (lambda args
                    (show-version-and-exit "guix import texlive")))
+         (option '(#\r "recursive") #f #f
+                 (lambda (opt name arg result)
+                   (alist-cons 'recursive #t result)))
          %standard-import-options))
 
 \f
@@ -78,12 +83,20 @@ Import and convert the Texlive package for PACKAGE-NAME.\n"))
                             (_ #f))
                            (reverse opts))))
     (match args
-      ((name)
-       (let ((sexp (texlive->guix-package name)))
-         (unless sexp
-           (leave (G_ "failed to import package '~a'~%")
-                  name))
-         sexp))
+      ((spec)
+       (let ((name version (package-name->name+version spec)))
+         (if (assoc-ref opts 'recursive)
+             ;; Recursive import
+             (with-error-handling
+               (map package->definition
+                    (filter identity (texlive-recursive-import name
+                                                               #:version version))))
+             ;; Single import
+             (let ((sexp (texlive->guix-package name #:version version)))
+               (unless sexp
+                 (leave (G_ "failed to download description for package '~a'~%")
+                        name))
+               sexp))))
       (()
        (leave (G_ "too few arguments~%")))
       ((many ...)