diff options
author | Martin Becze <mjbecze@riseup.net> | 2019-10-01 16:54:57 -0400 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2019-10-01 23:34:31 +0200 |
commit | ed661e38d8ce3c4efa5c495b2c34ba86e1e43290 (patch) | |
tree | d853a8c1aad50cd571c0f44d4d9d0213b2eb60dc | |
parent | f8372932027680a1f2f1b41ea8e19c12bb7d7070 (diff) |
import: crate: Add '--recursive'.
* guix/scripts/import/crate.scm (show-help, guix-import-crate): Add '--recursive'.
* doc/guix.texi (Invoking guix import): Mention '--recursive'.
Co-authored-by: Ludovic Courtès <ludo@gnu.org>
-rw-r--r-- | doc/guix.texi | 10 | ||||
-rw-r--r-- | guix/scripts/import/crate.scm | 36 |
2 files changed, 36 insertions, 10 deletions
diff --git a/doc/guix.texi b/doc/guix.texi index a6c1319405..93139e2d05 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -9083,6 +9083,16 @@ The crate importer also allows you to specify a version string: guix import crate constant-time-eq@@0.1.0 @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 + @item opam @cindex OPAM @cindex OCaml diff --git a/guix/scripts/import/crate.scm b/guix/scripts/import/crate.scm index 7ae8638911..4690cceb4d 100644 --- a/guix/scripts/import/crate.scm +++ b/guix/scripts/import/crate.scm @@ -28,6 +28,7 @@ #:use-module (srfi srfi-1) #:use-module (srfi srfi-11) #:use-module (srfi srfi-37) + #:use-module (srfi srfi-41) #:use-module (ice-9 match) #:use-module (ice-9 format) #:export (guix-import-crate)) @@ -44,6 +45,9 @@ (display (G_ "Usage: guix import crate PACKAGE-NAME Import and convert the crate.io package for PACKAGE-NAME.\n")) (display (G_ " + -r, --recursive import packages recursively")) + (newline) + (display (G_ " -h, --help display this help and exit")) (display (G_ " -V, --version display version information and exit")) @@ -59,6 +63,9 @@ Import and convert the crate.io package for PACKAGE-NAME.\n")) (option '(#\V "version") #f #f (lambda args (show-version-and-exit "guix import crate"))) + (option '(#\r "recursive") #f #f + (lambda (opt name arg result) + (alist-cons 'recursive #t result))) %standard-import-options)) @@ -79,22 +86,31 @@ Import and convert the crate.io package for PACKAGE-NAME.\n")) (let* ((opts (parse-options)) (args (filter-map (match-lambda - (('argument . value) - value) - (_ #f)) + (('argument . value) + value) + (_ #f)) (reverse opts)))) (match args ((spec) (define-values (name version) (package-name->name+version spec)) - (let ((sexp (crate->guix-package name version))) - (unless sexp - (leave (G_ "failed to download meta-data for package '~a'~%") - (if version - (string-append name "@" version) - name))) - sexp)) + (if (assoc-ref opts 'recursive) + (map (match-lambda + ((and ('package ('name name) . rest) pkg) + `(define-public ,(string->symbol name) + ,pkg)) + (_ #f)) + (reverse + (stream->list + (crate-recursive-import name)))) + (let ((sexp (crate->guix-package name version))) + (unless sexp + (leave (G_ "failed to download meta-data for package '~a'~%") + (if version + (string-append name "@" version) + name))) + sexp))) (() (leave (G_ "too few arguments~%"))) ((many ...) |