Patchwork [07/12] import: crate: Add crate updater.

login
register
mail settings
Submitter David Craven
Date Sept. 22, 2016, 1:18 p.m.
Message ID <20160922131903.1606-7-david@craven.ch>
Download mbox | patch
Permalink /patch/15923/
State New
Headers show

Comments

David Craven - Sept. 22, 2016, 1:18 p.m.
* guix/import/crate.scm (crate-package?, latest-release,
  %crate-updater): New variables.
* guix/scripts/refresh.scm (%updaters): Add %crate-updater to list of
  updaters.
* guix/upstream.scm (package-update): Use a url from the list when the
  find2 procedure doesn't find a url sig-url pair.
---
 guix/import/crate.scm    | 36 +++++++++++++++++++++++++++++++++++-
 guix/scripts/refresh.scm |  4 +++-
 guix/upstream.scm        |  2 +-
 3 files changed, 39 insertions(+), 3 deletions(-)
Ludovic Courtès - Sept. 26, 2016, 10:09 a.m.
David Craven <david@craven.ch> skribis:

> * guix/import/crate.scm (crate-package?, latest-release,
>   %crate-updater): New variables.
> * guix/scripts/refresh.scm (%updaters): Add %crate-updater to list of
>   updaters.
> * guix/upstream.scm (package-update): Use a url from the list when the
>   find2 procedure doesn't find a url sig-url pair.

Neat!

> +(define (latest-release package)
> +  "Return an <upstream-source> for the latest release of PACKAGE."
> +  (let* ((crate-name (guix-package->crate-name package))
> +         (metadata (crate-fetch crate-name))
> +         (version (assoc-ref* metadata "crate" "max_version"))
> +         (url (crate-uri crate-name version)))
> +    (upstream-source
> +     (package (package-name package))
> +     (version version)
> +     (urls (list url)))))

So they don’t publish OpenPGP signatures?  :-/

> --- a/guix/upstream.scm
> +++ b/guix/upstream.scm
> @@ -194,7 +194,7 @@ and 'interactive' (default)."
>                               (string-suffix? archive-type url))
>                             urls
>                             (or signature-urls (circular-list #f)))))
> -       (let ((tarball (download-tarball store url signature-url
> +       (let ((tarball (download-tarball store (if url url (car urls)) signature-url

I don’t understand this part, and I suspect it could lead to
inconsistent results where the signature URL doesn’t match the source
URL.

Do you have an example of the problem you experienced?  Since the
problem is probably not specific to Crates, we should probably address
it in a separate patch.

Otherwise LGTM!

Thanks,
Ludo’.

Patch

diff --git a/guix/import/crate.scm b/guix/import/crate.scm
index 3cc17f2..5b34330 100644
--- a/guix/import/crate.scm
+++ b/guix/import/crate.scm
@@ -28,7 +28,8 @@ 
   #:use-module (json)
   #:use-module (srfi srfi-1)
   #:export (crate->guix-package
-            guix-package->crate-name))
+            guix-package->crate-name
+            %crate-updater))
 
 (define (crate-fetch name)
   "Return an alist representation of the crates.io metadata for the package NAME,
@@ -89,3 +90,36 @@  VERSION, SOURCE-URL, HOME-PAGE, SYNOPSIS, DESCRIPTION, and LICENSE."
 
 (define (crate-name->package-name name)
   (string-append "rust-" name))
+
+(define (crate-package? package)
+  "Return true if PACKAGE is a Rust crate from crates.io."
+
+  (define (crate-url? url)
+    (string-prefix? "https://crates.io/" url))
+
+  (let ((source-url (and=> (package-source package) origin-uri))
+        (fetch-method (and=> (package-source package) origin-method)))
+    (and (eq? fetch-method download:url-fetch)
+         (match source-url
+           ((? string?)
+            (crate-url? source-url))
+           ((source-url ...)
+            (any crate-url? source-url))))))
+
+(define (latest-release package)
+  "Return an <upstream-source> for the latest release of PACKAGE."
+  (let* ((crate-name (guix-package->crate-name package))
+         (metadata (crate-fetch crate-name))
+         (version (assoc-ref* metadata "crate" "max_version"))
+         (url (crate-uri crate-name version)))
+    (upstream-source
+     (package (package-name package))
+     (version version)
+     (urls (list url)))))
+
+(define %crate-updater
+  (upstream-updater
+   (name 'crates)
+   (description "Updater for crates.io packages")
+   (pred crate-package?)
+   (latest latest-release)))
diff --git a/guix/scripts/refresh.scm b/guix/scripts/refresh.scm
index b00ac98..3cd5223 100644
--- a/guix/scripts/refresh.scm
+++ b/guix/scripts/refresh.scm
@@ -38,6 +38,7 @@ 
                           %xorg-updater))
   #:use-module (guix import elpa)
   #:use-module (guix import cran)
+  #:use-module (guix import crate)
   #:use-module (guix import hackage)
   #:use-module (guix gnupg)
   #:use-module (gnu packages)
@@ -206,7 +207,8 @@  unavailable optional dependencies such as Guile-JSON."
                  %hackage-updater
                  ((guix import pypi) => %pypi-updater)
                  ((guix import gem) => %gem-updater)
-                 ((guix import github) => %github-updater)))
+                 ((guix import github) => %github-updater)
+                 ((guix import crate) => %crate-updater)))
 
 (define (lookup-updater name)
   "Return the updater called NAME."
diff --git a/guix/upstream.scm b/guix/upstream.scm
index 1815737..ac3f72f 100644
--- a/guix/upstream.scm
+++ b/guix/upstream.scm
@@ -194,7 +194,7 @@  and 'interactive' (default)."
                              (string-suffix? archive-type url))
                            urls
                            (or signature-urls (circular-list #f)))))
-       (let ((tarball (download-tarball store url signature-url
+       (let ((tarball (download-tarball store (if url url (car urls)) signature-url
                                         #:key-download key-download)))
          (values version tarball))))
     (#f