From fd63ecbe050bf8fa7c8ff0a003d56cce97b6ded1 Mon Sep 17 00:00:00 2001 From: Martin Becze Date: Mon, 9 Sep 2019 11:36:04 -0400 Subject: import: crate: Allow imports of a specific version. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- doc/guix.texi | 12 +++++++++++- guix/import/crate.scm | 29 +++++++++++++++++++---------- guix/scripts/import/crate.scm | 13 ++++++++++--- 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 9101aafda1..989b3d03bb 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -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 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 ;;; Copyright © 2019 Ludovic Courtès +;;; Copyright © 2019 Martin Becze ;;; ;;; 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 (crate-version-license version) + #:license (and=> (crate-version-license version*) string->license))))) (define (guix-package->crate-name package) diff --git a/guix/scripts/import/crate.scm b/guix/scripts/import/crate.scm index cab9a4397b..7ae8638911 100644 --- a/guix/scripts/import/crate.scm +++ b/guix/scripts/import/crate.scm @@ -2,6 +2,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2014 David Thompson ;;; Copyright © 2016 David Craven +;;; Copyright © 2019 Martin Becze ;;; ;;; 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~%"))) -- cgit v1.2.3