From: Karl Meakin <karl.w.f.meakin@gmail.com>
To: 35813@debbugs.gnu.org
Cc: Karl Meakin <Karlwfmeakin@gmail.com>
Subject: [bug#35813] [PATCH] import: crate: add recursive option
Date: Mon, 20 May 2019 19:23:06 +0100 [thread overview]
Message-ID: <20190520182306.11899-1-Karlwfmeakin@gmail.com> (raw)
* guix/script/import/crate.scm: Add recursive option.
* guix/import/crate.scm (crate-recursive-import): New variable.
---
doc/guix.texi | 8 ++++++++
guix/import/crate.scm | 24 ++++++++++++++++--------
guix/scripts/import/crate.scm | 27 ++++++++++++++++++++++-----
3 files changed, 46 insertions(+), 13 deletions(-)
diff --git a/doc/guix.texi b/doc/guix.texi
index ae9ad0739e..636bb7521d 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -8787,6 +8787,14 @@ in Guix.
Import metadata from the crates.io Rust package repository
@uref{https://crates.io, crates.io}.
+@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/import/crate.scm b/guix/import/crate.scm
index e0b400d054..d8554b0e7a 100644
--- a/guix/import/crate.scm
+++ b/guix/import/crate.scm
@@ -37,6 +37,7 @@
#:use-module (srfi srfi-26)
#:export (crate->guix-package
guix-package->crate-name
+ crate-recursive-import
%crate-updater))
(define (crate-fetch crate-name callback)
@@ -86,8 +87,8 @@
VERSION, INPUTS, NATIVE-INPUTS, HOME-PAGE, SYNOPSIS, DESCRIPTION, and LICENSE."
(let* ((port (http-fetch (crate-uri name version)))
(guix-name (crate-name->package-name name))
- (inputs (map crate-name->package-name inputs))
- (native-inputs (map crate-name->package-name native-inputs))
+ (input-packages (map crate-name->package-name inputs))
+ (native-input-packages (map crate-name->package-name native-inputs))
(pkg `(package
(name ,guix-name)
(version ,version)
@@ -99,8 +100,8 @@ VERSION, INPUTS, NATIVE-INPUTS, HOME-PAGE, SYNOPSIS, DESCRIPTION, and LICENSE."
(base32
,(bytevector->nix-base32-string (port-sha256 port))))))
(build-system cargo-build-system)
- ,@(maybe-native-inputs native-inputs "src")
- ,@(maybe-inputs inputs "src")
+ ,@(maybe-native-inputs native-input-packages "src")
+ ,@(maybe-inputs input-packages "src")
(home-page ,(match home-page
(() "")
(_ home-page)))
@@ -111,12 +112,14 @@ VERSION, INPUTS, NATIVE-INPUTS, HOME-PAGE, SYNOPSIS, DESCRIPTION, and LICENSE."
((license) license)
(_ `(list ,@license)))))))
(close-port port)
- pkg))
+ (values pkg inputs)))
-(define (crate->guix-package crate-name)
- "Fetch the metadata for CRATE-NAME from crates.io, and return the
+(define crate->guix-package
+ (memoize
+ (lambda* (crate-name _)
+ "Fetch the metadata for CRATE-NAME from crates.io, and return the
`package' s-expression corresponding to that package, or #f on failure."
- (crate-fetch crate-name make-crate-sexp))
+ (crate-fetch crate-name make-crate-sexp))))
(define (guix-package->crate-name package)
"Return the crate name of PACKAGE."
@@ -158,6 +161,11 @@ VERSION, INPUTS, NATIVE-INPUTS, HOME-PAGE, SYNOPSIS, DESCRIPTION, and LICENSE."
(version version)
(urls (list url)))))
+(define* (crate-recursive-import package-name)
+ (recursive-import package-name #f
+ #:repo->guix-package crate->guix-package
+ #:guix-name crate-name->package-name))
+
(define %crate-updater
(upstream-updater
(name 'crates)
diff --git a/guix/scripts/import/crate.scm b/guix/scripts/import/crate.scm
index cab9a4397b..8fadcdd57c 100644
--- a/guix/scripts/import/crate.scm
+++ b/guix/scripts/import/crate.scm
@@ -27,6 +27,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))
@@ -45,6 +46,8 @@ Import and convert the crate.io package for PACKAGE-NAME.\n"))
(display (G_ "
-h, --help display this help and exit"))
(display (G_ "
+ -r, --recursive import packages recursively"))
+ (display (G_ "
-V, --version display version information and exit"))
(newline)
(show-bug-report-information))
@@ -58,6 +61,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))
\f
@@ -83,11 +89,22 @@ Import and convert the crate.io package for PACKAGE-NAME.\n"))
(reverse opts))))
(match args
((package-name)
- (let ((sexp (crate->guix-package package-name)))
- (unless sexp
- (leave (G_ "failed to download meta-data for package '~a'~%")
- package-name))
- sexp))
+ (if (assoc-ref opts 'recursive)
+ ;; Recursive import
+ (map (match-lambda
+ ((and ('package ('name name) . rest) pkg)
+ `(define-public ,(string->symbol name)
+ ,pkg))
+ (_ #f))
+ (reverse
+ (stream->list
+ (crate-recursive-import package-name))))
+ ;; Single import
+ (let ((sexp (crate->guix-package package-name #f)))
+ (unless sexp
+ (leave (G_ "failed to download meta-data for package '~a'~%")
+ package-name))
+ sexp)))
(()
(leave (G_ "too few arguments~%")))
((many ...)
--
2.21.0
next reply other threads:[~2019-05-20 19:43 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-20 18:23 Karl Meakin [this message]
2019-05-24 15:42 ` [bug#35813] [PATCH] import: crate: add recursive option Ludovic Courtès
2019-05-25 19:38 ` Ivan Petkov
2019-07-20 18:30 ` [bug#35813] Brian Leung
2019-07-20 21:43 ` [bug#35813] Ivan Petkov
2019-08-05 17:50 ` [bug#35813] [PATCH] Add crate-recursive-import Brian Leung
2019-08-06 3:42 ` Brian Leung
2019-08-06 16:03 ` Brian Leung
2019-08-08 10:39 ` Efraim Flashner
2019-09-07 21:49 ` Brian Leung
2019-09-08 7:57 ` Efraim Flashner
2019-10-13 7:42 ` bug#35813: " Brian Leung
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190520182306.11899-1-Karlwfmeakin@gmail.com \
--to=karl.w.f.meakin@gmail.com \
--cc=35813@debbugs.gnu.org \
--cc=Karlwfmeakin@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).