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>
This commit is contained in:
Martin Becze 2019-09-09 11:36:04 -04:00 committed by Ludovic Courtès
parent 7c101c4c17
commit fd63ecbe05
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
3 changed files with 40 additions and 14 deletions

View File

@ -8912,7 +8912,17 @@ in Guix.
@item crate
@cindex crate
Import metadata from the crates.io Rust package repository
@uref{https://crates.io, crates.io}.
@uref{https://crates.io, crates.io}, as in this example:
@example
guix import crate blake2-rfc
@end example
The crate importer also allows you to specify a version string:
@example
guix import crate constant-time-eq@@0.1.0
@end example
@item opam
@cindex OPAM

View File

@ -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)

View File

@ -2,6 +2,7 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2014 David Thompson <davet@gnu.org>
;;; Copyright © 2016 David Craven <david@craven.ch>
;;; Copyright © 2019 Martin Becze <mjbecze@riseup.net>
;;;
;;; This file is part of GNU Guix.
;;;
@ -75,6 +76,7 @@ Import and convert the crate.io package for PACKAGE-NAME.\n"))
(alist-cons 'argument arg result))
%default-options))
(let* ((opts (parse-options))
(args (filter-map (match-lambda
(('argument . value)
@ -82,11 +84,16 @@ Import and convert the crate.io package for PACKAGE-NAME.\n"))
(_ #f))
(reverse opts))))
(match args
((package-name)
(let ((sexp (crate->guix-package package-name)))
((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'~%")
package-name))
(if version
(string-append name "@" version)
name)))
sexp))
(()
(leave (G_ "too few arguments~%")))