unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: David Craven <david@craven.ch>
To: guix-devel@gnu.org
Subject: [PATCH 05/12] import: Add updater for rust crates.
Date: Sun, 11 Dec 2016 18:25:30 +0100	[thread overview]
Message-ID: <20161211172537.23315-6-david@craven.ch> (raw)
In-Reply-To: <20161211172537.23315-1-david@craven.ch>

* 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(-)

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."
-- 
2.11.0

  parent reply	other threads:[~2016-12-11 17:26 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-11 17:25 [PATCH 00/12] Rust build system v2 David Craven
2016-12-11 17:25 ` [PATCH 01/12] upstream: Use a the first url from urls when find2 returns #f David Craven
2016-12-13 17:25   ` Ludovic Courtès
2016-12-13 20:07     ` David Craven
2016-12-13 22:22       ` Ludovic Courtès
2016-12-11 17:25 ` [PATCH 02/12] build-system: Add cargo build system David Craven
2016-12-13 17:26   ` Ludovic Courtès
2016-12-30 11:08   ` Danny Milosavljevic
2017-01-01 14:42     ` David Craven
2016-12-11 17:25 ` [PATCH 03/12] import: utils: Add some utilities David Craven
2016-12-13 17:29   ` Ludovic Courtès
2016-12-13 18:09     ` David Craven
2016-12-11 17:25 ` [PATCH 04/12] import: Add importer for rust crates David Craven
2016-12-13 17:30   ` Ludovic Courtès
2016-12-11 17:25 ` David Craven [this message]
2016-12-13 17:30   ` [PATCH 05/12] import: Add updater " Ludovic Courtès
2016-12-11 17:25 ` [PATCH 06/12] gnu: llvm: Enable install utils David Craven
2016-12-13 22:50   ` Ludovic Courtès
2016-12-11 17:25 ` [PATCH 07/12] gnu: Add rust bootstrap binaries David Craven
2016-12-13 22:44   ` Ludovic Courtès
2016-12-11 17:25 ` [PATCH 08/12] gnu: Add rustc David Craven
2016-12-13 22:47   ` Ludovic Courtès
2016-12-11 17:25 ` [PATCH 09/12] gnu: Add rust-libc David Craven
2016-12-13 22:48   ` Ludovic Courtès
2016-12-11 17:25 ` [PATCH 10/12] RECURSIVE IMPORTER wip David Craven
2016-12-13 22:49   ` Ludovic Courtès
2016-12-11 17:25 ` [PATCH 11/12] gnu: Add rust-rand David Craven
2016-12-13 22:50   ` Ludovic Courtès
2017-01-03  0:52   ` Danny Milosavljevic
2016-12-11 17:25 ` [PATCH 12/12] gnu: Add cargo David Craven
2016-12-13 22:51   ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161211172537.23315-6-david@craven.ch \
    --to=david@craven.ch \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).