Archived
1
0
Fork 0

import: crate: Use guile-semver to resolve module versions.

* guix/import/crate.scm: Add guile-semver as a soft dependency.
  (make-crate-sexp): Don't allow other keys. Add '#:skip-build?' to build
  system args. Pass a VERSION argument to 'cargo-inputs'.
  (crate->guix-package): Use guile-semver to resolve the correct module
  versions. Treat "build" dependencies as normal dependencies.
  (crate-name->package-name): Reuse the procedure 'guix-name' instead of
  duplicating its logic.
* guix/import/utils.scm (package-names->package-inputs): Implement
  handling of (name version) pairs.
* guix/scripts/import/crate.scm (guix-import-crate): Use
  crate-recursive-import instead of duplicate code.
* tests/crate.scm (recursive-import): Change test packages versions to be
  distinguishable. Add version data to the test. Check created symbols, too.

Co-authored-by: Hartmut Goebel <h.goebel@crazy-compilers.com>
This commit is contained in:
Martin Becze 2020-02-04 03:50:48 -05:00 committed by Hartmut Goebel
parent bea3b17739
commit 269c1db41b
No known key found for this signature in database
GPG key ID: 634A8DFFD3F631DF
4 changed files with 391 additions and 232 deletions

View file

@ -1,7 +1,7 @@
;;; GNU Guix --- Functional package management for GNU ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2016 David Craven <david@craven.ch> ;;; Copyright © 2016 David Craven <david@craven.ch>
;;; Copyright © 2019, 2020 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2019, 2020 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2019 Martin Becze <mjbecze@riseup.net> ;;; Copyright © 2019, 2020 Martin Becze <mjbecze@riseup.net>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -37,6 +37,7 @@
#:use-module (srfi srfi-1) #:use-module (srfi srfi-1)
#:use-module (srfi srfi-2) #:use-module (srfi srfi-2)
#:use-module (srfi srfi-26) #:use-module (srfi srfi-26)
#:use-module (srfi srfi-71)
#:export (crate->guix-package #:export (crate->guix-package
guix-package->crate-name guix-package->crate-name
string->license string->license
@ -85,10 +86,15 @@
crate-dependency? crate-dependency?
json->crate-dependency json->crate-dependency
(id crate-dependency-id "crate_id") ;string (id crate-dependency-id "crate_id") ;string
(kind crate-dependency-kind "kind" ;'normal | 'dev (kind crate-dependency-kind "kind" ;'normal | 'dev | 'build
string->symbol) string->symbol)
(requirement crate-dependency-requirement "req")) ;string (requirement crate-dependency-requirement "req")) ;string
(module-autoload! (current-module)
'(semver) '(string->semver semver<?))
(module-autoload! (current-module)
'(semver ranges) '(string->semver-range semver-range-contains?))
(define (lookup-crate name) (define (lookup-crate name)
"Look up NAME on https://crates.io and return the corresopnding <crate> "Look up NAME on https://crates.io and return the corresopnding <crate>
record or #f if it was not found." record or #f if it was not found."
@ -142,16 +148,21 @@ record or #f if it was not found."
`((arguments (,'quasiquote ,args)))))) `((arguments (,'quasiquote ,args))))))
(define* (make-crate-sexp #:key name version cargo-inputs cargo-development-inputs (define* (make-crate-sexp #:key name version cargo-inputs cargo-development-inputs
home-page synopsis description license home-page synopsis description license)
#:allow-other-keys)
"Return the `package' s-expression for a rust package with the given NAME, "Return the `package' s-expression for a rust package with the given NAME,
VERSION, CARGO-INPUTS, CARGO-DEVELOPMENT-INPUTS, HOME-PAGE, SYNOPSIS, DESCRIPTION, VERSION, CARGO-INPUTS, CARGO-DEVELOPMENT-INPUTS, HOME-PAGE, SYNOPSIS, DESCRIPTION,
and LICENSE." and LICENSE."
(define (format-inputs inputs)
(map
(match-lambda
((name version)
(list (crate-name->package-name name) version)))
inputs))
(let* ((port (http-fetch (crate-uri name version))) (let* ((port (http-fetch (crate-uri name version)))
(guix-name (crate-name->package-name name)) (guix-name (crate-name->package-name name))
(cargo-inputs (map crate-name->package-name cargo-inputs)) (cargo-inputs (format-inputs cargo-inputs))
(cargo-development-inputs (map crate-name->package-name (cargo-development-inputs (format-inputs cargo-development-inputs))
cargo-development-inputs))
(pkg `(package (pkg `(package
(name ,guix-name) (name ,guix-name)
(version ,version) (version ,version)
@ -163,7 +174,8 @@ and LICENSE."
(base32 (base32
,(bytevector->nix-base32-string (port-sha256 port)))))) ,(bytevector->nix-base32-string (port-sha256 port))))))
(build-system cargo-build-system) (build-system cargo-build-system)
,@(maybe-arguments (append (maybe-cargo-inputs cargo-inputs) ,@(maybe-arguments (append '(#:skip-build? #t)
(maybe-cargo-inputs cargo-inputs)
(maybe-cargo-development-inputs (maybe-cargo-development-inputs
cargo-development-inputs))) cargo-development-inputs)))
(home-page ,(match home-page (home-page ,(match home-page
@ -176,7 +188,7 @@ and LICENSE."
((license) license) ((license) license)
(_ `(list ,@license))))))) (_ `(list ,@license)))))))
(close-port port) (close-port port)
pkg)) (package->definition pkg #t)))
(define (string->license string) (define (string->license string)
(filter-map (lambda (license) (filter-map (lambda (license)
@ -190,11 +202,17 @@ and LICENSE."
(define* (crate->guix-package crate-name #:key version repo) (define* (crate->guix-package crate-name #:key version repo)
"Fetch the metadata for CRATE-NAME from crates.io, and return the "Fetch the metadata for CRATE-NAME from crates.io, and return the
`package' s-expression corresponding to that package, or #f on failure. `package' s-expression corresponding to that package, or #f on failure.
When VERSION is specified, attempt to fetch that version; otherwise fetch the When VERSION is specified, convert it into a semver range and attempt to fetch
latest version of CRATE-NAME." the latest version matching this semver range; otherwise fetch the latest
version of CRATE-NAME."
(define (semver-range-contains-string? range version)
(semver-range-contains? (string->semver-range range)
(string->semver version)))
(define (normal-dependency? dependency) (define (normal-dependency? dependency)
(eq? (crate-dependency-kind dependency) 'normal)) (or (eq? (crate-dependency-kind dependency) 'build)
(eq? (crate-dependency-kind dependency) 'normal)))
(define crate (define crate
(lookup-crate crate-name)) (lookup-crate crate-name))
@ -204,22 +222,45 @@ latest version of CRATE-NAME."
(or version (or version
(crate-latest-version crate)))) (crate-latest-version crate))))
;; 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)))))
(define version* (define version*
(and crate (and crate
(find (lambda (version) (find-crate-version crate version-number)))
(string=? (crate-version-number version)
version-number)) ;; sort and map the dependencies to a list containing
(crate-versions crate)))) ;; pairs of (name version)
(define (sort-map-dependencies deps)
(sort (map (lambda (dep)
(let* ((name (crate-dependency-id dep))
(crate (lookup-crate name))
(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)))))
(and crate version* (and crate version*
(let* ((dependencies (crate-version-dependencies version*)) (let* ((dependencies (crate-version-dependencies version*))
(dep-crates (filter normal-dependency? dependencies)) (dep-crates dev-dep-crates (partition normal-dependency? dependencies))
(dev-dep-crates (remove normal-dependency? dependencies)) (cargo-inputs (sort-map-dependencies dep-crates))
(cargo-inputs (sort (map crate-dependency-id dep-crates) (cargo-development-inputs '()))
string-ci<?))
(cargo-development-inputs
(sort (map crate-dependency-id dev-dep-crates)
string-ci<?)))
(values (values
(make-crate-sexp #:name crate-name (make-crate-sexp #:name crate-name
#:version (crate-version-number version*) #:version (crate-version-number version*)
@ -251,7 +292,7 @@ latest version of CRATE-NAME."
((name _ ...) name)))) ((name _ ...) name))))
(define (crate-name->package-name name) (define (crate-name->package-name name)
(string-append "rust-" (string-join (string-split name #\_) "-"))) (guix-name "rust-" name))
;;; ;;;

View file

@ -229,13 +229,20 @@ into a proper sentence and by using two spaces between sentences."
cleaned 'pre ". " 'post))) cleaned 'pre ". " 'post)))
(define* (package-names->package-inputs names #:optional (output #f)) (define* (package-names->package-inputs names #:optional (output #f))
"Given a list of PACKAGE-NAMES, and an optional OUTPUT, tries to generate a "Given a list of PACKAGE-NAMES or (PACKAGE-NAME VERSION) pairs, and an
quoted list of inputs, as suitable to use in an 'inputs' field of a package optional OUTPUT, tries to generate a quoted list of inputs, as suitable to
definition." use in an 'inputs' field of a package definition."
(map (lambda (input) (define (make-input input version)
(cons* input (list 'unquote (string->symbol input)) (cons* input (list 'unquote (string->symbol
(or (and output (list output)) (if version
'()))) (string-append input "-" version)
input)))
(or (and output (list output))
'())))
(map (match-lambda
((input version) (make-input input version))
(input (make-input input #f)))
names)) names))
(define* (maybe-inputs package-names #:optional (output #f)) (define* (maybe-inputs package-names #:optional (output #f))

View file

@ -2,7 +2,7 @@
;;; GNU Guix --- Functional package management for GNU ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2014 David Thompson <davet@gnu.org> ;;; Copyright © 2014 David Thompson <davet@gnu.org>
;;; Copyright © 2016 David Craven <david@craven.ch> ;;; Copyright © 2016 David Craven <david@craven.ch>
;;; Copyright © 2019 Martin Becze <mjbecze@riseup.net> ;;; Copyright © 2019, 2020 Martin Becze <mjbecze@riseup.net>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -95,19 +95,14 @@ Import and convert the crate.io package for PACKAGE-NAME.\n"))
(package-name->name+version spec)) (package-name->name+version spec))
(if (assoc-ref opts 'recursive) (if (assoc-ref opts 'recursive)
(map (match-lambda (crate-recursive-import name #:version version)
((and ('package ('name name) . rest) pkg)
`(define-public ,(string->symbol name)
,pkg))
(_ #f))
(crate-recursive-import name #:version version))
(let ((sexp (crate->guix-package name #:version version))) (let ((sexp (crate->guix-package name #:version version)))
(unless sexp (unless sexp
(leave (G_ "failed to download meta-data for package '~a'~%") (leave (G_ "failed to download meta-data for package '~a'~%")
(if version (if version
(string-append name "@" version) (string-append name "@" version)
name))) name)))
sexp))) (list sexp))))
(() (()
(leave (G_ "too few arguments~%"))) (leave (G_ "too few arguments~%")))
((many ...) ((many ...)

View file

@ -2,6 +2,7 @@
;;; Copyright © 2014 David Thompson <davet@gnu.org> ;;; Copyright © 2014 David Thompson <davet@gnu.org>
;;; Copyright © 2016 David Craven <david@craven.ch> ;;; Copyright © 2016 David Craven <david@craven.ch>
;;; Copyright © 2019, 2020 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2019, 2020 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2020 Martin Becze <mjbecze@riseup.net>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -28,23 +29,67 @@
#:use-module (ice-9 match) #:use-module (ice-9 match)
#:use-module (srfi srfi-64)) #:use-module (srfi srfi-64))
;; crate versions and dependencies used here
;; foo-0.8.1
;; foo-1.0.0
;; foo-1.0.3
;; leaf-alice 0.7.5
;;
;; root-1.0.0
;; root-1.0.4
;; intermediate-a 1.0.42
;; intermeidate-b ^1.0.0
;; leaf-alice ^0.7
;; leaf-bob ^3
;;
;; intermediate-a-1.0.40
;; intermediate-a-1.0.42
;; intermediate-a-1.1.0-alpha.1
;; intermediate-a 1.2.3
;; leaf-alice 0.7.5
;; leaf-bob ^3
;;
;; intermediate-b-1.2.3
;; leaf-bob 3.0.1
;;
;; leaf-alice-0.7.3
;; leaf-alice-0.7.5
;;
;; leaf-bob-3.0.1
(define test-foo-crate (define test-foo-crate
"{ "{
\"crate\": { \"crate\": {
\"max_version\": \"1.0.0\", \"max_version\": \"1.0.3\",
\"name\": \"foo\", \"name\": \"foo\",
\"description\": \"summary\", \"description\": \"summary\",
\"homepage\": \"http://example.com\", \"homepage\": \"http://example.com\",
\"repository\": \"http://example.com\", \"repository\": \"http://example.com\",
\"keywords\": [\"dummy\" \"test\"], \"keywords\": [\"dummy\", \"test\"],
\"categories\": [\"test\"] \"categories\": [\"test\"],
\"actual_versions\": [ \"actual_versions\": [
{ \"id\": \"foo\", { \"id\": 234210,
\"num\": \"0.8.1\",
\"license\": \"MIT OR Apache-2.0\",
\"links\": {
\"dependencies\": \"/api/v1/crates/foo/0.8.1/dependencies\"
}
},
{ \"id\": 234212,
\"num\": \"1.0.0\", \"num\": \"1.0.0\",
\"license\": \"MIT OR Apache-2.0\", \"license\": \"MIT OR Apache-2.0\",
\"links\": { \"links\": {
\"dependencies\": \"/api/v1/crates/foo/1.0.0/dependencies\" \"dependencies\": \"/api/v1/crates/foo/1.0.0/dependencies\"
} }
},
{ \"id\": 234214,
\"num\": \"1.0.3\",
\"license\": \"MIT OR Apache-2.0\",
\"links\": {
\"dependencies\": \"/api/v1/crates/foo/1.0.3/dependencies\"
}
} }
] ]
} }
@ -54,8 +99,9 @@
"{ "{
\"dependencies\": [ \"dependencies\": [
{ {
\"crate_id\": \"bar\", \"crate_id\": \"leaf-alice\",
\"kind\": \"normal\" \"kind\": \"normal\",
\"req\": \"0.7.5\"
} }
] ]
}") }")
@ -63,20 +109,27 @@
(define test-root-crate (define test-root-crate
"{ "{
\"crate\": { \"crate\": {
\"max_version\": \"1.0.0\", \"max_version\": \"1.0.4\",
\"name\": \"root\", \"name\": \"root\",
\"description\": \"summary\", \"description\": \"summary\",
\"homepage\": \"http://example.com\", \"homepage\": \"http://example.com\",
\"repository\": \"http://example.com\", \"repository\": \"http://example.com\",
\"keywords\": [\"dummy\" \"test\"], \"keywords\": [\"dummy\", \"test\"],
\"categories\": [\"test\"] \"categories\": [\"test\"],
\"actual_versions\": [ \"actual_versions\": [
{ \"id\": \"foo\", { \"id\": 234240,
\"num\": \"1.0.0\", \"num\": \"1.0.0\",
\"license\": \"MIT OR Apache-2.0\", \"license\": \"MIT OR Apache-2.0\",
\"links\": { \"links\": {
\"dependencies\": \"/api/v1/crates/root/1.0.0/dependencies\" \"dependencies\": \"/api/v1/crates/root/1.0.0/dependencies\"
} }
},
{ \"id\": 234242,
\"num\": \"1.0.4\",
\"license\": \"MIT OR Apache-2.0\",
\"links\": {
\"dependencies\": \"/api/v1/crates/root/1.0.4/dependencies\"
}
} }
] ]
} }
@ -86,92 +139,114 @@
"{ "{
\"dependencies\": [ \"dependencies\": [
{ {
\"crate_id\": \"intermediate-1\", \"crate_id\": \"intermediate-a\",
\"kind\": \"normal\" \"kind\": \"normal\",
\"req\": \"1.0.42\"
}, },
{ {
\"crate_id\": \"intermediate-2\", \"crate_id\": \"intermediate-b\",
\"kind\": \"normal\" \"kind\": \"normal\",
\"req\": \"^1.0.0\"
} }
{ {
\"crate_id\": \"leaf-alice\", \"crate_id\": \"leaf-alice\",
\"kind\": \"normal\" \"kind\": \"normal\",
\"req\": \"^0.7\"
}, },
{ {
\"crate_id\": \"leaf-bob\", \"crate_id\": \"leaf-bob\",
\"kind\": \"normal\" \"kind\": \"normal\",
\"req\": \"^3\"
} }
] ]
}") }")
(define test-intermediate-1-crate (define test-intermediate-a-crate
"{ "{
\"crate\": { \"crate\": {
\"max_version\": \"1.0.0\", \"max_version\": \"1.1.0-alpha.1\",
\"name\": \"intermediate-1\", \"name\": \"intermediate-a\",
\"description\": \"summary\", \"description\": \"summary\",
\"homepage\": \"http://example.com\", \"homepage\": \"http://example.com\",
\"repository\": \"http://example.com\", \"repository\": \"http://example.com\",
\"keywords\": [\"dummy\" \"test\"], \"keywords\": [\"dummy\", \"test\"],
\"categories\": [\"test\"] \"categories\": [\"test\"],
\"actual_versions\": [ \"actual_versions\": [
{ \"id\": \"intermediate-1\", { \"id\": 234251,
\"num\": \"1.0.0\", \"num\": \"1.0.40\",
\"license\": \"MIT OR Apache-2.0\", \"license\": \"MIT OR Apache-2.0\",
\"links\": { \"links\": {
\"dependencies\": \"/api/v1/crates/intermediate-1/1.0.0/dependencies\" \"dependencies\": \"/api/v1/crates/intermediate-a/1.0.40/dependencies\"
}
},
{ \"id\": 234250,
\"num\": \"1.0.42\",
\"license\": \"MIT OR Apache-2.0\",
\"links\": {
\"dependencies\": \"/api/v1/crates/intermediate-a/1.0.42/dependencies\"
}
},
{ \"id\": 234252,
\"num\": \"1.1.0-alpha.1\",
\"license\": \"MIT OR Apache-2.0\",
\"links\": {
\"dependencies\": \"/api/v1/crates/intermediate-a/1.1.0-alpha.1/dependencies\"
} }
} }
] ]
} }
}") }")
(define test-intermediate-1-dependencies (define test-intermediate-a-dependencies
"{ "{
\"dependencies\": [ \"dependencies\": [
{ {
\"crate_id\": \"intermediate-2\", \"crate_id\": \"intermediate-b\",
\"kind\": \"normal\" \"kind\": \"normal\",
\"req\": \"1.2.3\"
}, },
{ {
\"crate_id\": \"leaf-alice\", \"crate_id\": \"leaf-alice\",
\"kind\": \"normal\" \"kind\": \"normal\",
\"req\": \"0.7.5\"
}, },
{ {
\"crate_id\": \"leaf-bob\", \"crate_id\": \"leaf-bob\",
\"kind\": \"normal\" \"kind\": \"normal\",
\"req\": \"^3\"
} }
] ]
}") }")
(define test-intermediate-2-crate (define test-intermediate-b-crate
"{ "{
\"crate\": { \"crate\": {
\"max_version\": \"1.0.0\", \"max_version\": \"1.2.3\",
\"name\": \"intermediate-2\", \"name\": \"intermediate-b\",
\"description\": \"summary\", \"description\": \"summary\",
\"homepage\": \"http://example.com\", \"homepage\": \"http://example.com\",
\"repository\": \"http://example.com\", \"repository\": \"http://example.com\",
\"keywords\": [\"dummy\" \"test\"], \"keywords\": [\"dummy\", \"test\"],
\"categories\": [\"test\"] \"categories\": [\"test\"],
\"actual_versions\": [ \"actual_versions\": [
{ \"id\": \"intermediate-2\", { \"id\": 234260,
\"num\": \"1.0.0\", \"num\": \"1.2.3\",
\"license\": \"MIT OR Apache-2.0\", \"license\": \"MIT OR Apache-2.0\",
\"links\": { \"links\": {
\"dependencies\": \"/api/v1/crates/intermediate-2/1.0.0/dependencies\" \"dependencies\": \"/api/v1/crates/intermediate-b/1.2.3/dependencies\"
} }
} }
] ]
} }
}") }")
(define test-intermediate-2-dependencies (define test-intermediate-b-dependencies
"{ "{
\"dependencies\": [ \"dependencies\": [
{ {
\"crate_id\": \"leaf-bob\", \"crate_id\": \"leaf-bob\",
\"kind\": \"normal\" \"kind\": \"normal\",
\"req\": \"3.0.1\"
} }
] ]
}") }")
@ -179,19 +254,26 @@
(define test-leaf-alice-crate (define test-leaf-alice-crate
"{ "{
\"crate\": { \"crate\": {
\"max_version\": \"1.0.0\", \"max_version\": \"0.7.5\",
\"name\": \"leaf-alice\", \"name\": \"leaf-alice\",
\"description\": \"summary\", \"description\": \"summary\",
\"homepage\": \"http://example.com\", \"homepage\": \"http://example.com\",
\"repository\": \"http://example.com\", \"repository\": \"http://example.com\",
\"keywords\": [\"dummy\" \"test\"], \"keywords\": [\"dummy\", \"test\"],
\"categories\": [\"test\"] \"categories\": [\"test\"],
\"actual_versions\": [ \"actual_versions\": [
{ \"id\": \"leaf-alice\", { \"id\": 234270,
\"num\": \"1.0.0\", \"num\": \"0.7.3\",
\"license\": \"MIT OR Apache-2.0\", \"license\": \"MIT OR Apache-2.0\",
\"links\": { \"links\": {
\"dependencies\": \"/api/v1/crates/leaf-alice/1.0.0/dependencies\" \"dependencies\": \"/api/v1/crates/leaf-alice/0.7.3/dependencies\"
}
},
{ \"id\": 234272,
\"num\": \"0.7.5\",
\"license\": \"MIT OR Apache-2.0\",
\"links\": {
\"dependencies\": \"/api/v1/crates/leaf-alice/0.7.5/dependencies\"
} }
} }
] ]
@ -206,19 +288,19 @@
(define test-leaf-bob-crate (define test-leaf-bob-crate
"{ "{
\"crate\": { \"crate\": {
\"max_version\": \"1.0.0\", \"max_version\": \"3.0.1\",
\"name\": \"leaf-bob\", \"name\": \"leaf-bob\",
\"description\": \"summary\", \"description\": \"summary\",
\"homepage\": \"http://example.com\", \"homepage\": \"http://example.com\",
\"repository\": \"http://example.com\", \"repository\": \"http://example.com\",
\"keywords\": [\"dummy\" \"test\"], \"keywords\": [\"dummy\", \"test\"],
\"categories\": [\"test\"] \"categories\": [\"test\"]
\"actual_versions\": [ \"actual_versions\": [
{ \"id\": \"leaf-bob\", { \"id\": 234280,
\"num\": \"1.0.0\", \"num\": \"3.0.1\",
\"license\": \"MIT OR Apache-2.0\", \"license\": \"MIT OR Apache-2.0\",
\"links\": { \"links\": {
\"dependencies\": \"/api/v1/crates/leaf-bob/1.0.0/dependencies\" \"dependencies\": \"/api/v1/crates/leaf-bob/3.0.1/dependencies\"
} }
} }
] ]
@ -251,36 +333,51 @@
(match url (match url
("https://crates.io/api/v1/crates/foo" ("https://crates.io/api/v1/crates/foo"
(open-input-string test-foo-crate)) (open-input-string test-foo-crate))
("https://crates.io/api/v1/crates/foo/1.0.0/download" ("https://crates.io/api/v1/crates/foo/1.0.3/download"
(set! test-source-hash (set! test-source-hash
(bytevector->nix-base32-string (bytevector->nix-base32-string
(sha256 (string->bytevector "empty file\n" "utf-8")))) (sha256 (string->bytevector "empty file\n" "utf-8"))))
(open-input-string "empty file\n")) (open-input-string "empty file\n"))
("https://crates.io/api/v1/crates/foo/1.0.0/dependencies" ("https://crates.io/api/v1/crates/foo/1.0.3/dependencies"
(open-input-string test-foo-dependencies)) (open-input-string test-foo-dependencies))
("https://crates.io/api/v1/crates/leaf-alice"
(open-input-string test-leaf-alice-crate))
("https://crates.io/api/v1/crates/leaf-alice/0.7.5/download"
(set! test-source-hash
(bytevector->nix-base32-string
(sha256 (string->bytevector "empty file\n" "utf-8"))))
(open-input-string "empty file\n"))
("https://crates.io/api/v1/crates/leaf-alice/0.7.5/dependencies"
(open-input-string test-leaf-alice-dependencies))
(_ (error "Unexpected URL: " url))))) (_ (error "Unexpected URL: " url)))))
(match (crate->guix-package "foo")
(('package (match (crate->guix-package "foo")
('name "rust-foo") ((define-public 'rust-foo-1.0.3
('version "1.0.0") (package (name "rust-foo")
('source ('origin (version "1.0.3")
('method 'url-fetch) (source
('uri ('crate-uri "foo" 'version)) (origin
('file-name ('string-append 'name "-" 'version ".tar.gz")) (method url-fetch)
('sha256 (uri (crate-uri "foo" 'version))
('base32 (file-name (string-append name "-" version ".tar.gz"))
(? string? hash))))) (sha256
('build-system 'cargo-build-system) (base32
('arguments (? string? hash)))))
('quasiquote (build-system 'cargo-build-system)
('#:cargo-inputs (("rust-bar" ('unquote rust-bar)))))) (arguments
('home-page "http://example.com") ('quasiquote
('synopsis "summary") (#:skip-build? #t
('description "summary") #:cargo-inputs
('license ('list 'license:expat 'license:asl2.0))) (("rust-leaf-alice"
(string=? test-source-hash hash)) ('unquote 'rust-leaf-alice-0.7.5))))))
(x (home-page "http://example.com")
(pk 'fail x #f))))) (synopsis "summary")
(description "summary")
(license (list license:expat license:asl2.0))))
(string=? test-source-hash hash))
(x
(pk 'fail x #f)))))
(test-assert "cargo-recursive-import" (test-assert "cargo-recursive-import"
;; Replace network resources with sample data. ;; Replace network resources with sample data.
@ -289,151 +386,170 @@
(match url (match url
("https://crates.io/api/v1/crates/root" ("https://crates.io/api/v1/crates/root"
(open-input-string test-root-crate)) (open-input-string test-root-crate))
("https://crates.io/api/v1/crates/root/1.0.0/download" ("https://crates.io/api/v1/crates/root/1.0.4/download"
(set! test-source-hash (set! test-source-hash
(bytevector->nix-base32-string (bytevector->nix-base32-string
(sha256 (string->bytevector "empty file\n" "utf-8")))) (sha256 (string->bytevector "empty file\n" "utf-8"))))
(open-input-string "empty file\n")) (open-input-string "empty file\n"))
("https://crates.io/api/v1/crates/root/1.0.0/dependencies" ("https://crates.io/api/v1/crates/root/1.0.4/dependencies"
(open-input-string test-root-dependencies)) (open-input-string test-root-dependencies))
("https://crates.io/api/v1/crates/intermediate-1" ("https://crates.io/api/v1/crates/intermediate-a"
(open-input-string test-intermediate-1-crate)) (open-input-string test-intermediate-a-crate))
("https://crates.io/api/v1/crates/intermediate-1/1.0.0/download" ("https://crates.io/api/v1/crates/intermediate-a/1.0.42/download"
(set! test-source-hash (set! test-source-hash
(bytevector->nix-base32-string (bytevector->nix-base32-string
(sha256 (string->bytevector "empty file\n" "utf-8")))) (sha256 (string->bytevector "empty file\n" "utf-8"))))
(open-input-string "empty file\n")) (open-input-string "empty file\n"))
("https://crates.io/api/v1/crates/intermediate-1/1.0.0/dependencies" ("https://crates.io/api/v1/crates/intermediate-a/1.0.42/dependencies"
(open-input-string test-intermediate-1-dependencies)) (open-input-string test-intermediate-a-dependencies))
("https://crates.io/api/v1/crates/intermediate-2" ("https://crates.io/api/v1/crates/intermediate-b"
(open-input-string test-intermediate-2-crate)) (open-input-string test-intermediate-b-crate))
("https://crates.io/api/v1/crates/intermediate-2/1.0.0/download" ("https://crates.io/api/v1/crates/intermediate-b/1.2.3/download"
(set! test-source-hash (set! test-source-hash
(bytevector->nix-base32-string (bytevector->nix-base32-string
(sha256 (string->bytevector "empty file\n" "utf-8")))) (sha256 (string->bytevector "empty file\n" "utf-8"))))
(open-input-string "empty file\n")) (open-input-string "empty file\n"))
("https://crates.io/api/v1/crates/intermediate-2/1.0.0/dependencies" ("https://crates.io/api/v1/crates/intermediate-b/1.2.3/dependencies"
(open-input-string test-intermediate-2-dependencies)) (open-input-string test-intermediate-b-dependencies))
("https://crates.io/api/v1/crates/leaf-alice" ("https://crates.io/api/v1/crates/leaf-alice"
(open-input-string test-leaf-alice-crate)) (open-input-string test-leaf-alice-crate))
("https://crates.io/api/v1/crates/leaf-alice/1.0.0/download" ("https://crates.io/api/v1/crates/leaf-alice/0.7.5/download"
(set! test-source-hash (set! test-source-hash
(bytevector->nix-base32-string (bytevector->nix-base32-string
(sha256 (string->bytevector "empty file\n" "utf-8")))) (sha256 (string->bytevector "empty file\n" "utf-8"))))
(open-input-string "empty file\n")) (open-input-string "empty file\n"))
("https://crates.io/api/v1/crates/leaf-alice/1.0.0/dependencies" ("https://crates.io/api/v1/crates/leaf-alice/0.7.5/dependencies"
(open-input-string test-leaf-alice-dependencies)) (open-input-string test-leaf-alice-dependencies))
("https://crates.io/api/v1/crates/leaf-bob" ("https://crates.io/api/v1/crates/leaf-bob"
(open-input-string test-leaf-bob-crate)) (open-input-string test-leaf-bob-crate))
("https://crates.io/api/v1/crates/leaf-bob/1.0.0/download" ("https://crates.io/api/v1/crates/leaf-bob/3.0.1/download"
(set! test-source-hash (set! test-source-hash
(bytevector->nix-base32-string (bytevector->nix-base32-string
(sha256 (string->bytevector "empty file\n" "utf-8")))) (sha256 (string->bytevector "empty file\n" "utf-8"))))
(open-input-string "empty file\n")) (open-input-string "empty file\n"))
("https://crates.io/api/v1/crates/leaf-bob/1.0.0/dependencies" ("https://crates.io/api/v1/crates/leaf-bob/3.0.1/dependencies"
(open-input-string test-leaf-bob-dependencies)) (open-input-string test-leaf-bob-dependencies))
(_ (error "Unexpected URL: " url))))) (_ (error "Unexpected URL: " url)))))
(match (crate-recursive-import "root") (match (crate-recursive-import "root")
;; rust-intermediate-2 has no dependency on the rust-leaf-alice package, so this is a valid ordering ;; rust-intermediate-b has no dependency on the rust-leaf-alice
((('package ;; package, so this is a valid ordering
('name "rust-leaf-alice") (((define-public 'rust-leaf-alice-0.7.5
('version (? string? ver)) (package
('source (name "rust-leaf-alice")
('origin (version "0.7.5")
('method 'url-fetch) (source
('uri ('crate-uri "leaf-alice" 'version)) (origin
('file-name (method url-fetch)
('string-append 'name "-" 'version ".tar.gz")) (uri (crate-uri "leaf-alice" version))
('sha256 (file-name
('base32 (string-append name "-" version ".tar.gz"))
(? string? hash))))) (sha256
('build-system 'cargo-build-system) (base32
('home-page "http://example.com") (? string? hash)))))
('synopsis "summary") (build-system cargo-build-system)
('description "summary") (arguments ('quasiquote (#:skip-build? #t)))
('license ('list 'license:expat 'license:asl2.0))) (home-page "http://example.com")
('package (synopsis "summary")
('name "rust-leaf-bob") (description "summary")
('version (? string? ver)) (license (list license:expat license:asl2.0))))
('source (define-public 'rust-leaf-bob-3.0.1
('origin (package
('method 'url-fetch) (name "rust-leaf-bob")
('uri ('crate-uri "leaf-bob" 'version)) (version "3.0.1")
('file-name (source
('string-append 'name "-" 'version ".tar.gz")) (origin
('sha256 (method url-fetch)
('base32 (uri (crate-uri "leaf-bob" version))
(? string? hash))))) (file-name
('build-system 'cargo-build-system) (string-append name "-" version ".tar.gz"))
('home-page "http://example.com") (sha256
('synopsis "summary") (base32
('description "summary") (? string? hash)))))
('license ('list 'license:expat 'license:asl2.0))) (build-system cargo-build-system)
('package (arguments ('quasiquote (#:skip-build? #t)))
('name "rust-intermediate-2") (home-page "http://example.com")
('version (? string? ver)) (synopsis "summary")
('source (description "summary")
('origin (license (list license:expat license:asl2.0))))
('method 'url-fetch) (define-public 'rust-intermediate-b-1.2.3
('uri ('crate-uri "intermediate-2" 'version)) (package
('file-name (name "rust-intermediate-b")
('string-append 'name "-" 'version ".tar.gz")) (version "1.2.3")
('sha256 (source
('base32 (origin
(? string? hash))))) (method url-fetch)
('build-system 'cargo-build-system) (uri (crate-uri "intermediate-b" version))
('arguments (file-name
('quasiquote (string-append name "-" version ".tar.gz"))
('#:cargo-inputs (("rust-leaf-bob" ('unquote rust-leaf-bob)))))) (sha256
('home-page "http://example.com") (base32
('synopsis "summary") (? string? hash)))))
('description "summary") (build-system cargo-build-system)
('license ('list 'license:expat 'license:asl2.0))) (arguments
('package ('quasiquote (#:skip-build? #t
('name "rust-intermediate-1") #:cargo-inputs
('version (? string? ver)) (("rust-leaf-bob"
('source ('unquote 'rust-leaf-bob-3.0.1))))))
('origin (home-page "http://example.com")
('method 'url-fetch) (synopsis "summary")
('uri ('crate-uri "intermediate-1" 'version)) (description "summary")
('file-name (license (list license:expat license:asl2.0))))
('string-append 'name "-" 'version ".tar.gz")) (define-public 'rust-intermediate-a-1.0.42
('sha256 (package
('base32 (name "rust-intermediate-a")
(? string? hash))))) (version "1.0.42")
('build-system 'cargo-build-system) (source
('arguments (origin
('quasiquote (method url-fetch)
('#:cargo-inputs (("rust-intermediate-2" ('unquote rust-intermediate-2)) (uri (crate-uri "intermediate-a" version))
("rust-leaf-alice" ('unquote rust-leaf-alice)) (file-name
("rust-leaf-bob" ('unquote rust-leaf-bob)))))) (string-append name "-" version ".tar.gz"))
('home-page "http://example.com") (sha256
('synopsis "summary") (base32
('description "summary") (? string? hash)))))
('license ('list 'license:expat 'license:asl2.0))) (build-system cargo-build-system)
('package (arguments
('name "rust-root") ('quasiquote (#:skip-build? #t
('version (? string? ver)) #:cargo-inputs
('source (("rust-intermediate-b"
('origin ('unquote 'rust-intermediate-b-1.2.3))
('method 'url-fetch) ("rust-leaf-alice"
('uri ('crate-uri "root" 'version)) ('unquote 'rust-leaf-alice-0.7.5))
('file-name ("rust-leaf-bob"
('string-append 'name "-" 'version ".tar.gz")) ('unquote 'rust-leaf-bob-3.0.1))))))
('sha256 (home-page "http://example.com")
('base32 (synopsis "summary")
(? string? hash))))) (description "summary")
('build-system 'cargo-build-system) (license (list license:expat license:asl2.0))))
('arguments (define-public 'rust-root-1.0.4
('quasiquote (package
('#:cargo-inputs (("rust-intermediate-1" ('unquote rust-intermediate-1)) (name "rust-root")
("rust-intermediate-2" ('unquote rust-intermediate-2)) (version "1.0.4")
("rust-leaf-alice" ('unquote rust-leaf-alice)) (source
("rust-leaf-bob" ('unquote rust-leaf-bob)))))) (origin
('home-page "http://example.com") (method url-fetch)
('synopsis "summary") (uri (crate-uri "root" version))
('description "summary") (file-name
('license ('list 'license:expat 'license:asl2.0)))) (string-append name "-" version ".tar.gz"))
(sha256
(base32
(? string? hash)))))
(build-system cargo-build-system)
(arguments
('quasiquote (#:skip-build? #t
#:cargo-inputs
(("rust-intermediate-a"
('unquote 'rust-intermediate-a-1.0.42))
("rust-intermediate-b"
('unquote 'rust-intermediate-b-1.2.3))
("rust-leaf-alice"
('unquote 'rust-leaf-alice-0.7.5))
("rust-leaf-bob"
('unquote 'rust-leaf-bob-3.0.1))))))
(home-page "http://example.com")
(synopsis "summary")
(description "summary")
(license (list license:expat license:asl2.0)))))
#t) #t)
(x (x
(pk 'fail x #f))))) (pk 'fail x #f)))))