summaryrefslogtreecommitdiff
path: root/guix/import
diff options
context:
space:
mode:
authorMartin Becze <mjbecze@riseup.net>2019-09-09 11:36:04 -0400
committerLudovic Courtès <ludo@gnu.org>2019-09-10 00:34:40 +0200
commitfd63ecbe050bf8fa7c8ff0a003d56cce97b6ded1 (patch)
treef39aa889848227be7f1ea76d22d380d0c8c7ab9a /guix/import
parent7c101c4c175b7abcb43279d1c66b41a91b9c64bc (diff)
import: crate: Allow imports of a specific version.
* guix/import/crate.scm (crate->guix-package): Add optional 'version' argument and honor it. * guix/scripts/import/crate.scm (guix-import-crate): Assume the first argument is a spec and destructure it with 'package-name->name+version'. Pass both to 'crate->guix-package'. * doc/guix.texi (Invoking guix import): Document it. Co-authored-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'guix/import')
-rw-r--r--guix/import/crate.scm29
1 files changed, 19 insertions, 10 deletions
diff --git a/guix/import/crate.scm b/guix/import/crate.scm
index f6057dbf8b..fd1974eae8 100644
--- a/guix/import/crate.scm
+++ b/guix/import/crate.scm
@@ -1,6 +1,7 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2016 David Craven <david@craven.ch>
;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2019 Martin Becze <mjbecze@riseup.net>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -181,9 +182,11 @@ and LICENSE."
;; This regexp matches that.
(make-regexp "^(.*) OR (.*)$"))
-(define (crate->guix-package crate-name)
+(define* (crate->guix-package crate-name #:optional version)
"Fetch the metadata for CRATE-NAME from crates.io, and return the
-`package' s-expression corresponding to that package, or #f on failure."
+`package' s-expression corresponding to that package, or #f on failure.
+When VERSION is specified, attempt to fetch that version; otherwise fetch the
+latest version of CRATE-NAME."
(define (string->license string)
(match (regexp-exec %dual-license-rx string)
(#f (list (spdx-string->license string)))
@@ -196,12 +199,18 @@ and LICENSE."
(define crate
(lookup-crate crate-name))
- (and crate
- (let* ((version (find (lambda (version)
- (string=? (crate-version-number version)
- (crate-latest-version crate)))
- (crate-versions crate)))
- (dependencies (crate-version-dependencies version))
+ (define version-number
+ (or version
+ (crate-latest-version crate)))
+
+ (define version*
+ (find (lambda (version)
+ (string=? (crate-version-number version)
+ version-number))
+ (crate-versions crate)))
+
+ (and crate version*
+ (let* ((dependencies (crate-version-dependencies version*))
(dep-crates (filter normal-dependency? dependencies))
(dev-dep-crates (remove normal-dependency? dependencies))
(cargo-inputs (sort (map crate-dependency-id dep-crates)
@@ -210,14 +219,14 @@ and LICENSE."
(sort (map crate-dependency-id dev-dep-crates)
string-ci<?)))
(make-crate-sexp #:name crate-name
- #:version (crate-version-number version)
+ #:version (crate-version-number version*)
#:cargo-inputs cargo-inputs
#:cargo-development-inputs cargo-development-inputs
#:home-page (or (crate-home-page crate)
(crate-repository crate))
#:synopsis (crate-description crate)
#:description (crate-description crate)
- #:license (and=> (crate-version-license version)
+ #:license (and=> (crate-version-license version*)
string->license)))))
(define (guix-package->crate-name package)