1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014 David Thompson <davet@gnu.org>
3 ;;; Copyright © 2016 David Craven <david@craven.ch>
4 ;;; Copyright © 2019, 2020 Ludovic Courtès <ludo@gnu.org>
5 ;;; Copyright © 2020 Martin Becze <mjbecze@riseup.net>
7 ;;; This file is part of GNU Guix.
9 ;;; GNU Guix is free software; you can redistribute it and/or modify it
10 ;;; under the terms of the GNU General Public License as published by
11 ;;; the Free Software Foundation; either version 3 of the License, or (at
12 ;;; your option) any later version.
14 ;;; GNU Guix is distributed in the hope that it will be useful, but
15 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;;; GNU General Public License for more details.
19 ;;; You should have received a copy of the GNU General Public License
20 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
22 (define-module (test-crate)
23 #:use-module (guix import crate)
24 #:use-module (guix base32)
25 #:use-module (guix build-system cargo)
26 #:use-module (gcrypt hash)
27 #:use-module (guix tests)
28 #:use-module (ice-9 iconv)
29 #:use-module (ice-9 match)
30 #:use-module (srfi srfi-64))
33 ;; crate versions and dependencies used here
41 ;; intermediate-a 1.0.42
42 ;; intermeidate-b ^1.0.0
46 ;; intermediate-a-1.0.40
47 ;; intermediate-a-1.0.42
48 ;; intermediate-a-1.1.0-alpha.1
49 ;; intermediate-a 1.2.3
53 ;; intermediate-b-1.2.3
62 (define test-foo-crate
65 \"max_version\": \"1.0.3\",
67 \"description\": \"summary\",
68 \"homepage\": \"http://example.com\",
69 \"repository\": \"http://example.com\",
70 \"keywords\": [\"dummy\", \"test\"],
71 \"categories\": [\"test\"],
72 \"actual_versions\": [
75 \"license\": \"MIT OR Apache-2.0\",
77 \"dependencies\": \"/api/v1/crates/foo/0.8.1/dependencies\"
82 \"license\": \"MIT OR Apache-2.0\",
84 \"dependencies\": \"/api/v1/crates/foo/1.0.0/dependencies\"
89 \"license\": \"MIT OR Apache-2.0\",
91 \"dependencies\": \"/api/v1/crates/foo/1.0.3/dependencies\"
98 (define test-foo-dependencies
102 \"crate_id\": \"leaf-alice\",
103 \"kind\": \"normal\",
109 (define test-root-crate
112 \"max_version\": \"1.0.4\",
114 \"description\": \"summary\",
115 \"homepage\": \"http://example.com\",
116 \"repository\": \"http://example.com\",
117 \"keywords\": [\"dummy\", \"test\"],
118 \"categories\": [\"test\"],
119 \"actual_versions\": [
122 \"license\": \"MIT OR Apache-2.0\",
124 \"dependencies\": \"/api/v1/crates/root/1.0.0/dependencies\"
129 \"license\": \"MIT OR Apache-2.0\",
131 \"dependencies\": \"/api/v1/crates/root/1.0.4/dependencies\"
138 (define test-root-dependencies
142 \"crate_id\": \"intermediate-a\",
143 \"kind\": \"normal\",
147 \"crate_id\": \"intermediate-b\",
148 \"kind\": \"normal\",
152 \"crate_id\": \"leaf-alice\",
153 \"kind\": \"normal\",
157 \"crate_id\": \"leaf-bob\",
158 \"kind\": \"normal\",
164 (define test-intermediate-a-crate
167 \"max_version\": \"1.1.0-alpha.1\",
168 \"name\": \"intermediate-a\",
169 \"description\": \"summary\",
170 \"homepage\": \"http://example.com\",
171 \"repository\": \"http://example.com\",
172 \"keywords\": [\"dummy\", \"test\"],
173 \"categories\": [\"test\"],
174 \"actual_versions\": [
177 \"license\": \"MIT OR Apache-2.0\",
179 \"dependencies\": \"/api/v1/crates/intermediate-a/1.0.40/dependencies\"
184 \"license\": \"MIT OR Apache-2.0\",
186 \"dependencies\": \"/api/v1/crates/intermediate-a/1.0.42/dependencies\"
190 \"num\": \"1.1.0-alpha.1\",
191 \"license\": \"MIT OR Apache-2.0\",
193 \"dependencies\": \"/api/v1/crates/intermediate-a/1.1.0-alpha.1/dependencies\"
200 (define test-intermediate-a-dependencies
204 \"crate_id\": \"intermediate-b\",
205 \"kind\": \"normal\",
209 \"crate_id\": \"leaf-alice\",
210 \"kind\": \"normal\",
214 \"crate_id\": \"leaf-bob\",
215 \"kind\": \"normal\",
221 (define test-intermediate-b-crate
224 \"max_version\": \"1.2.3\",
225 \"name\": \"intermediate-b\",
226 \"description\": \"summary\",
227 \"homepage\": \"http://example.com\",
228 \"repository\": \"http://example.com\",
229 \"keywords\": [\"dummy\", \"test\"],
230 \"categories\": [\"test\"],
231 \"actual_versions\": [
234 \"license\": \"MIT OR Apache-2.0\",
236 \"dependencies\": \"/api/v1/crates/intermediate-b/1.2.3/dependencies\"
243 (define test-intermediate-b-dependencies
247 \"crate_id\": \"leaf-bob\",
248 \"kind\": \"normal\",
254 (define test-leaf-alice-crate
257 \"max_version\": \"0.7.5\",
258 \"name\": \"leaf-alice\",
259 \"description\": \"summary\",
260 \"homepage\": \"http://example.com\",
261 \"repository\": \"http://example.com\",
262 \"keywords\": [\"dummy\", \"test\"],
263 \"categories\": [\"test\"],
264 \"actual_versions\": [
267 \"license\": \"MIT OR Apache-2.0\",
269 \"dependencies\": \"/api/v1/crates/leaf-alice/0.7.3/dependencies\"
274 \"license\": \"MIT OR Apache-2.0\",
276 \"dependencies\": \"/api/v1/crates/leaf-alice/0.7.5/dependencies\"
283 (define test-leaf-alice-dependencies
288 (define test-leaf-bob-crate
291 \"max_version\": \"3.0.1\",
292 \"name\": \"leaf-bob\",
293 \"description\": \"summary\",
294 \"homepage\": \"http://example.com\",
295 \"repository\": \"http://example.com\",
296 \"keywords\": [\"dummy\", \"test\"],
297 \"categories\": [\"test\"]
298 \"actual_versions\": [
301 \"license\": \"MIT OR Apache-2.0\",
303 \"dependencies\": \"/api/v1/crates/leaf-bob/3.0.1/dependencies\"
310 (define test-leaf-bob-dependencies
315 (define test-source-hash
321 (test-equal "guix-package->crate-name"
323 (guix-package->crate-name
325 "rust-rustc-serialize"
326 (source (dummy-origin
327 (uri (crate-uri "rustc-serialize" "1.0")))))))
329 (test-assert "crate->guix-package"
330 ;; Replace network resources with sample data.
331 (mock ((guix http-client) http-fetch
334 ("https://crates.io/api/v1/crates/foo"
335 (open-input-string test-foo-crate))
336 ("https://crates.io/api/v1/crates/foo/1.0.3/download"
337 (set! test-source-hash
338 (bytevector->nix-base32-string
339 (sha256 (string->bytevector "empty file\n" "utf-8"))))
340 (open-input-string "empty file\n"))
341 ("https://crates.io/api/v1/crates/foo/1.0.3/dependencies"
342 (open-input-string test-foo-dependencies))
343 ("https://crates.io/api/v1/crates/leaf-alice"
344 (open-input-string test-leaf-alice-crate))
345 ("https://crates.io/api/v1/crates/leaf-alice/0.7.5/download"
346 (set! test-source-hash
347 (bytevector->nix-base32-string
348 (sha256 (string->bytevector "empty file\n" "utf-8"))))
349 (open-input-string "empty file\n"))
350 ("https://crates.io/api/v1/crates/leaf-alice/0.7.5/dependencies"
351 (open-input-string test-leaf-alice-dependencies))
352 (_ (error "Unexpected URL: " url)))))
354 (match (crate->guix-package "foo")
355 ((define-public 'rust-foo-1
356 (package (name "rust-foo")
361 (uri (crate-uri "foo" 'version))
362 (file-name (string-append name "-" version ".tar.gz"))
366 (build-system 'cargo-build-system)
371 (("rust-leaf-alice" ('unquote 'rust-leaf-alice-0.7))))))
372 (home-page "http://example.com")
374 (description "summary")
375 (license (list license:expat license:asl2.0))))
377 (string=? test-source-hash hash))
381 (test-assert "cargo-recursive-import"
382 ;; Replace network resources with sample data.
383 (mock ((guix http-client) http-fetch
386 ("https://crates.io/api/v1/crates/root"
387 (open-input-string test-root-crate))
388 ("https://crates.io/api/v1/crates/root/1.0.4/download"
389 (set! test-source-hash
390 (bytevector->nix-base32-string
391 (sha256 (string->bytevector "empty file\n" "utf-8"))))
392 (open-input-string "empty file\n"))
393 ("https://crates.io/api/v1/crates/root/1.0.4/dependencies"
394 (open-input-string test-root-dependencies))
395 ("https://crates.io/api/v1/crates/intermediate-a"
396 (open-input-string test-intermediate-a-crate))
397 ("https://crates.io/api/v1/crates/intermediate-a/1.0.42/download"
398 (set! test-source-hash
399 (bytevector->nix-base32-string
400 (sha256 (string->bytevector "empty file\n" "utf-8"))))
401 (open-input-string "empty file\n"))
402 ("https://crates.io/api/v1/crates/intermediate-a/1.0.42/dependencies"
403 (open-input-string test-intermediate-a-dependencies))
404 ("https://crates.io/api/v1/crates/intermediate-b"
405 (open-input-string test-intermediate-b-crate))
406 ("https://crates.io/api/v1/crates/intermediate-b/1.2.3/download"
407 (set! test-source-hash
408 (bytevector->nix-base32-string
409 (sha256 (string->bytevector "empty file\n" "utf-8"))))
410 (open-input-string "empty file\n"))
411 ("https://crates.io/api/v1/crates/intermediate-b/1.2.3/dependencies"
412 (open-input-string test-intermediate-b-dependencies))
413 ("https://crates.io/api/v1/crates/leaf-alice"
414 (open-input-string test-leaf-alice-crate))
415 ("https://crates.io/api/v1/crates/leaf-alice/0.7.5/download"
416 (set! test-source-hash
417 (bytevector->nix-base32-string
418 (sha256 (string->bytevector "empty file\n" "utf-8"))))
419 (open-input-string "empty file\n"))
420 ("https://crates.io/api/v1/crates/leaf-alice/0.7.5/dependencies"
421 (open-input-string test-leaf-alice-dependencies))
422 ("https://crates.io/api/v1/crates/leaf-bob"
423 (open-input-string test-leaf-bob-crate))
424 ("https://crates.io/api/v1/crates/leaf-bob/3.0.1/download"
425 (set! test-source-hash
426 (bytevector->nix-base32-string
427 (sha256 (string->bytevector "empty file\n" "utf-8"))))
428 (open-input-string "empty file\n"))
429 ("https://crates.io/api/v1/crates/leaf-bob/3.0.1/dependencies"
430 (open-input-string test-leaf-bob-dependencies))
431 (_ (error "Unexpected URL: " url)))))
432 (match (crate-recursive-import "root")
433 ;; rust-intermediate-b has no dependency on the rust-leaf-alice
434 ;; package, so this is a valid ordering
435 (((define-public 'rust-leaf-alice-0.7
437 (name "rust-leaf-alice")
442 (uri (crate-uri "leaf-alice" version))
444 (string-append name "-" version ".tar.gz"))
448 (build-system cargo-build-system)
449 (arguments ('quasiquote (#:skip-build? #t)))
450 (home-page "http://example.com")
452 (description "summary")
453 (license (list license:expat license:asl2.0))))
454 (define-public 'rust-leaf-bob-3
456 (name "rust-leaf-bob")
461 (uri (crate-uri "leaf-bob" version))
463 (string-append name "-" version ".tar.gz"))
467 (build-system cargo-build-system)
468 (arguments ('quasiquote (#:skip-build? #t)))
469 (home-page "http://example.com")
471 (description "summary")
472 (license (list license:expat license:asl2.0))))
473 (define-public 'rust-intermediate-b-1
475 (name "rust-intermediate-b")
480 (uri (crate-uri "intermediate-b" version))
482 (string-append name "-" version ".tar.gz"))
486 (build-system cargo-build-system)
488 ('quasiquote (#:skip-build? #t
491 ('unquote rust-leaf-bob-3))))))
492 (home-page "http://example.com")
494 (description "summary")
495 (license (list license:expat license:asl2.0))))
496 (define-public 'rust-intermediate-a-1
498 (name "rust-intermediate-a")
503 (uri (crate-uri "intermediate-a" version))
505 (string-append name "-" version ".tar.gz"))
509 (build-system cargo-build-system)
511 ('quasiquote (#:skip-build? #t
513 (("rust-intermediate-b"
514 ('unquote rust-intermediate-b-1))
516 ('unquote 'rust-leaf-alice-0.7))
518 ('unquote rust-leaf-bob-3))))))
519 (home-page "http://example.com")
521 (description "summary")
522 (license (list license:expat license:asl2.0))))
523 (define-public 'rust-root-1
530 (uri (crate-uri "root" version))
532 (string-append name "-" version ".tar.gz"))
536 (build-system cargo-build-system)
538 ('quasiquote (#:cargo-inputs
539 (("rust-intermediate-a"
540 ('unquote rust-intermediate-a-1))
541 ("rust-intermediate-b"
542 ('unquote rust-intermediate-b-1))
544 ('unquote 'rust-leaf-alice-0.7))
546 ('unquote rust-leaf-bob-3))))))
547 (home-page "http://example.com")
549 (description "summary")
550 (license (list license:expat license:asl2.0)))))
555 (test-equal "licenses: MIT OR Apache-2.0"
556 '(license:expat license:asl2.0)
557 (string->license "MIT OR Apache-2.0"))
559 (test-equal "licenses: Apache-2.0 / MIT"
560 '(license:asl2.0 license:expat)
561 (string->license "Apache-2.0 / MIT"))
563 (test-equal "licenses: Apache-2.0 WITH LLVM-exception"
564 '(license:asl2.0 unknown-license!)
565 (string->license "Apache-2.0 WITH LLVM-exception"))
567 (test-equal "licenses: MIT/Apache-2.0 AND BSD-2-Clause"
568 '(license:expat license:asl2.0 unknown-license!)
569 (string->license "MIT/Apache-2.0 AND BSD-2-Clause"))
571 (test-equal "licenses: MIT/Apache-2.0"
572 '(license:expat license:asl2.0)
573 (string->license "MIT/Apache-2.0"))