Patchwork [05/12] import: Add updater for rust crates.

login
register
mail settings
Submitter David Craven
Date Dec. 11, 2016, 5:25 p.m.
Message ID <20161211172537.23315-6-david@craven.ch>
Download mbox | patch
Permalink /patch/18358/
State New
Headers show

Comments

David Craven - Dec. 11, 2016, 5:25 p.m.
* guix/import/crate.scm (crate-package?, latest-release,
  %crate-updater): New variables.
* guix/scripts/refresh.scm (%updaters): Add crate updater.
---
 guix/import/crate.scm    | 36 +++++++++++++++++++++++++++++++++++-
 guix/scripts/refresh.scm |  3 ++-
 2 files changed, 37 insertions(+), 2 deletions(-)
Ludovic Courtès - Dec. 13, 2016, 5:30 p.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.

Please add a line under “Invoking guix refresh” in guix.texi, like we
did for the other updaters.

OK with this change!

Ludo’.

Patch

diff --git a/guix/import/crate.scm b/guix/import/crate.scm
index 766b2a12c..45d5bf846 100644
--- a/guix/import/crate.scm
+++ b/guix/import/crate.scm
@@ -35,7 +35,8 @@ 
   #:use-module (srfi srfi-2)
   #:use-module (srfi srfi-26)
   #:export (crate->guix-package
-            guix-package->crate-name))
+            guix-package->crate-name
+            %crate-updater))
 
 (define (crate-fetch crate-name callback)
   "Fetch the metadata for CRATE-NAME from crates.io and call the callback."
@@ -122,3 +123,36 @@  VERSION, INPUTS, NATIVE-INPUTS, HOME-PAGE, SYNOPSIS, DESCRIPTION, and LICENSE."
 (define (crate-name->package-name name)
   (string-append "rust-" (string-join (string-split name #\_) "-")))
 
+;;;
+;;; Updater
+;;;
+
+(define (crate-package? package)
+  "Return true if PACKAGE is a Rust crate from crates.io."
+  (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))
+         (callback (lambda* (#:key version #:allow-other-keys) version))
+         (version (crate-fetch crate-name callback))
+         (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 bcc11a2d2..3d495963c 100644
--- a/guix/scripts/refresh.scm
+++ b/guix/scripts/refresh.scm
@@ -209,7 +209,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-by-name name)
   "Return the updater called NAME."