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:
parent
7c101c4c17
commit
fd63ecbe05
|
@ -8912,7 +8912,17 @@ in Guix.
|
||||||
@item crate
|
@item crate
|
||||||
@cindex crate
|
@cindex crate
|
||||||
Import metadata from the crates.io Rust package repository
|
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
|
@item opam
|
||||||
@cindex OPAM
|
@cindex OPAM
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
;;; GNU Guix --- Functional package management for GNU
|
;;; GNU Guix --- Functional package management for GNU
|
||||||
;;; Copyright © 2016 David Craven <david@craven.ch>
|
;;; Copyright © 2016 David Craven <david@craven.ch>
|
||||||
;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
|
;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
|
||||||
|
;;; Copyright © 2019 Martin Becze <mjbecze@riseup.net>
|
||||||
;;;
|
;;;
|
||||||
;;; This file is part of GNU Guix.
|
;;; This file is part of GNU Guix.
|
||||||
;;;
|
;;;
|
||||||
|
@ -181,9 +182,11 @@ and LICENSE."
|
||||||
;; This regexp matches that.
|
;; This regexp matches that.
|
||||||
(make-regexp "^(.*) OR (.*)$"))
|
(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
|
"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)
|
(define (string->license string)
|
||||||
(match (regexp-exec %dual-license-rx string)
|
(match (regexp-exec %dual-license-rx string)
|
||||||
(#f (list (spdx-string->license string)))
|
(#f (list (spdx-string->license string)))
|
||||||
|
@ -196,12 +199,18 @@ and LICENSE."
|
||||||
(define crate
|
(define crate
|
||||||
(lookup-crate crate-name))
|
(lookup-crate crate-name))
|
||||||
|
|
||||||
(and crate
|
(define version-number
|
||||||
(let* ((version (find (lambda (version)
|
(or version
|
||||||
(string=? (crate-version-number version)
|
(crate-latest-version crate)))
|
||||||
(crate-latest-version crate)))
|
|
||||||
(crate-versions crate)))
|
(define version*
|
||||||
(dependencies (crate-version-dependencies 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))
|
(dep-crates (filter normal-dependency? dependencies))
|
||||||
(dev-dep-crates (remove normal-dependency? dependencies))
|
(dev-dep-crates (remove normal-dependency? dependencies))
|
||||||
(cargo-inputs (sort (map crate-dependency-id dep-crates)
|
(cargo-inputs (sort (map crate-dependency-id dep-crates)
|
||||||
|
@ -210,14 +219,14 @@ and LICENSE."
|
||||||
(sort (map crate-dependency-id dev-dep-crates)
|
(sort (map crate-dependency-id dev-dep-crates)
|
||||||
string-ci<?)))
|
string-ci<?)))
|
||||||
(make-crate-sexp #:name crate-name
|
(make-crate-sexp #:name crate-name
|
||||||
#:version (crate-version-number version)
|
#:version (crate-version-number version*)
|
||||||
#:cargo-inputs cargo-inputs
|
#:cargo-inputs cargo-inputs
|
||||||
#:cargo-development-inputs cargo-development-inputs
|
#:cargo-development-inputs cargo-development-inputs
|
||||||
#:home-page (or (crate-home-page crate)
|
#:home-page (or (crate-home-page crate)
|
||||||
(crate-repository crate))
|
(crate-repository crate))
|
||||||
#:synopsis (crate-description crate)
|
#:synopsis (crate-description crate)
|
||||||
#:description (crate-description crate)
|
#:description (crate-description crate)
|
||||||
#:license (and=> (crate-version-license version)
|
#:license (and=> (crate-version-license version*)
|
||||||
string->license)))))
|
string->license)))))
|
||||||
|
|
||||||
(define (guix-package->crate-name package)
|
(define (guix-package->crate-name package)
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
;;; GNU Guix --- Functional package management for GNU
|
;;; GNU Guix --- Functional package management for GNU
|
||||||
;;; Copyright © 2014 David Thompson <davet@gnu.org>
|
;;; Copyright © 2014 David Thompson <davet@gnu.org>
|
||||||
;;; Copyright © 2016 David Craven <david@craven.ch>
|
;;; Copyright © 2016 David Craven <david@craven.ch>
|
||||||
|
;;; Copyright © 2019 Martin Becze <mjbecze@riseup.net>
|
||||||
;;;
|
;;;
|
||||||
;;; This file is part of GNU Guix.
|
;;; 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))
|
(alist-cons 'argument arg result))
|
||||||
%default-options))
|
%default-options))
|
||||||
|
|
||||||
|
|
||||||
(let* ((opts (parse-options))
|
(let* ((opts (parse-options))
|
||||||
(args (filter-map (match-lambda
|
(args (filter-map (match-lambda
|
||||||
(('argument . value)
|
(('argument . value)
|
||||||
|
@ -82,11 +84,16 @@ Import and convert the crate.io package for PACKAGE-NAME.\n"))
|
||||||
(_ #f))
|
(_ #f))
|
||||||
(reverse opts))))
|
(reverse opts))))
|
||||||
(match args
|
(match args
|
||||||
((package-name)
|
((spec)
|
||||||
(let ((sexp (crate->guix-package package-name)))
|
(define-values (name version)
|
||||||
|
(package-name->name+version spec))
|
||||||
|
|
||||||
|
(let ((sexp (crate->guix-package name version)))
|
||||||
(unless sexp
|
(unless sexp
|
||||||
(leave (G_ "failed to download meta-data for package '~a'~%")
|
(leave (G_ "failed to download meta-data for package '~a'~%")
|
||||||
package-name))
|
(if version
|
||||||
|
(string-append name "@" version)
|
||||||
|
name)))
|
||||||
sexp))
|
sexp))
|
||||||
(()
|
(()
|
||||||
(leave (G_ "too few arguments~%")))
|
(leave (G_ "too few arguments~%")))
|
||||||
|
|
Loading…
Reference in New Issue