summaryrefslogtreecommitdiff
path: root/guix/import/crate.scm
diff options
context:
space:
mode:
authorDavid Craven <david@craven.ch>2016-09-22 11:40:58 +0200
committerDavid Craven <david@craven.ch>2016-12-14 16:30:42 +0100
commit8ac529878640de632356895fbcaeeed6c1cb335e (patch)
tree25ac42be793630a474ed26a618324d055f3c7971 /guix/import/crate.scm
parent3e0c036584b41bcc08a8c8e040295716108bb0b2 (diff)
import: Add updater for rust crates.
* guix/import/crate.scm (crate-package?, latest-release, %crate-updater): New variables. * guix/scripts/refresh.scm (%updaters): Add crate updater. * doc/guix.texi: Add crate updater to table.
Diffstat (limited to 'guix/import/crate.scm')
-rw-r--r--guix/import/crate.scm36
1 files changed, 35 insertions, 1 deletions
diff --git a/guix/import/crate.scm b/guix/import/crate.scm
index e78e3ad9ca..3a19fc70cf 100644
--- a/guix/import/crate.scm
+++ b/guix/import/crate.scm
@@ -36,7 +36,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."
@@ -123,3 +124,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)))
+