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