gnu: Add Guile-Lib.
[jackhill/guix/guix.git] / tests / derivations.scm
CommitLineData
233e7676
LC
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org>
341c6fdd 3;;;
233e7676 4;;; This file is part of GNU Guix.
341c6fdd 5;;;
233e7676 6;;; GNU Guix is free software; you can redistribute it and/or modify it
341c6fdd
LC
7;;; under the terms of the GNU General Public License as published by
8;;; the Free Software Foundation; either version 3 of the License, or (at
9;;; your option) any later version.
10;;;
233e7676 11;;; GNU Guix is distributed in the hope that it will be useful, but
341c6fdd
LC
12;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
233e7676 17;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
341c6fdd
LC
18
19
20(define-module (test-derivations)
21 #:use-module (guix derivations)
26bbbb95 22 #:use-module (guix store)
de4c3f26 23 #:use-module (guix utils)
72626a71 24 #:use-module (guix hash)
ddc29a78 25 #:use-module (guix base32)
b272c474 26 #:use-module ((guix packages) #:select (package-derivation))
59a43334 27 #:use-module ((gnu packages) #:select (search-bootstrap-binary))
1ffa7090 28 #:use-module (gnu packages bootstrap)
b37eb5ed 29 #:use-module (srfi srfi-1)
fb3eec83 30 #:use-module (srfi srfi-11)
341c6fdd 31 #:use-module (srfi srfi-26)
99634e3f 32 #:use-module (srfi srfi-34)
341c6fdd 33 #:use-module (srfi srfi-64)
fb3eec83 34 #:use-module (rnrs io ports)
749c6567 35 #:use-module (rnrs bytevectors)
dd36b51b 36 #:use-module (web uri)
b37eb5ed 37 #:use-module (ice-9 rdelim)
db393b33 38 #:use-module (ice-9 regex)
99634e3f
LC
39 #:use-module (ice-9 ftw)
40 #:use-module (ice-9 match))
341c6fdd 41
26bbbb95
LC
42(define %store
43 (false-if-exception (open-connection)))
44
b272c474 45(when %store
81dbd783
LC
46 ;; Make sure we build everything by ourselves.
47 (set-build-options %store #:use-substitutes? #f)
48
b272c474
LC
49 ;; By default, use %BOOTSTRAP-GUILE for the current system.
50 (let ((drv (package-derivation %store %bootstrap-guile)))
51 (%guile-for-build drv)))
52
97d3998e
LC
53(define %bash
54 (let ((bash (search-bootstrap-binary "bash" (%current-system))))
55 (and %store
a9ebd9ef 56 (add-to-store %store "bash" #t "sha256" bash))))
97d3998e 57
b37eb5ed
LC
58(define (directory-contents dir)
59 "Return an alist representing the contents of DIR."
60 (define prefix-len (string-length dir))
61 (sort (file-system-fold (const #t) ; enter?
62 (lambda (path stat result) ; leaf
63 (alist-cons (string-drop path prefix-len)
64 (call-with-input-file path
65 get-bytevector-all)
66 result))
67 (lambda (path stat result) result) ; down
68 (lambda (path stat result) result) ; up
69 (lambda (path stat result) result) ; skip
70 (lambda (path stat errno result) result) ; error
71 '()
72 dir)
73 (lambda (e1 e2)
74 (string<? (car e1) (car e2)))))
75
341c6fdd
LC
76(test-begin "derivations")
77
78(test-assert "parse & export"
33594aa4
LC
79 (let* ((f (search-path %load-path "tests/test.drv"))
80 (b1 (call-with-input-file f get-bytevector-all))
341c6fdd
LC
81 (d1 (read-derivation (open-bytevector-input-port b1)))
82 (b2 (call-with-bytevector-output-port (cut write-derivation d1 <>)))
83 (d2 (read-derivation (open-bytevector-input-port b2))))
84 (and (equal? b1 b2)
85 (equal? d1 d2))))
86
29833b26 87(test-skip (if %store 0 11))
b37eb5ed 88
d1b1c424
LC
89(test-assert "add-to-store, flat"
90 (let* ((file (search-path %load-path "language/tree-il/spec.scm"))
a9ebd9ef 91 (drv (add-to-store %store "flat-test" #f "sha256" file)))
d1b1c424 92 (and (eq? 'regular (stat:type (stat drv)))
31ef99a8 93 (valid-path? %store drv)
d1b1c424
LC
94 (equal? (call-with-input-file file get-bytevector-all)
95 (call-with-input-file drv get-bytevector-all)))))
96
b37eb5ed
LC
97(test-assert "add-to-store, recursive"
98 (let* ((dir (dirname (search-path %load-path "language/tree-il/spec.scm")))
a9ebd9ef 99 (drv (add-to-store %store "dir-tree-test" #t "sha256" dir)))
b37eb5ed 100 (and (eq? 'directory (stat:type (stat drv)))
31ef99a8 101 (valid-path? %store drv)
b37eb5ed
LC
102 (equal? (directory-contents dir)
103 (directory-contents drv)))))
26bbbb95
LC
104
105(test-assert "derivation with no inputs"
31ef99a8 106 (let* ((builder (add-text-to-store %store "my-builder.sh"
97d3998e 107 "echo hello, world\n"
31ef99a8 108 '()))
97d3998e
LC
109 (drv-path (derivation %store "foo" (%current-system)
110 %bash `("-e" ,builder)
111 '(("HOME" . "/homeless")) '())))
31ef99a8
LC
112 (and (store-path? drv-path)
113 (valid-path? %store drv-path))))
26bbbb95 114
fb3eec83
LC
115(test-assert "build derivation with 1 source"
116 (let*-values (((builder)
117 (add-text-to-store %store "my-builder.sh"
de4c3f26 118 "echo hello, world > \"$out\"\n"
fb3eec83
LC
119 '()))
120 ((drv-path drv)
98090557 121 (derivation %store "foo" (%current-system)
97d3998e 122 %bash `(,builder)
af7f9e5f
LC
123 '(("HOME" . "/homeless")
124 ("zzz" . "Z!")
125 ("AAA" . "A!"))
fb3eec83
LC
126 `((,builder))))
127 ((succeeded?)
128 (build-derivations %store (list drv-path))))
129 (and succeeded?
130 (let ((path (derivation-output-path
131 (assoc-ref (derivation-outputs drv) "out"))))
31ef99a8
LC
132 (and (valid-path? %store path)
133 (string=? (call-with-input-file path read-line)
134 "hello, world"))))))
fb3eec83 135
860a6f1a
LC
136(test-assert "derivation with local file as input"
137 (let* ((builder (add-text-to-store
138 %store "my-builder.sh"
bbb76f6f 139 "(while read line ; do echo \"$line\" ; done) < $in > $out"
860a6f1a
LC
140 '()))
141 (input (search-path %load-path "ice-9/boot-9.scm"))
142 (drv-path (derivation %store "derivation-with-input-file"
143 (%current-system)
97d3998e 144 %bash `(,builder)
860a6f1a
LC
145 `(("in"
146 ;; Cheat to pass the actual file
147 ;; name to the builder.
148 . ,(add-to-store %store
149 (basename input)
a9ebd9ef 150 #t "sha256"
860a6f1a
LC
151 input)))
152 `((,builder)
153 (,input))))) ; ← local file name
154 (and (build-derivations %store (list drv-path))
bbb76f6f
LC
155 ;; Note: we can't compare the files because the above trick alters
156 ;; the contents.
157 (valid-path? %store (derivation-path->output-path drv-path)))))
860a6f1a 158
749c6567
LC
159(test-assert "fixed-output derivation"
160 (let* ((builder (add-text-to-store %store "my-fixed-builder.sh"
161 "echo -n hello > $out" '()))
162 (hash (sha256 (string->utf8 "hello")))
98090557 163 (drv-path (derivation %store "fixed" (%current-system)
97d3998e 164 %bash `(,builder)
813986ac
LC
165 '()
166 `((,builder)) ; optional
749c6567
LC
167 #:hash hash #:hash-algo 'sha256))
168 (succeeded? (build-derivations %store (list drv-path))))
169 (and succeeded?
170 (let ((p (derivation-path->output-path drv-path)))
82058eff
LC
171 (and (equal? (string->utf8 "hello")
172 (call-with-input-file p get-bytevector-all))
173 (bytevector? (query-path-hash %store p)))))))
749c6567 174
813986ac
LC
175(test-assert "fixed-output derivation: output paths are equal"
176 (let* ((builder1 (add-text-to-store %store "fixed-builder1.sh"
177 "echo -n hello > $out" '()))
178 (builder2 (add-text-to-store %store "fixed-builder2.sh"
179 "echo hey; echo -n hello > $out" '()))
180 (hash (sha256 (string->utf8 "hello")))
181 (drv-path1 (derivation %store "fixed" (%current-system)
97d3998e 182 %bash `(,builder1)
813986ac
LC
183 '() `()
184 #:hash hash #:hash-algo 'sha256))
185 (drv-path2 (derivation %store "fixed" (%current-system)
97d3998e 186 %bash `(,builder2)
813986ac
LC
187 '() `()
188 #:hash hash #:hash-algo 'sha256))
189 (succeeded? (build-derivations %store
190 (list drv-path1 drv-path2))))
191 (and succeeded?
192 (equal? (derivation-path->output-path drv-path1)
193 (derivation-path->output-path drv-path2)))))
194
195(test-assert "derivation with a fixed-output input"
196 ;; A derivation D using a fixed-output derivation F doesn't has the same
197 ;; output path when passed F or F', as long as F and F' have the same output
198 ;; path.
199 (let* ((builder1 (add-text-to-store %store "fixed-builder1.sh"
200 "echo -n hello > $out" '()))
201 (builder2 (add-text-to-store %store "fixed-builder2.sh"
202 "echo hey; echo -n hello > $out" '()))
203 (hash (sha256 (string->utf8 "hello")))
204 (fixed1 (derivation %store "fixed" (%current-system)
97d3998e 205 %bash `(,builder1)
813986ac
LC
206 '() `()
207 #:hash hash #:hash-algo 'sha256))
208 (fixed2 (derivation %store "fixed" (%current-system)
97d3998e 209 %bash `(,builder2)
813986ac
LC
210 '() `()
211 #:hash hash #:hash-algo 'sha256))
212 (fixed-out (derivation-path->output-path fixed1))
213 (builder3 (add-text-to-store
214 %store "final-builder.sh"
215 ;; Use Bash hackery to avoid Coreutils.
216 "echo $in ; (read -u 3 c; echo $c) 3< $in > $out" '()))
217 (final1 (derivation %store "final" (%current-system)
97d3998e 218 %bash `(,builder3)
813986ac
LC
219 `(("in" . ,fixed-out))
220 `((,builder3) (,fixed1))))
221 (final2 (derivation %store "final" (%current-system)
97d3998e 222 %bash `(,builder3)
813986ac
LC
223 `(("in" . ,fixed-out))
224 `((,builder3) (,fixed2))))
225 (succeeded? (build-derivations %store
226 (list final1 final2))))
227 (and succeeded?
228 (equal? (derivation-path->output-path final1)
229 (derivation-path->output-path final2)))))
230
7946c4e7
LC
231(test-assert "multiple-output derivation"
232 (let* ((builder (add-text-to-store %store "my-fixed-builder.sh"
233 "echo one > $out ; echo two > $second"
234 '()))
98090557 235 (drv-path (derivation %store "fixed" (%current-system)
97d3998e 236 %bash `(,builder)
7946c4e7
LC
237 '(("HOME" . "/homeless")
238 ("zzz" . "Z!")
239 ("AAA" . "A!"))
240 `((,builder))
241 #:outputs '("out" "second")))
242 (succeeded? (build-derivations %store (list drv-path))))
243 (and succeeded?
244 (let ((one (derivation-path->output-path drv-path "out"))
245 (two (derivation-path->output-path drv-path "second")))
7244a5f7
LC
246 (and (lset= equal?
247 (derivation-path->output-paths drv-path)
248 `(("out" . ,one) ("second" . ,two)))
249 (eq? 'one (call-with-input-file one read))
7946c4e7
LC
250 (eq? 'two (call-with-input-file two read)))))))
251
4b1786aa
LC
252(test-assert "multiple-output derivation, non-alphabetic order"
253 ;; Here, the outputs are not listed in alphabetic order. Yet, the store
254 ;; path computation must reorder them first.
255 (let* ((builder (add-text-to-store %store "my-fixed-builder.sh"
256 "echo one > $out ; echo two > $AAA"
257 '()))
258 (drv-path (derivation %store "fixed" (%current-system)
97d3998e 259 %bash `(,builder)
4b1786aa
LC
260 '()
261 `((,builder))
262 #:outputs '("out" "AAA")))
263 (succeeded? (build-derivations %store (list drv-path))))
264 (and succeeded?
265 (let ((one (derivation-path->output-path drv-path "out"))
266 (two (derivation-path->output-path drv-path "AAA")))
267 (and (eq? 'one (call-with-input-file one read))
268 (eq? 'two (call-with-input-file two read)))))))
269
d66ac374
LC
270(test-assert "user of multiple-output derivation"
271 ;; Check whether specifying several inputs coming from the same
272 ;; multiple-output derivation works.
273 (let* ((builder1 (add-text-to-store %store "my-mo-builder.sh"
274 "echo one > $out ; echo two > $two"
275 '()))
276 (mdrv (derivation %store "multiple-output" (%current-system)
97d3998e 277 %bash `(,builder1)
d66ac374
LC
278 '()
279 `((,builder1))
280 #:outputs '("out" "two")))
281 (builder2 (add-text-to-store %store "my-mo-user-builder.sh"
282 "read x < $one;
283 read y < $two;
284 echo \"($x $y)\" > $out"
285 '()))
286 (udrv (derivation %store "multiple-output-user"
287 (%current-system)
97d3998e 288 %bash `(,builder2)
d66ac374
LC
289 `(("one" . ,(derivation-path->output-path
290 mdrv "out"))
291 ("two" . ,(derivation-path->output-path
292 mdrv "two")))
293 `((,builder2)
294 ;; two occurrences of MDRV:
295 (,mdrv)
296 (,mdrv "two")))))
297 (and (build-derivations %store (list (pk 'udrv udrv)))
298 (let ((p (derivation-path->output-path udrv)))
299 (and (valid-path? %store p)
300 (equal? '(one two) (call-with-input-file p read)))))))
301
de4c3f26
LC
302\f
303(define %coreutils
8f3ecbd7 304 (false-if-exception
ad1ebab3
LC
305 (and (getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)
306 (or (package-derivation %store %bootstrap-coreutils&co)
307 (nixpkgs-derivation "coreutils")))))
de4c3f26
LC
308
309(test-skip (if %coreutils 0 1))
310
311(test-assert "build derivation with coreutils"
312 (let* ((builder
313 (add-text-to-store %store "build-with-coreutils.sh"
314 "echo $PATH ; mkdir --version ; mkdir $out ; touch $out/good"
315 '()))
316 (drv-path
98090557 317 (derivation %store "foo" (%current-system)
97d3998e 318 %bash `(,builder)
de4c3f26
LC
319 `(("PATH" .
320 ,(string-append
321 (derivation-path->output-path %coreutils)
322 "/bin")))
323 `((,builder)
324 (,%coreutils))))
325 (succeeded?
326 (build-derivations %store (list drv-path))))
327 (and succeeded?
328 (let ((p (derivation-path->output-path drv-path)))
31ef99a8
LC
329 (and (valid-path? %store p)
330 (file-exists? (string-append p "/good")))))))
de4c3f26 331
813986ac 332(test-skip (if (%guile-for-build) 0 7))
9a20830e
LC
333
334(test-assert "build-expression->derivation and derivation-prerequisites"
335 (let-values (((drv-path drv)
336 (build-expression->derivation %store "fail" (%current-system)
337 #f '())))
338 (any (match-lambda
339 (($ <derivation-input> path)
340 (string=? path (%guile-for-build))))
341 (derivation-prerequisites drv))))
d9085c23
LC
342
343(test-assert "build-expression->derivation without inputs"
344 (let* ((builder '(begin
345 (mkdir %output)
346 (call-with-output-file (string-append %output "/test")
347 (lambda (p)
348 (display '(hello guix) p)))))
98090557 349 (drv-path (build-expression->derivation %store "goo" (%current-system)
d9085c23
LC
350 builder '()))
351 (succeeded? (build-derivations %store (list drv-path))))
352 (and succeeded?
353 (let ((p (derivation-path->output-path drv-path)))
354 (equal? '(hello guix)
355 (call-with-input-file (string-append p "/test") read))))))
356
969e678e
LC
357(test-assert "build-expression->derivation and max-silent-time"
358 (let* ((store (let ((s (open-connection)))
359 (set-build-options s #:max-silent-time 1)
360 s))
361 (builder '(sleep 100))
362 (drv-path (build-expression->derivation %store "silent"
363 (%current-system)
364 builder '()))
365 (out-path (derivation-path->output-path drv-path)))
366 (guard (c ((nix-protocol-error? c)
367 (and (string-contains (nix-protocol-error-message c)
368 "failed")
369 (not (valid-path? store out-path)))))
370 (build-derivations %store (list drv-path)))))
371
9a20830e
LC
372(test-assert "build-expression->derivation and derivation-prerequisites-to-build"
373 (let-values (((drv-path drv)
374 (build-expression->derivation %store "fail" (%current-system)
375 #f '())))
376 ;; The only direct dependency is (%guile-for-build) and it's already
377 ;; built.
378 (null? (derivation-prerequisites-to-build %store drv))))
379
784bb1f3
LC
380(test-assert "derivation-prerequisites-to-build when outputs already present"
381 (let*-values (((builder)
382 '(begin (mkdir %output) #t))
383 ((input-drv-path input-drv)
384 (build-expression->derivation %store "input"
385 (%current-system)
386 builder '()))
387 ((input-path)
388 (derivation-output-path
389 (assoc-ref (derivation-outputs input-drv)
390 "out")))
391 ((drv-path drv)
392 (build-expression->derivation %store "something"
393 (%current-system)
394 builder
395 `(("i" ,input-drv-path))))
396 ((output)
397 (derivation-output-path
398 (assoc-ref (derivation-outputs drv) "out"))))
399 ;; Make sure these things are not already built.
400 (when (valid-path? %store input-path)
401 (delete-paths %store (list input-path)))
402 (when (valid-path? %store output)
403 (delete-paths %store (list output)))
404
405 (and (equal? (map derivation-input-path
406 (derivation-prerequisites-to-build %store drv))
407 (list input-drv-path))
408
409 ;; Build DRV and delete its input.
410 (build-derivations %store (list drv-path))
411 (delete-paths %store (list input-path))
412 (not (valid-path? %store input-path))
413
414 ;; Now INPUT-PATH is missing, yet it shouldn't be listed as a
415 ;; prerequisite to build because DRV itself is already built.
416 (null? (derivation-prerequisites-to-build %store drv)))))
417
dd36b51b
LC
418(test-skip (if (getenv "GUIX_BINARY_SUBSTITUTE_URL") 0 1))
419(test-assert "derivation-prerequisites-to-build and substitutes"
420 (let*-values (((store)
421 (open-connection))
422 ((drv-path drv)
423 (build-expression->derivation store "prereq-subst"
424 (%current-system)
425 (random 1000) '()))
426 ((output)
427 (derivation-output-path
428 (assoc-ref (derivation-outputs drv) "out")))
429 ((dir)
430 (and=> (getenv "GUIX_BINARY_SUBSTITUTE_URL")
431 (compose uri-path string->uri))))
432 ;; Create fake substituter data, to be read by `substitute-binary'.
433 (call-with-output-file (string-append dir "/nix-cache-info")
434 (lambda (p)
435 (format p "StoreDir: ~a\nWantMassQuery: 0\n"
436 (%store-prefix))))
437 (call-with-output-file (string-append dir "/" (store-path-hash-part output)
438 ".narinfo")
439 (lambda (p)
440 (format p "StorePath: ~a
441URL: ~a
442Compression: none
443NarSize: 1234
444References:
445System: ~a
446Deriver: ~a~%"
447 output ; StorePath
448 (string-append dir "/example.nar") ; URL
449 (%current-system) ; System
450 (basename drv-path)))) ; Deriver
451
452 (let-values (((build download)
453 (derivation-prerequisites-to-build store drv))
454 ((build* download*)
455 (derivation-prerequisites-to-build store drv
456 #:use-substitutes? #f)))
457 (pk build download build* download*)
458 (and (null? build)
459 (equal? download (list output))
460 (null? download*)
461 (null? build*)))))
462
db393b33
LC
463(test-assert "build-expression->derivation with expression returning #f"
464 (let* ((builder '(begin
465 (mkdir %output)
466 #f)) ; fail!
467 (drv-path (build-expression->derivation %store "fail" (%current-system)
31ef99a8
LC
468 builder '()))
469 (out-path (derivation-path->output-path drv-path)))
db393b33
LC
470 (guard (c ((nix-protocol-error? c)
471 ;; Note that the output path may exist at this point, but it
472 ;; is invalid.
31ef99a8
LC
473 (and (string-match "build .* failed"
474 (nix-protocol-error-message c))
475 (not (valid-path? %store out-path)))))
db393b33
LC
476 (build-derivations %store (list drv-path))
477 #f)))
478
9bc07f4d
LC
479(test-assert "build-expression->derivation with two outputs"
480 (let* ((builder '(begin
481 (call-with-output-file (assoc-ref %outputs "out")
482 (lambda (p)
483 (display '(hello) p)))
484 (call-with-output-file (assoc-ref %outputs "second")
485 (lambda (p)
486 (display '(world) p)))))
487 (drv-path (build-expression->derivation %store "double"
98090557 488 (%current-system)
9bc07f4d
LC
489 builder '()
490 #:outputs '("out"
491 "second")))
492 (succeeded? (build-derivations %store (list drv-path))))
493 (and succeeded?
494 (let ((one (derivation-path->output-path drv-path))
495 (two (derivation-path->output-path drv-path "second")))
496 (and (equal? '(hello) (call-with-input-file one read))
497 (equal? '(world) (call-with-input-file two read)))))))
498
ad1ebab3 499(test-skip (if %coreutils 0 1))
d9085c23
LC
500(test-assert "build-expression->derivation with one input"
501 (let* ((builder '(call-with-output-file %output
502 (lambda (p)
503 (let ((cu (assoc-ref %build-inputs "cu")))
504 (close 1)
505 (dup2 (port->fdes p) 1)
506 (execl (string-append cu "/bin/uname")
507 "uname" "-a")))))
98090557 508 (drv-path (build-expression->derivation %store "uname" (%current-system)
d9085c23 509 builder
2acb2cb6 510 `(("cu" ,%coreutils))))
d9085c23
LC
511 (succeeded? (build-derivations %store (list drv-path))))
512 (and succeeded?
513 (let ((p (derivation-path->output-path drv-path)))
514 (string-contains (call-with-input-file p read-line) "GNU")))))
515
99634e3f
LC
516(test-assert "imported-files"
517 (let* ((files `(("x" . ,(search-path %load-path "ice-9/q.scm"))
518 ("a/b/c" . ,(search-path %load-path
519 "guix/derivations.scm"))
224f7ad6
LC
520 ("p/q" . ,(search-path %load-path "guix.scm"))
521 ("p/z" . ,(search-path %load-path "guix/store.scm"))))
99634e3f
LC
522 (drv-path (imported-files %store files)))
523 (and (build-derivations %store (list drv-path))
524 (let ((dir (derivation-path->output-path drv-path)))
525 (every (match-lambda
526 ((path . source)
527 (equal? (call-with-input-file (string-append dir "/" path)
528 get-bytevector-all)
529 (call-with-input-file source
530 get-bytevector-all))))
531 files)))))
532
d9024884
LC
533(test-assert "build-expression->derivation with modules"
534 (let* ((builder `(begin
535 (use-modules (guix build utils))
536 (let ((out (assoc-ref %outputs "out")))
537 (mkdir-p (string-append out "/guile/guix/nix"))
538 #t)))
539 (drv-path (build-expression->derivation %store
540 "test-with-modules"
541 (%current-system)
542 builder '()
543 #:modules
544 '((guix build utils)))))
545 (and (build-derivations %store (list drv-path))
546 (let* ((p (derivation-path->output-path drv-path))
547 (s (stat (string-append p "/guile/guix/nix"))))
548 (eq? (stat:type s) 'directory)))))
549
813986ac
LC
550(test-assert "build-expression->derivation: same fixed-output path"
551 (let* ((builder1 '(call-with-output-file %output
552 (lambda (p)
553 (write "hello" p))))
554 (builder2 '(call-with-output-file (pk 'difference-here! %output)
555 (lambda (p)
556 (write "hello" p))))
557 (hash (sha256 (string->utf8 "hello")))
558 (input1 (build-expression->derivation %store "fixed"
559 (%current-system)
560 builder1 '()
561 #:hash hash
562 #:hash-algo 'sha256))
563 (input2 (build-expression->derivation %store "fixed"
564 (%current-system)
565 builder2 '()
566 #:hash hash
567 #:hash-algo 'sha256))
568 (succeeded? (build-derivations %store (list input1 input2))))
569 (and succeeded?
570 (not (string=? input1 input2))
571 (string=? (derivation-path->output-path input1)
572 (derivation-path->output-path input2)))))
573
7bdd1f0e
LC
574(test-assert "build-expression->derivation with a fixed-output input"
575 (let* ((builder1 '(call-with-output-file %output
576 (lambda (p)
577 (write "hello" p))))
578 (builder2 '(call-with-output-file (pk 'difference-here! %output)
579 (lambda (p)
580 (write "hello" p))))
581 (hash (sha256 (string->utf8 "hello")))
582 (input1 (build-expression->derivation %store "fixed"
583 (%current-system)
584 builder1 '()
585 #:hash hash
586 #:hash-algo 'sha256))
587 (input2 (build-expression->derivation %store "fixed"
588 (%current-system)
589 builder2 '()
590 #:hash hash
591 #:hash-algo 'sha256))
592 (builder3 '(let ((input (assoc-ref %build-inputs "input")))
593 (call-with-output-file %output
594 (lambda (out)
595 (format #f "My input is ~a.~%" input)))))
596 (final1 (build-expression->derivation %store "final"
597 (%current-system)
598 builder3
599 `(("input" ,input1))))
600 (final2 (build-expression->derivation %store "final"
601 (%current-system)
602 builder3
603 `(("input" ,input2)))))
604 (and (string=? (derivation-path->output-path final1)
605 (derivation-path->output-path final2))
606 (build-derivations %store (list final1 final2)))))
607
341c6fdd
LC
608(test-end)
609
610\f
611(exit (= (test-runner-fail-count (test-runner-current)) 0))