2016-09-22 05:40:58 -04:00
|
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
|
|
|
|
;;; Copyright © 2016 David Craven <david@craven.ch>
|
2020-01-16 15:45:36 -05:00
|
|
|
|
;;; Copyright © 2019, 2020 Ludovic Courtès <ludo@gnu.org>
|
2020-02-04 03:50:48 -05:00
|
|
|
|
;;; Copyright © 2019, 2020 Martin Becze <mjbecze@riseup.net>
|
2016-09-22 05:40:58 -04:00
|
|
|
|
;;;
|
|
|
|
|
;;; This file is part of GNU Guix.
|
|
|
|
|
;;;
|
|
|
|
|
;;; GNU Guix is free software; you can redistribute it and/or modify it
|
|
|
|
|
;;; under the terms of the GNU General Public License as published by
|
|
|
|
|
;;; the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
|
;;; your option) any later version.
|
|
|
|
|
;;;
|
|
|
|
|
;;; GNU Guix is distributed in the hope that it will be useful, but
|
|
|
|
|
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;;; GNU General Public License for more details.
|
|
|
|
|
;;;
|
|
|
|
|
;;; You should have received a copy of the GNU General Public License
|
|
|
|
|
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
(define-module (guix import crate)
|
|
|
|
|
#:use-module (guix base32)
|
|
|
|
|
#:use-module (guix build-system cargo)
|
|
|
|
|
#:use-module ((guix download) #:prefix download:)
|
Switch to Guile-Gcrypt.
This removes (guix hash) and (guix pk-crypto), which now live as part of
Guile-Gcrypt (version 0.1.0.)
* guix/gcrypt.scm, guix/hash.scm, guix/pk-crypto.scm,
tests/hash.scm, tests/pk-crypto.scm: Remove.
* configure.ac: Test for Guile-Gcrypt. Remove LIBGCRYPT and
LIBGCRYPT_LIBDIR assignments.
* m4/guix.m4 (GUIX_ASSERT_LIBGCRYPT_USABLE): Remove.
* README: Add Guile-Gcrypt to the dependencies; move libgcrypt as
"required unless --disable-daemon".
* doc/guix.texi (Requirements): Likewise.
* gnu/packages/bash.scm, guix/derivations.scm, guix/docker.scm,
guix/git.scm, guix/http-client.scm, guix/import/cpan.scm,
guix/import/cran.scm, guix/import/crate.scm, guix/import/elpa.scm,
guix/import/gnu.scm, guix/import/hackage.scm,
guix/import/texlive.scm, guix/import/utils.scm, guix/nar.scm,
guix/pki.scm, guix/scripts/archive.scm,
guix/scripts/authenticate.scm, guix/scripts/download.scm,
guix/scripts/hash.scm, guix/scripts/pack.scm,
guix/scripts/publish.scm, guix/scripts/refresh.scm,
guix/scripts/substitute.scm, guix/store.scm,
guix/store/deduplication.scm, guix/tests.scm, tests/base32.scm,
tests/builders.scm, tests/challenge.scm, tests/cpan.scm,
tests/crate.scm, tests/derivations.scm, tests/gem.scm,
tests/nar.scm, tests/opam.scm, tests/pki.scm,
tests/publish.scm, tests/pypi.scm, tests/store-deduplication.scm,
tests/store.scm, tests/substitute.scm: Adjust imports.
* gnu/system/vm.scm: Likewise.
(guile-sqlite3&co): Rename to...
(gcrypt-sqlite3&co): ... this. Add GUILE-GCRYPT.
(expression->derivation-in-linux-vm)[config]: Remove.
(iso9660-image)[config]: Remove.
(qemu-image)[config]: Remove.
(system-docker-image)[config]: Remove.
* guix/scripts/pack.scm: Adjust imports.
(guile-sqlite3&co): Rename to...
(gcrypt-sqlite3&co): ... this. Add GUILE-GCRYPT.
(self-contained-tarball)[build]: Call 'make-config.scm' without
#:libgcrypt argument.
(squashfs-image)[libgcrypt]: Remove.
[build]: Call 'make-config.scm' without #:libgcrypt.
(docker-image)[config, json]: Remove.
[build]: Add GUILE-GCRYPT to the extensions Remove (guix config) from
the imported modules.
* guix/self.scm (specification->package): Remove "libgcrypt", add
"guile-gcrypt".
(compiled-guix): Remove #:libgcrypt.
[guile-gcrypt]: New variable.
[dependencies]: Add it.
[*core-modules*]: Remove #:libgcrypt from 'make-config.scm' call.
Add #:extensions.
[*config*]: Remove #:libgcrypt from 'make-config.scm' call.
(%dependency-variables): Remove %libgcrypt.
(make-config.scm): Remove #:libgcrypt.
* build-aux/build-self.scm (guile-gcrypt): New variable.
(make-config.scm): Remove #:libgcrypt.
(build-program)[fake-gcrypt-hash]: New variable.
Add (gcrypt hash) to the imported modules. Adjust load path
assignments.
* gnu/packages/package-management.scm (guix)[propagated-inputs]: Add
GUILE-GCRYPT.
[arguments]: In 'wrap-program' phase, add GUILE-GCRYPT to the search
path.
2018-08-31 11:07:07 -04:00
|
|
|
|
#:use-module (gcrypt hash)
|
2016-09-22 05:40:58 -04:00
|
|
|
|
#:use-module (guix http-client)
|
|
|
|
|
#:use-module (guix import json)
|
|
|
|
|
#:use-module (guix import utils)
|
|
|
|
|
#:use-module ((guix licenses) #:prefix license:)
|
2020-01-30 11:17:00 -05:00
|
|
|
|
#:use-module (guix memoization)
|
2016-09-22 05:40:58 -04:00
|
|
|
|
#:use-module (guix monads)
|
|
|
|
|
#:use-module (guix packages)
|
|
|
|
|
#:use-module (guix upstream)
|
|
|
|
|
#:use-module (guix utils)
|
|
|
|
|
#:use-module (ice-9 match)
|
2019-09-01 10:32:11 -04:00
|
|
|
|
#:use-module (ice-9 regex)
|
2016-09-22 05:40:58 -04:00
|
|
|
|
#:use-module (json)
|
|
|
|
|
#:use-module (srfi srfi-1)
|
|
|
|
|
#:use-module (srfi srfi-2)
|
|
|
|
|
#:use-module (srfi srfi-26)
|
2020-02-04 03:50:48 -05:00
|
|
|
|
#:use-module (srfi srfi-71)
|
2016-09-22 05:40:58 -04:00
|
|
|
|
#:export (crate->guix-package
|
2016-09-22 05:40:58 -04:00
|
|
|
|
guix-package->crate-name
|
2020-01-16 15:45:36 -05:00
|
|
|
|
string->license
|
2019-10-01 16:54:56 -04:00
|
|
|
|
crate-recursive-import
|
2016-09-22 05:40:58 -04:00
|
|
|
|
%crate-updater))
|
2016-09-22 05:40:58 -04:00
|
|
|
|
|
2019-09-01 10:20:36 -04:00
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Interface to https://crates.io/api/v1.
|
|
|
|
|
;;;
|
2016-09-22 05:40:58 -04:00
|
|
|
|
|
2019-09-01 10:20:36 -04:00
|
|
|
|
;; Crates. A crate is essentially a "package". It can have several
|
|
|
|
|
;; "versions", each of which has its own set of dependencies, license,
|
|
|
|
|
;; etc.--see <crate-version> below.
|
|
|
|
|
(define-json-mapping <crate> make-crate crate?
|
|
|
|
|
json->crate
|
|
|
|
|
(name crate-name) ;string
|
|
|
|
|
(latest-version crate-latest-version "max_version") ;string
|
|
|
|
|
(home-page crate-home-page "homepage") ;string | #nil
|
|
|
|
|
(repository crate-repository) ;string
|
|
|
|
|
(description crate-description) ;string
|
|
|
|
|
(keywords crate-keywords ;list of strings
|
|
|
|
|
"keywords" vector->list)
|
|
|
|
|
(categories crate-categories ;list of strings
|
|
|
|
|
"categories" vector->list)
|
|
|
|
|
(versions crate-versions "actual_versions" ;list of <crate-version>
|
|
|
|
|
(lambda (vector)
|
|
|
|
|
(map json->crate-version
|
|
|
|
|
(vector->list vector))))
|
|
|
|
|
(links crate-links)) ;alist
|
2016-09-22 05:40:58 -04:00
|
|
|
|
|
2019-09-01 10:20:36 -04:00
|
|
|
|
;; Crate version.
|
|
|
|
|
(define-json-mapping <crate-version> make-crate-version crate-version?
|
|
|
|
|
json->crate-version
|
|
|
|
|
(id crate-version-id) ;integer
|
|
|
|
|
(number crate-version-number "num") ;string
|
|
|
|
|
(download-path crate-version-download-path "dl_path") ;string
|
|
|
|
|
(readme-path crate-version-readme-path "readme_path") ;string
|
|
|
|
|
(license crate-version-license "license") ;string
|
|
|
|
|
(links crate-version-links)) ;alist
|
|
|
|
|
|
|
|
|
|
;; Crate dependency. Each dependency (each edge in the graph) is annotated as
|
|
|
|
|
;; being a "normal" dependency or a development dependency. There also
|
|
|
|
|
;; information about the minimum required version, such as "^0.0.41".
|
|
|
|
|
(define-json-mapping <crate-dependency> make-crate-dependency
|
|
|
|
|
crate-dependency?
|
|
|
|
|
json->crate-dependency
|
|
|
|
|
(id crate-dependency-id "crate_id") ;string
|
2020-02-04 03:50:48 -05:00
|
|
|
|
(kind crate-dependency-kind "kind" ;'normal | 'dev | 'build
|
2019-09-01 10:20:36 -04:00
|
|
|
|
string->symbol)
|
|
|
|
|
(requirement crate-dependency-requirement "req")) ;string
|
|
|
|
|
|
2020-02-04 03:50:48 -05:00
|
|
|
|
(module-autoload! (current-module)
|
|
|
|
|
'(semver) '(string->semver semver<?))
|
|
|
|
|
(module-autoload! (current-module)
|
|
|
|
|
'(semver ranges) '(string->semver-range semver-range-contains?))
|
|
|
|
|
|
2019-09-01 10:20:36 -04:00
|
|
|
|
(define (lookup-crate name)
|
|
|
|
|
"Look up NAME on https://crates.io and return the corresopnding <crate>
|
|
|
|
|
record or #f if it was not found."
|
|
|
|
|
(let ((json (json-fetch (string-append (%crate-base-url) "/api/v1/crates/"
|
|
|
|
|
name))))
|
|
|
|
|
(and=> (and json (assoc-ref json "crate"))
|
|
|
|
|
(lambda (alist)
|
|
|
|
|
;; The "versions" field of ALIST is simply a list of version IDs
|
|
|
|
|
;; (integers). Here, we squeeze in the actual version
|
|
|
|
|
;; dictionaries that are not part of ALIST but are just more
|
|
|
|
|
;; convenient handled this way.
|
|
|
|
|
(let ((versions (or (assoc-ref json "versions") '#())))
|
|
|
|
|
(json->crate `(,@alist
|
|
|
|
|
("actual_versions" . ,versions))))))))
|
|
|
|
|
|
2020-01-30 11:17:00 -05:00
|
|
|
|
(define lookup-crate* (memoize lookup-crate))
|
|
|
|
|
|
2019-09-01 10:20:36 -04:00
|
|
|
|
(define (crate-version-dependencies version)
|
|
|
|
|
"Return the list of <crate-dependency> records of VERSION, a
|
|
|
|
|
<crate-version>."
|
|
|
|
|
(let* ((path (assoc-ref (crate-version-links version) "dependencies"))
|
|
|
|
|
(url (string-append (%crate-base-url) path)))
|
|
|
|
|
(match (assoc-ref (or (json-fetch url) '()) "dependencies")
|
|
|
|
|
((? vector? vector)
|
2020-01-30 10:52:28 -05:00
|
|
|
|
(delete-duplicates (map json->crate-dependency (vector->list vector))))
|
2019-09-01 10:20:36 -04:00
|
|
|
|
(_
|
|
|
|
|
'()))))
|
2016-09-22 05:40:58 -04:00
|
|
|
|
|
2019-09-01 10:20:36 -04:00
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Converting crates to Guix packages.
|
|
|
|
|
;;;
|
2016-09-22 05:40:58 -04:00
|
|
|
|
|
2019-05-17 03:26:07 -04:00
|
|
|
|
(define (maybe-cargo-inputs package-names)
|
|
|
|
|
(match (package-names->package-inputs package-names)
|
|
|
|
|
(()
|
|
|
|
|
'())
|
|
|
|
|
((package-inputs ...)
|
2019-06-30 10:18:20 -04:00
|
|
|
|
`(#:cargo-inputs ,package-inputs))))
|
2019-05-17 03:26:07 -04:00
|
|
|
|
|
|
|
|
|
(define (maybe-cargo-development-inputs package-names)
|
|
|
|
|
(match (package-names->package-inputs package-names)
|
|
|
|
|
(()
|
|
|
|
|
'())
|
|
|
|
|
((package-inputs ...)
|
2019-06-30 10:18:20 -04:00
|
|
|
|
`(#:cargo-development-inputs ,package-inputs))))
|
2019-05-17 03:26:07 -04:00
|
|
|
|
|
|
|
|
|
(define (maybe-arguments arguments)
|
|
|
|
|
(match arguments
|
|
|
|
|
(()
|
|
|
|
|
'())
|
|
|
|
|
((args ...)
|
|
|
|
|
`((arguments (,'quasiquote ,args))))))
|
|
|
|
|
|
|
|
|
|
(define* (make-crate-sexp #:key name version cargo-inputs cargo-development-inputs
|
2020-02-03 16:19:49 -05:00
|
|
|
|
home-page synopsis description license build?)
|
2016-09-22 05:40:58 -04:00
|
|
|
|
"Return the `package' s-expression for a rust package with the given NAME,
|
2019-05-17 03:26:07 -04:00
|
|
|
|
VERSION, CARGO-INPUTS, CARGO-DEVELOPMENT-INPUTS, HOME-PAGE, SYNOPSIS, DESCRIPTION,
|
|
|
|
|
and LICENSE."
|
2020-02-04 03:50:48 -05:00
|
|
|
|
(define (format-inputs inputs)
|
|
|
|
|
(map
|
|
|
|
|
(match-lambda
|
|
|
|
|
((name version)
|
2020-11-14 13:47:32 -05:00
|
|
|
|
(list (crate-name->package-name name)
|
|
|
|
|
(version-major+minor version))))
|
2020-02-04 03:50:48 -05:00
|
|
|
|
inputs))
|
|
|
|
|
|
2016-09-22 05:40:58 -04:00
|
|
|
|
(let* ((port (http-fetch (crate-uri name version)))
|
|
|
|
|
(guix-name (crate-name->package-name name))
|
2020-02-04 03:50:48 -05:00
|
|
|
|
(cargo-inputs (format-inputs cargo-inputs))
|
|
|
|
|
(cargo-development-inputs (format-inputs cargo-development-inputs))
|
2016-09-22 05:40:58 -04:00
|
|
|
|
(pkg `(package
|
|
|
|
|
(name ,guix-name)
|
|
|
|
|
(version ,version)
|
|
|
|
|
(source (origin
|
|
|
|
|
(method url-fetch)
|
|
|
|
|
(uri (crate-uri ,name version))
|
|
|
|
|
(file-name (string-append name "-" version ".tar.gz"))
|
|
|
|
|
(sha256
|
|
|
|
|
(base32
|
|
|
|
|
,(bytevector->nix-base32-string (port-sha256 port))))))
|
|
|
|
|
(build-system cargo-build-system)
|
2020-02-03 16:19:49 -05:00
|
|
|
|
,@(maybe-arguments (append (if build?
|
|
|
|
|
'()
|
|
|
|
|
'(#:skip-build? #t))
|
2020-02-04 03:50:48 -05:00
|
|
|
|
(maybe-cargo-inputs cargo-inputs)
|
2019-05-17 03:26:07 -04:00
|
|
|
|
(maybe-cargo-development-inputs
|
|
|
|
|
cargo-development-inputs)))
|
2017-01-01 10:14:45 -05:00
|
|
|
|
(home-page ,(match home-page
|
2020-10-19 13:48:33 -04:00
|
|
|
|
('null "")
|
2017-01-01 10:14:45 -05:00
|
|
|
|
(_ home-page)))
|
2016-09-22 05:40:58 -04:00
|
|
|
|
(synopsis ,synopsis)
|
|
|
|
|
(description ,(beautify-description description))
|
|
|
|
|
(license ,(match license
|
|
|
|
|
(() #f)
|
|
|
|
|
((license) license)
|
|
|
|
|
(_ `(list ,@license)))))))
|
|
|
|
|
(close-port port)
|
2020-02-04 03:50:48 -05:00
|
|
|
|
(package->definition pkg #t)))
|
2016-09-22 05:40:58 -04:00
|
|
|
|
|
2019-11-26 15:17:21 -05:00
|
|
|
|
(define (string->license string)
|
|
|
|
|
(filter-map (lambda (license)
|
|
|
|
|
(and (not (string-null? license))
|
|
|
|
|
(not (any (lambda (elem) (string=? elem license))
|
|
|
|
|
'("AND" "OR" "WITH")))
|
|
|
|
|
(or (spdx-string->license license)
|
|
|
|
|
'unknown-license!)))
|
|
|
|
|
(string-split string (string->char-set " /"))))
|
2019-09-01 10:32:11 -04:00
|
|
|
|
|
2020-02-03 16:19:49 -05:00
|
|
|
|
(define* (crate->guix-package crate-name #:key version include-dev-deps? repo)
|
2016-09-22 05:40:58 -04:00
|
|
|
|
"Fetch the metadata for CRATE-NAME from crates.io, and return the
|
2019-09-09 11:36:04 -04:00
|
|
|
|
`package' s-expression corresponding to that package, or #f on failure.
|
2020-02-04 03:50:48 -05:00
|
|
|
|
When VERSION is specified, convert it into a semver range and attempt to fetch
|
|
|
|
|
the latest version matching this semver range; otherwise fetch the latest
|
2020-02-03 16:19:49 -05:00
|
|
|
|
version of CRATE-NAME. If INCLUDE-DEV-DEPS is true then this will also
|
|
|
|
|
look up the development dependencs for the given crate."
|
2020-02-04 03:50:48 -05:00
|
|
|
|
|
|
|
|
|
(define (semver-range-contains-string? range version)
|
|
|
|
|
(semver-range-contains? (string->semver-range range)
|
|
|
|
|
(string->semver version)))
|
2019-09-01 10:20:36 -04:00
|
|
|
|
|
|
|
|
|
(define (normal-dependency? dependency)
|
2020-02-04 03:50:48 -05:00
|
|
|
|
(or (eq? (crate-dependency-kind dependency) 'build)
|
|
|
|
|
(eq? (crate-dependency-kind dependency) 'normal)))
|
2019-09-01 10:20:36 -04:00
|
|
|
|
|
|
|
|
|
(define crate
|
2020-01-30 11:17:00 -05:00
|
|
|
|
(lookup-crate* crate-name))
|
2019-09-01 10:20:36 -04:00
|
|
|
|
|
2019-09-09 11:36:04 -04:00
|
|
|
|
(define version-number
|
2020-04-27 16:17:53 -04:00
|
|
|
|
(and crate
|
|
|
|
|
(or version
|
|
|
|
|
(crate-latest-version crate))))
|
2019-09-09 11:36:04 -04:00
|
|
|
|
|
2020-02-04 03:50:48 -05:00
|
|
|
|
;; find the highest version of a crate that fulfills the semver <range>
|
|
|
|
|
(define (find-crate-version crate range)
|
|
|
|
|
(let* ((semver-range (string->semver-range range))
|
|
|
|
|
(versions
|
|
|
|
|
(sort
|
|
|
|
|
(filter (lambda (entry)
|
|
|
|
|
(semver-range-contains? semver-range (first entry)))
|
|
|
|
|
(map (lambda (ver)
|
|
|
|
|
(list (string->semver (crate-version-number ver))
|
|
|
|
|
ver))
|
|
|
|
|
(crate-versions crate)))
|
|
|
|
|
(match-lambda* (((semver _) ...)
|
|
|
|
|
(apply semver<? semver))))))
|
|
|
|
|
(and (not (null-list? versions))
|
|
|
|
|
(second (last versions)))))
|
|
|
|
|
|
2019-09-09 11:36:04 -04:00
|
|
|
|
(define version*
|
2020-04-27 16:17:53 -04:00
|
|
|
|
(and crate
|
2020-02-04 03:50:48 -05:00
|
|
|
|
(find-crate-version crate version-number)))
|
|
|
|
|
|
|
|
|
|
;; sort and map the dependencies to a list containing
|
|
|
|
|
;; pairs of (name version)
|
|
|
|
|
(define (sort-map-dependencies deps)
|
|
|
|
|
(sort (map (lambda (dep)
|
|
|
|
|
(let* ((name (crate-dependency-id dep))
|
2020-01-30 11:17:00 -05:00
|
|
|
|
(crate (lookup-crate* name))
|
2020-02-04 03:50:48 -05:00
|
|
|
|
(req (crate-dependency-requirement dep))
|
|
|
|
|
(ver (find-crate-version crate req)))
|
|
|
|
|
(list name
|
|
|
|
|
(crate-version-number ver))))
|
|
|
|
|
deps)
|
|
|
|
|
(match-lambda* (((name _) ...)
|
|
|
|
|
(apply string-ci<? name)))))
|
2019-09-09 11:36:04 -04:00
|
|
|
|
|
|
|
|
|
(and crate version*
|
2020-02-04 03:50:48 -05:00
|
|
|
|
(let* ((dependencies (crate-version-dependencies version*))
|
|
|
|
|
(dep-crates dev-dep-crates (partition normal-dependency? dependencies))
|
|
|
|
|
(cargo-inputs (sort-map-dependencies dep-crates))
|
2020-02-03 16:19:49 -05:00
|
|
|
|
(cargo-development-inputs (if include-dev-deps?
|
|
|
|
|
(sort-map-dependencies dev-dep-crates)
|
|
|
|
|
'())))
|
2019-10-01 16:54:56 -04:00
|
|
|
|
(values
|
2020-02-03 16:19:49 -05:00
|
|
|
|
(make-crate-sexp #:build? include-dev-deps?
|
|
|
|
|
#:name crate-name
|
2019-10-01 16:54:56 -04:00
|
|
|
|
#:version (crate-version-number version*)
|
|
|
|
|
#:cargo-inputs cargo-inputs
|
|
|
|
|
#:cargo-development-inputs cargo-development-inputs
|
|
|
|
|
#:home-page (or (crate-home-page crate)
|
|
|
|
|
(crate-repository crate))
|
|
|
|
|
#:synopsis (crate-description crate)
|
|
|
|
|
#:description (crate-description crate)
|
|
|
|
|
#:license (and=> (crate-version-license version*)
|
|
|
|
|
string->license))
|
|
|
|
|
(append cargo-inputs cargo-development-inputs)))))
|
|
|
|
|
|
2020-02-04 07:18:18 -05:00
|
|
|
|
(define* (crate-recursive-import crate-name #:key version)
|
|
|
|
|
(recursive-import crate-name
|
2020-02-03 16:19:49 -05:00
|
|
|
|
#:repo->guix-package (lambda* params
|
|
|
|
|
;; download development dependencies only for the top level package
|
|
|
|
|
(let ((include-dev-deps? (equal? (car params) crate-name))
|
|
|
|
|
(crate->guix-package* (memoize crate->guix-package)))
|
|
|
|
|
(apply crate->guix-package*
|
|
|
|
|
(append params `(#:include-dev-deps? ,include-dev-deps?)))))
|
2020-02-04 07:18:18 -05:00
|
|
|
|
#:version version
|
2019-10-01 16:54:56 -04:00
|
|
|
|
#:guix-name crate-name->package-name))
|
2016-09-22 05:40:58 -04:00
|
|
|
|
|
|
|
|
|
(define (guix-package->crate-name package)
|
|
|
|
|
"Return the crate name of PACKAGE."
|
|
|
|
|
(and-let* ((origin (package-source package))
|
|
|
|
|
(uri (origin-uri origin))
|
|
|
|
|
(crate-url? uri)
|
|
|
|
|
(len (string-length crate-url))
|
|
|
|
|
(path (xsubstring uri len))
|
|
|
|
|
(parts (string-split path #\/)))
|
|
|
|
|
(match parts
|
|
|
|
|
((name _ ...) name))))
|
|
|
|
|
|
|
|
|
|
(define (crate-name->package-name name)
|
2020-02-04 03:50:48 -05:00
|
|
|
|
(guix-name "rust-" name))
|
2016-09-22 05:40:58 -04:00
|
|
|
|
|
2019-09-01 10:20:36 -04:00
|
|
|
|
|
2016-09-22 05:40:58 -04:00
|
|
|
|
;;;
|
|
|
|
|
;;; Updater
|
|
|
|
|
;;;
|
|
|
|
|
|
2020-07-03 16:45:21 -04:00
|
|
|
|
(define crate-package?
|
|
|
|
|
(url-predicate crate-url?))
|
2016-09-22 05:40:58 -04:00
|
|
|
|
|
|
|
|
|
(define (latest-release package)
|
|
|
|
|
"Return an <upstream-source> for the latest release of PACKAGE."
|
|
|
|
|
(let* ((crate-name (guix-package->crate-name package))
|
2019-09-01 10:20:36 -04:00
|
|
|
|
(crate (lookup-crate crate-name))
|
|
|
|
|
(version (crate-latest-version crate))
|
|
|
|
|
(url (crate-uri crate-name version)))
|
2016-09-22 05:40:58 -04:00
|
|
|
|
(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)))
|
|
|
|
|
|