summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2020-05-19 15:55:08 +0200
committerLudovic Courtès <ludo@gnu.org>2020-05-22 01:29:39 +0200
commitce0be5675b702b2ff89aed1772ebb42af4150243 (patch)
treeec275112c97e9450ed9c4a8d30e7c153a7c10786 /tests
parent56f7ca6e7c8b5eadeee48b00bcbd78f9fa9e5f43 (diff)
packages: Introduce <content-hash> and use it in <origin>.
* guix/packages.scm (<content-hash>): New record type. (define-content-hash-constructor, build-content-hash) (content-hash): New macros. (print-content-hash): New procedure. (<origin>): Rename constructor to '%origin'. [sha256]: Remove field. [hash]: New field. Adjust users. (origin-compatibility-helper, origin): New macros. (origin-sha256): New deprecated procedure. (origin->derivation): Adjust accordingly. * tests/packages.scm ("package-source-derivation, origin, sha512"): New test. * guix/tests.scm: Hide (gcrypt hash) 'sha256' for proper syntax matching. * tests/challenge.scm: Add #:prefix for (gcrypt hash) and adjust users. * tests/derivations.scm: Likewise. * tests/store.scm: Likewise. * tests/graph.scm ("bag DAG, including origins"): Provide 'sha256' field with the right length. * gnu/packages/aspell.scm (aspell-dictionary) (aspell-dict-ca, aspell-dict-it): Use 'hash' and 'content-hash' for proper syntax matching. * gnu/packages/bash.scm (bash-patch): Rename 'sha256' to 'sha256-bv'. * gnu/packages/bootstrap.scm (bootstrap-executable): Rename 'sha256' to 'bv'. * gnu/packages/readline.scm (readline-patch): Likewise. * gnu/packages/virtualization.scm (qemu-patch): Rename 'sha256' to 'sha256-bv'. * guix/import/utils.scm: Hide (gcrypt hash) 'sha256'.
Diffstat (limited to 'tests')
-rw-r--r--tests/challenge.scm6
-rw-r--r--tests/derivations.scm32
-rw-r--r--tests/graph.scm6
-rw-r--r--tests/packages.scm28
-rw-r--r--tests/store.scm8
5 files changed, 55 insertions, 25 deletions
diff --git a/tests/challenge.scm b/tests/challenge.scm
index bb5633a3ebe..9c6d6e0d58f 100644
--- a/tests/challenge.scm
+++ b/tests/challenge.scm
@@ -1,5 +1,5 @@
1;;; GNU Guix --- Functional package management for GNU 1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2015, 2017, 2019 Ludovic Courtès <ludo@gnu.org> 2;;; Copyright © 2015, 2017, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
3;;; 3;;;
4;;; This file is part of GNU Guix. 4;;; This file is part of GNU Guix.
5;;; 5;;;
@@ -19,7 +19,7 @@
19(define-module (test-challenge) 19(define-module (test-challenge)
20 #:use-module (guix tests) 20 #:use-module (guix tests)
21 #:use-module (guix tests http) 21 #:use-module (guix tests http)
22 #:use-module (gcrypt hash) 22 #:use-module ((gcrypt hash) #:prefix gcrypt:)
23 #:use-module (guix store) 23 #:use-module (guix store)
24 #:use-module (guix monads) 24 #:use-module (guix monads)
25 #:use-module (guix derivations) 25 #:use-module (guix derivations)
@@ -135,7 +135,7 @@
135 (mlet* %store-monad ((drv (gexp->derivation "something" 135 (mlet* %store-monad ((drv (gexp->derivation "something"
136 #~(list #$output #$text))) 136 #~(list #$output #$text)))
137 (out -> (derivation->output-path drv)) 137 (out -> (derivation->output-path drv))
138 (hash -> (sha256 #vu8()))) 138 (hash -> (gcrypt:sha256 #vu8())))
139 (with-derivation-narinfo* drv (sha256 => hash) 139 (with-derivation-narinfo* drv (sha256 => hash)
140 (>>= (compare-contents (list out) (%test-substitute-urls)) 140 (>>= (compare-contents (list out) (%test-substitute-urls))
141 (match-lambda 141 (match-lambda
diff --git a/tests/derivations.scm b/tests/derivations.scm
index a409fa99f0d..9f1104a8879 100644
--- a/tests/derivations.scm
+++ b/tests/derivations.scm
@@ -23,7 +23,7 @@
23 #:use-module (guix grafts) 23 #:use-module (guix grafts)
24 #:use-module (guix store) 24 #:use-module (guix store)
25 #:use-module (guix utils) 25 #:use-module (guix utils)
26 #:use-module (gcrypt hash) 26 #:use-module ((gcrypt hash) #:prefix gcrypt:)
27 #:use-module (guix base32) 27 #:use-module (guix base32)
28 #:use-module (guix tests) 28 #:use-module (guix tests)
29 #:use-module (guix tests http) 29 #:use-module (guix tests http)
@@ -215,7 +215,7 @@
215 #:env-vars `(("url" 215 #:env-vars `(("url"
216 . ,(object->string (%local-url)))) 216 . ,(object->string (%local-url))))
217 #:hash-algo 'sha256 217 #:hash-algo 'sha256
218 #:hash (sha256 (string->utf8 text))))) 218 #:hash (gcrypt:sha256 (string->utf8 text)))))
219 (and (build-derivations %store (list drv)) 219 (and (build-derivations %store (list drv))
220 (string=? (call-with-input-file (derivation->output-path drv) 220 (string=? (call-with-input-file (derivation->output-path drv)
221 get-string-all) 221 get-string-all)
@@ -230,7 +230,7 @@
230 #:env-vars `(("url" 230 #:env-vars `(("url"
231 . ,(object->string (%local-url)))) 231 . ,(object->string (%local-url))))
232 #:hash-algo 'sha256 232 #:hash-algo 'sha256
233 #:hash (sha256 (random-bytevector 100))))) ;wrong 233 #:hash (gcrypt:sha256 (random-bytevector 100))))) ;wrong
234 (guard (c ((store-protocol-error? c) 234 (guard (c ((store-protocol-error? c)
235 (string-contains (store-protocol-error-message c) "failed"))) 235 (string-contains (store-protocol-error-message c) "failed")))
236 (build-derivations %store (list drv)) 236 (build-derivations %store (list drv))
@@ -245,7 +245,7 @@
245 #:env-vars `(("url" 245 #:env-vars `(("url"
246 . ,(object->string (%local-url)))) 246 . ,(object->string (%local-url))))
247 #:hash-algo 'sha256 247 #:hash-algo 'sha256
248 #:hash (sha256 (random-bytevector 100))))) 248 #:hash (gcrypt:sha256 (random-bytevector 100)))))
249 (guard (c ((store-protocol-error? c) 249 (guard (c ((store-protocol-error? c)
250 (string-contains (store-protocol-error-message (pk c)) "failed"))) 250 (string-contains (store-protocol-error-message (pk c)) "failed")))
251 (build-derivations %store (list drv)) 251 (build-derivations %store (list drv))
@@ -273,7 +273,7 @@
273 #:env-vars `(("url" 273 #:env-vars `(("url"
274 . ,(object->string (%local-url)))) 274 . ,(object->string (%local-url))))
275 #:hash-algo 'sha256 275 #:hash-algo 'sha256
276 #:hash (sha256 (string->utf8 text))))) 276 #:hash (gcrypt:sha256 (string->utf8 text)))))
277 (and (with-http-server `((200 ,text)) 277 (and (with-http-server `((200 ,text))
278 (build-derivations %store (list drv))) 278 (build-derivations %store (list drv)))
279 (with-http-server `((200 ,text)) 279 (with-http-server `((200 ,text))
@@ -317,7 +317,7 @@
317(test-assert "fixed-output-derivation?" 317(test-assert "fixed-output-derivation?"
318 (let* ((builder (add-text-to-store %store "my-fixed-builder.sh" 318 (let* ((builder (add-text-to-store %store "my-fixed-builder.sh"
319 "echo -n hello > $out" '())) 319 "echo -n hello > $out" '()))
320 (hash (sha256 (string->utf8 "hello"))) 320 (hash (gcrypt:sha256 (string->utf8 "hello")))
321 (drv (derivation %store "fixed" 321 (drv (derivation %store "fixed"
322 %bash `(,builder) 322 %bash `(,builder)
323 #:sources (list builder) 323 #:sources (list builder)
@@ -329,10 +329,10 @@
329 (map (lambda (hash-algorithm) 329 (map (lambda (hash-algorithm)
330 (let* ((builder (add-text-to-store %store "my-fixed-builder.sh" 330 (let* ((builder (add-text-to-store %store "my-fixed-builder.sh"
331 "echo -n hello > $out" '())) 331 "echo -n hello > $out" '()))
332 (sha256 (sha256 (string->utf8 "hello"))) 332 (sha256 (gcrypt:sha256 (string->utf8 "hello")))
333 (hash (bytevector-hash 333 (hash (gcrypt:bytevector-hash
334 (string->utf8 "hello") 334 (string->utf8 "hello")
335 (lookup-hash-algorithm hash-algorithm))) 335 (gcrypt:lookup-hash-algorithm hash-algorithm)))
336 (drv (derivation %store 336 (drv (derivation %store
337 (string-append 337 (string-append
338 "fixed-" (symbol->string hash-algorithm)) 338 "fixed-" (symbol->string hash-algorithm))
@@ -353,7 +353,7 @@
353 "echo -n hello > $out" '())) 353 "echo -n hello > $out" '()))
354 (builder2 (add-text-to-store %store "fixed-builder2.sh" 354 (builder2 (add-text-to-store %store "fixed-builder2.sh"
355 "echo hey; echo -n hello > $out" '())) 355 "echo hey; echo -n hello > $out" '()))
356 (hash (sha256 (string->utf8 "hello"))) 356 (hash (gcrypt:sha256 (string->utf8 "hello")))
357 (drv1 (derivation %store "fixed" 357 (drv1 (derivation %store "fixed"
358 %bash `(,builder1) 358 %bash `(,builder1)
359 #:hash hash #:hash-algo 'sha256)) 359 #:hash hash #:hash-algo 'sha256))
@@ -368,7 +368,7 @@
368(test-assert "fixed-output derivation, recursive" 368(test-assert "fixed-output derivation, recursive"
369 (let* ((builder (add-text-to-store %store "my-fixed-builder.sh" 369 (let* ((builder (add-text-to-store %store "my-fixed-builder.sh"
370 "echo -n hello > $out" '())) 370 "echo -n hello > $out" '()))
371 (hash (sha256 (string->utf8 "hello"))) 371 (hash (gcrypt:sha256 (string->utf8 "hello")))
372 (drv (derivation %store "fixed-rec" 372 (drv (derivation %store "fixed-rec"
373 %bash `(,builder) 373 %bash `(,builder)
374 #:sources (list builder) 374 #:sources (list builder)
@@ -390,7 +390,7 @@
390 "echo -n hello > $out" '())) 390 "echo -n hello > $out" '()))
391 (builder2 (add-text-to-store %store "fixed-builder2.sh" 391 (builder2 (add-text-to-store %store "fixed-builder2.sh"
392 "echo hey; echo -n hello > $out" '())) 392 "echo hey; echo -n hello > $out" '()))
393 (hash (sha256 (string->utf8 "hello"))) 393 (hash (gcrypt:sha256 (string->utf8 "hello")))
394 (fixed1 (derivation %store "fixed" 394 (fixed1 (derivation %store "fixed"
395 %bash `(,builder1) 395 %bash `(,builder1)
396 #:hash hash #:hash-algo 'sha256)) 396 #:hash hash #:hash-algo 'sha256))
@@ -427,7 +427,7 @@
427 "echo -n hello > $out" '())) 427 "echo -n hello > $out" '()))
428 (builder2 (add-text-to-store %store "fixed-builder2.sh" 428 (builder2 (add-text-to-store %store "fixed-builder2.sh"
429 "echo hey; echo -n hello > $out" '())) 429 "echo hey; echo -n hello > $out" '()))
430 (hash (sha256 (string->utf8 "hello"))) 430 (hash (gcrypt:sha256 (string->utf8 "hello")))
431 (fixed1 (derivation %store "fixed" 431 (fixed1 (derivation %store "fixed"
432 %bash `(,builder1) 432 %bash `(,builder1)
433 #:hash hash #:hash-algo 'sha256)) 433 #:hash hash #:hash-algo 'sha256))
@@ -680,7 +680,7 @@
680 (let* ((value (getenv "GUIX_STATE_DIRECTORY")) 680 (let* ((value (getenv "GUIX_STATE_DIRECTORY"))
681 (drv (derivation %store "leaked-env-vars" %bash 681 (drv (derivation %store "leaked-env-vars" %bash
682 '("-c" "echo -n $GUIX_STATE_DIRECTORY > $out") 682 '("-c" "echo -n $GUIX_STATE_DIRECTORY > $out")
683 #:hash (sha256 (string->utf8 value)) 683 #:hash (gcrypt:sha256 (string->utf8 value))
684 #:hash-algo 'sha256 684 #:hash-algo 'sha256
685 #:sources (list %bash) 685 #:sources (list %bash)
686 #:leaked-env-vars '("GUIX_STATE_DIRECTORY")))) 686 #:leaked-env-vars '("GUIX_STATE_DIRECTORY"))))
@@ -1106,7 +1106,7 @@
1106 (builder2 '(call-with-output-file (pk 'difference-here! %output) 1106 (builder2 '(call-with-output-file (pk 'difference-here! %output)
1107 (lambda (p) 1107 (lambda (p)
1108 (write "hello" p)))) 1108 (write "hello" p))))
1109 (hash (sha256 (string->utf8 "hello"))) 1109 (hash (gcrypt:sha256 (string->utf8 "hello")))
1110 (input1 (build-expression->derivation %store "fixed" builder1 1110 (input1 (build-expression->derivation %store "fixed" builder1
1111 #:hash hash 1111 #:hash hash
1112 #:hash-algo 'sha256)) 1112 #:hash-algo 'sha256))
@@ -1127,7 +1127,7 @@
1127 (builder2 '(call-with-output-file (pk 'difference-here! %output) 1127 (builder2 '(call-with-output-file (pk 'difference-here! %output)
1128 (lambda (p) 1128 (lambda (p)
1129 (write "hello" p)))) 1129 (write "hello" p))))
1130 (hash (sha256 (string->utf8 "hello"))) 1130 (hash (gcrypt:sha256 (string->utf8 "hello")))
1131 (input1 (build-expression->derivation %store "fixed" builder1 1131 (input1 (build-expression->derivation %store "fixed" builder1
1132 #:hash hash 1132 #:hash hash
1133 #:hash-algo 'sha256)) 1133 #:hash-algo 'sha256))
diff --git a/tests/graph.scm b/tests/graph.scm
index 136260c7d10..0663d13b493 100644
--- a/tests/graph.scm
+++ b/tests/graph.scm
@@ -162,7 +162,11 @@ edges."
162 (let-values (((backend nodes+edges) (make-recording-backend))) 162 (let-values (((backend nodes+edges) (make-recording-backend)))
163 (let* ((m (lambda* (uri hash-type hash name #:key system) 163 (let* ((m (lambda* (uri hash-type hash name #:key system)
164 (text-file "foo-1.2.3.tar.gz" "This is a fake!"))) 164 (text-file "foo-1.2.3.tar.gz" "This is a fake!")))
165 (o (origin (method m) (uri "the-uri") (sha256 #vu8(0 1 2)))) 165 (o (origin
166 (method m) (uri "the-uri")
167 (sha256
168 (base32
169 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))))
166 (p (dummy-package "p" (source o)))) 170 (p (dummy-package "p" (source o))))
167 (run-with-store %store 171 (run-with-store %store
168 (export-graph (list p) 'port 172 (export-graph (list p) 'port
diff --git a/tests/packages.scm b/tests/packages.scm
index c528d2080c9..4935d4503e6 100644
--- a/tests/packages.scm
+++ b/tests/packages.scm
@@ -29,7 +29,7 @@
29 #:renamer (lambda (name) 29 #:renamer (lambda (name)
30 (cond ((eq? name 'location) 'make-location) 30 (cond ((eq? name 'location) 'make-location)
31 (else name)))) 31 (else name))))
32 #:use-module (gcrypt hash) 32 #:use-module ((gcrypt hash) #:hide (sha256))
33 #:use-module (guix derivations) 33 #:use-module (guix derivations)
34 #:use-module (guix packages) 34 #:use-module (guix packages)
35 #:use-module (guix grafts) 35 #:use-module (guix grafts)
@@ -51,6 +51,7 @@
51 #:use-module (srfi srfi-34) 51 #:use-module (srfi srfi-34)
52 #:use-module (srfi srfi-35) 52 #:use-module (srfi srfi-35)
53 #:use-module (srfi srfi-64) 53 #:use-module (srfi srfi-64)
54 #:use-module (rnrs bytevectors)
54 #:use-module (rnrs io ports) 55 #:use-module (rnrs io ports)
55 #:use-module (ice-9 vlist) 56 #:use-module (ice-9 vlist)
56 #:use-module (ice-9 regex) 57 #:use-module (ice-9 regex)
@@ -497,6 +498,31 @@
497 (search-path %load-path "guix/base32.scm") 498 (search-path %load-path "guix/base32.scm")
498 get-bytevector-all))))) 499 get-bytevector-all)))))
499 500
501(test-equal "package-source-derivation, origin, sha512"
502 "hello"
503 (let* ((bash (search-bootstrap-binary "bash" (%current-system)))
504 (builder (add-text-to-store %store "my-fixed-builder.sh"
505 "echo -n hello > $out" '()))
506 (method (lambda* (url hash-algo hash #:optional name
507 #:rest rest)
508 (and (eq? hash-algo 'sha512)
509 (raw-derivation name bash (list builder)
510 #:sources (list builder)
511 #:hash hash
512 #:hash-algo hash-algo))))
513 (source (origin
514 (method method)
515 (uri "unused://")
516 (file-name "origin-sha512")
517 (hash (content-hash
518 (bytevector-hash (string->utf8 "hello")
519 (hash-algorithm sha512))
520 sha512))))
521 (drv (package-source-derivation %store source))
522 (output (derivation->output-path drv)))
523 (build-derivations %store (list drv))
524 (call-with-input-file output get-string-all)))
525
500(unless (network-reachable?) (test-skip 1)) 526(unless (network-reachable?) (test-skip 1))
501(test-equal "package-source-derivation, snippet" 527(test-equal "package-source-derivation, snippet"
502 "OK" 528 "OK"
diff --git a/tests/store.scm b/tests/store.scm
index f007846dc16..06f79396579 100644
--- a/tests/store.scm
+++ b/tests/store.scm
@@ -22,7 +22,7 @@
22 #:use-module (guix store) 22 #:use-module (guix store)
23 #:use-module (guix utils) 23 #:use-module (guix utils)
24 #:use-module (guix monads) 24 #:use-module (guix monads)
25 #:use-module (gcrypt hash) 25 #:use-module ((gcrypt hash) #:prefix gcrypt:)
26 #:use-module (guix base32) 26 #:use-module (guix base32)
27 #:use-module (guix packages) 27 #:use-module (guix packages)
28 #:use-module (guix derivations) 28 #:use-module (guix derivations)
@@ -321,7 +321,7 @@
321 #:env-vars `(("t2" . ,t2)))) 321 #:env-vars `(("t2" . ,t2))))
322 (o (derivation->output-path d))) 322 (o (derivation->output-path d)))
323 (with-derivation-narinfo d 323 (with-derivation-narinfo d
324 (sha256 => (sha256 (string->utf8 t2))) 324 (sha256 => (gcrypt:sha256 (string->utf8 t2)))
325 (references => (list t2)) 325 (references => (list t2))
326 326
327 (equal? (references/substitutes s (list o t3 t2 t1)) 327 (equal? (references/substitutes s (list o t3 t2 t1))
@@ -940,7 +940,7 @@
940 (foldm %store-monad 940 (foldm %store-monad
941 (lambda (item result) 941 (lambda (item result)
942 (define ref-hash 942 (define ref-hash
943 (let-values (((port get) (open-sha256-port))) 943 (let-values (((port get) (gcrypt:open-sha256-port)))
944 (write-file item port) 944 (write-file item port)
945 (close-port port) 945 (close-port port)
946 (get))) 946 (get)))
@@ -1144,7 +1144,7 @@
1144 (info (query-path-info %store item))) 1144 (info (query-path-info %store item)))
1145 (and (equal? (path-info-references info) (list ref)) 1145 (and (equal? (path-info-references info) (list ref))
1146 (equal? (path-info-hash info) 1146 (equal? (path-info-hash info)
1147 (sha256 1147 (gcrypt:sha256
1148 (string->utf8 1148 (string->utf8
1149 (call-with-output-string (cut write-file item <>)))))))) 1149 (call-with-output-string (cut write-file item <>))))))))
1150 1150