Merge branch 'master' into core-updates
[jackhill/guix/guix.git] / tests / derivations.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
3 ;;;
4 ;;; This file is part of GNU Guix.
5 ;;;
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
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 ;;;
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
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
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19 (unsetenv "http_proxy")
20
21 (define-module (test-derivations)
22 #:use-module (guix derivations)
23 #:use-module (guix grafts)
24 #:use-module (guix store)
25 #:use-module (guix utils)
26 #:use-module (gcrypt hash)
27 #:use-module (guix base32)
28 #:use-module (guix tests)
29 #:use-module (guix tests http)
30 #:use-module ((guix packages) #:select (package-derivation base32))
31 #:use-module ((guix build utils) #:select (executable-file?))
32 #:use-module (gnu packages bootstrap)
33 #:use-module ((gnu packages guile) #:select (guile-1.8))
34 #:use-module (srfi srfi-1)
35 #:use-module (srfi srfi-11)
36 #:use-module (srfi srfi-26)
37 #:use-module (srfi srfi-34)
38 #:use-module (srfi srfi-64)
39 #:use-module (rnrs io ports)
40 #:use-module (rnrs bytevectors)
41 #:use-module (web uri)
42 #:use-module (ice-9 rdelim)
43 #:use-module (ice-9 regex)
44 #:use-module (ice-9 ftw)
45 #:use-module (ice-9 match))
46
47 (define %store
48 (open-connection-for-tests))
49
50 ;; Globally disable grafts because they can trigger early builds.
51 (%graft? #f)
52
53 (define (bootstrap-binary name)
54 (let ((bin (search-bootstrap-binary name (%current-system))))
55 (and %store
56 (add-to-store %store name #t "sha256" bin))))
57
58 (define %bash
59 (bootstrap-binary "bash"))
60 (define %mkdir
61 (bootstrap-binary "mkdir"))
62
63 (define* (directory-contents dir #:optional (slurp get-bytevector-all))
64 "Return an alist representing the contents of DIR."
65 (define prefix-len (string-length dir))
66 (sort (file-system-fold (const #t) ; enter?
67 (lambda (path stat result) ; leaf
68 (alist-cons (string-drop path prefix-len)
69 (call-with-input-file path slurp)
70 result))
71 (lambda (path stat result) result) ; down
72 (lambda (path stat result) result) ; up
73 (lambda (path stat result) result) ; skip
74 (lambda (path stat errno result) result) ; error
75 '()
76 dir)
77 (lambda (e1 e2)
78 (string<? (car e1) (car e2)))))
79
80 ;; Avoid collisions with other tests.
81 (%http-server-port 10500)
82
83 \f
84 (test-begin "derivations")
85
86 (test-assert "parse & export"
87 (let* ((f (search-path %load-path "tests/test.drv"))
88 (b1 (call-with-input-file f get-bytevector-all))
89 (d1 (read-derivation (open-bytevector-input-port b1)
90 identity))
91 (b2 (call-with-bytevector-output-port (cut write-derivation d1 <>)))
92 (d2 (read-derivation (open-bytevector-input-port b2)
93 identity)))
94 (and (equal? b1 b2)
95 (equal? d1 d2))))
96
97 (test-skip (if %store 0 12))
98
99 (test-assert "add-to-store, flat"
100 ;; Use 'readlink*' in case spec.scm is a symlink, as is the case when Guile
101 ;; was installed with Stow.
102 (let* ((file (readlink*
103 (search-path %load-path "language/tree-il/spec.scm")))
104 (drv (add-to-store %store "flat-test" #f "sha256" file)))
105 (and (eq? 'regular (stat:type (stat drv)))
106 (valid-path? %store drv)
107 (equal? (call-with-input-file file get-bytevector-all)
108 (call-with-input-file drv get-bytevector-all)))))
109
110 (test-assert "add-to-store, recursive"
111 (let* ((dir (dirname
112 (readlink* (search-path %load-path
113 "language/tree-il/spec.scm"))))
114 (drv (add-to-store %store "dir-tree-test" #t "sha256" dir)))
115 (and (eq? 'directory (stat:type (stat drv)))
116 (valid-path? %store drv)
117 (equal? (directory-contents dir)
118 (directory-contents drv)))))
119
120 (test-assert "derivation with no inputs"
121 (let* ((builder (add-text-to-store %store "my-builder.sh"
122 "echo hello, world\n"
123 '()))
124 (drv (derivation %store "foo"
125 %bash `("-e" ,builder)
126 #:env-vars '(("HOME" . "/homeless")))))
127 (and (store-path? (derivation-file-name drv))
128 (valid-path? %store (derivation-file-name drv)))))
129
130 (test-assert "build derivation with 1 source"
131 (let* ((builder (add-text-to-store %store "my-builder.sh"
132 "echo hello, world > \"$out\"\n"
133 '()))
134 (drv (derivation %store "foo"
135 %bash `(,builder)
136 #:env-vars '(("HOME" . "/homeless")
137 ("zzz" . "Z!")
138 ("AAA" . "A!"))
139 #:sources `(,%bash ,builder)))
140 (succeeded?
141 (build-derivations %store (list drv))))
142 (and succeeded?
143 (let ((path (derivation->output-path drv)))
144 (and (valid-path? %store path)
145 (string=? (call-with-input-file path read-line)
146 "hello, world"))))))
147
148 (test-assert "derivation fails but keep going"
149 ;; In keep-going mode, 'build-derivations' should fail because of D1, but it
150 ;; must return only after D2 has succeeded.
151 (with-store store
152 (let* ((d1 (derivation %store "fails"
153 %bash `("-c" "false")
154 #:sources (list %bash)))
155 (d2 (build-expression->derivation %store "sleep-then-succeed"
156 `(begin
157 ,(random-text)
158 ;; XXX: Hopefully that's long
159 ;; enough that D1 has already
160 ;; failed.
161 (sleep 2)
162 (mkdir %output)))))
163 (set-build-options %store
164 #:use-substitutes? #f
165 #:keep-going? #t)
166 (guard (c ((store-protocol-error? c)
167 (and (= 100 (store-protocol-error-status c))
168 (string-contains (store-protocol-error-message c)
169 (derivation-file-name d1))
170 (not (valid-path? %store (derivation->output-path d1)))
171 (valid-path? %store (derivation->output-path d2)))))
172 (build-derivations %store (list d1 d2))
173 #f))))
174
175 (test-assert "identical files are deduplicated"
176 (let* ((build1 (add-text-to-store %store "one.sh"
177 "echo hello, world > \"$out\"\n"
178 '()))
179 (build2 (add-text-to-store %store "two.sh"
180 "# Hey!\necho hello, world > \"$out\"\n"
181 '()))
182 (drv1 (derivation %store "foo"
183 %bash `(,build1)
184 #:sources `(,%bash ,build1)))
185 (drv2 (derivation %store "bar"
186 %bash `(,build2)
187 #:sources `(,%bash ,build2))))
188 (and (build-derivations %store (list drv1 drv2))
189 (let ((file1 (derivation->output-path drv1))
190 (file2 (derivation->output-path drv2)))
191 (and (valid-path? %store file1) (valid-path? %store file2)
192 (string=? (call-with-input-file file1 get-string-all)
193 "hello, world\n")
194 (= (stat:ino (lstat file1))
195 (stat:ino (lstat file2))))))))
196
197 (test-equal "built-in-builders"
198 '("download")
199 (built-in-builders %store))
200
201 (test-assert "unknown built-in builder"
202 (let ((drv (derivation %store "ohoh" "builtin:does-not-exist" '())))
203 (guard (c ((store-protocol-error? c)
204 (string-contains (store-protocol-error-message c) "failed")))
205 (build-derivations %store (list drv))
206 #f)))
207
208 (unless (http-server-can-listen?)
209 (test-skip 1))
210 (test-assert "'download' built-in builder"
211 (let ((text (random-text)))
212 (with-http-server 200 text
213 (let* ((drv (derivation %store "world"
214 "builtin:download" '()
215 #:env-vars `(("url"
216 . ,(object->string (%local-url))))
217 #:hash-algo 'sha256
218 #:hash (sha256 (string->utf8 text)))))
219 (and (build-derivations %store (list drv))
220 (string=? (call-with-input-file (derivation->output-path drv)
221 get-string-all)
222 text))))))
223
224 (unless (http-server-can-listen?)
225 (test-skip 1))
226 (test-assert "'download' built-in builder, invalid hash"
227 (with-http-server 200 "hello, world!"
228 (let* ((drv (derivation %store "world"
229 "builtin:download" '()
230 #:env-vars `(("url"
231 . ,(object->string (%local-url))))
232 #:hash-algo 'sha256
233 #:hash (sha256 (random-bytevector 100))))) ;wrong
234 (guard (c ((store-protocol-error? c)
235 (string-contains (store-protocol-error-message c) "failed")))
236 (build-derivations %store (list drv))
237 #f))))
238
239 (unless (http-server-can-listen?)
240 (test-skip 1))
241 (test-assert "'download' built-in builder, not found"
242 (with-http-server 404 "not found"
243 (let* ((drv (derivation %store "will-never-be-found"
244 "builtin:download" '()
245 #:env-vars `(("url"
246 . ,(object->string (%local-url))))
247 #:hash-algo 'sha256
248 #:hash (sha256 (random-bytevector 100)))))
249 (guard (c ((store-protocol-error? c)
250 (string-contains (store-protocol-error-message (pk c)) "failed")))
251 (build-derivations %store (list drv))
252 #f))))
253
254 (test-assert "'download' built-in builder, not fixed-output"
255 (let* ((source (add-text-to-store %store "hello" "hi!"))
256 (url (string-append "file://" source))
257 (drv (derivation %store "world"
258 "builtin:download" '()
259 #:env-vars `(("url" . ,(object->string url))))))
260 (guard (c ((store-protocol-error? c)
261 (string-contains (store-protocol-error-message c) "failed")))
262 (build-derivations %store (list drv))
263 #f)))
264
265 (unless (http-server-can-listen?)
266 (test-skip 1))
267 (test-assert "'download' built-in builder, check mode"
268 ;; Make sure rebuilding the 'builtin:download' derivation in check mode
269 ;; works. See <http://bugs.gnu.org/25089>.
270 (let* ((text (random-text))
271 (drv (derivation %store "world"
272 "builtin:download" '()
273 #:env-vars `(("url"
274 . ,(object->string (%local-url))))
275 #:hash-algo 'sha256
276 #:hash (sha256 (string->utf8 text)))))
277 (and (with-http-server 200 text
278 (build-derivations %store (list drv)))
279 (with-http-server 200 text
280 (build-derivations %store (list drv)
281 (build-mode check)))
282 (string=? (call-with-input-file (derivation->output-path drv)
283 get-string-all)
284 text))))
285
286 (test-equal "derivation-name"
287 "foo-0.0"
288 (let ((drv (derivation %store "foo-0.0" %bash '())))
289 (derivation-name drv)))
290
291 (test-equal "derivation-output-names"
292 '(("out") ("bar" "chbouib"))
293 (let ((drv1 (derivation %store "foo-0.0" %bash '()))
294 (drv2 (derivation %store "foo-0.0" %bash '()
295 #:outputs '("bar" "chbouib"))))
296 (list (derivation-output-names drv1)
297 (derivation-output-names drv2))))
298
299 (test-assert "offloadable-derivation?"
300 (and (offloadable-derivation? (derivation %store "foo" %bash '()))
301 (offloadable-derivation? ;see <http://bugs.gnu.org/18747>
302 (derivation %store "foo" %bash '()
303 #:substitutable? #f))
304 (not (offloadable-derivation?
305 (derivation %store "foo" %bash '()
306 #:local-build? #t)))))
307
308 (test-assert "substitutable-derivation?"
309 (and (substitutable-derivation? (derivation %store "foo" %bash '()))
310 (substitutable-derivation? ;see <http://bugs.gnu.org/18747>
311 (derivation %store "foo" %bash '()
312 #:local-build? #t))
313 (not (substitutable-derivation?
314 (derivation %store "foo" %bash '()
315 #:substitutable? #f)))))
316
317 (test-assert "fixed-output-derivation?"
318 (let* ((builder (add-text-to-store %store "my-fixed-builder.sh"
319 "echo -n hello > $out" '()))
320 (hash (sha256 (string->utf8 "hello")))
321 (drv (derivation %store "fixed"
322 %bash `(,builder)
323 #:sources (list builder)
324 #:hash hash #:hash-algo 'sha256)))
325 (fixed-output-derivation? drv)))
326
327 (test-assert "fixed-output derivation"
328 (let* ((builder (add-text-to-store %store "my-fixed-builder.sh"
329 "echo -n hello > $out" '()))
330 (hash (sha256 (string->utf8 "hello")))
331 (drv (derivation %store "fixed"
332 %bash `(,builder)
333 #:sources `(,builder) ;optional
334 #:hash hash #:hash-algo 'sha256))
335 (succeeded? (build-derivations %store (list drv))))
336 (and succeeded?
337 (let ((p (derivation->output-path drv)))
338 (and (equal? (string->utf8 "hello")
339 (call-with-input-file p get-bytevector-all))
340 (bytevector? (query-path-hash %store p)))))))
341
342 (test-assert "fixed-output derivation: output paths are equal"
343 (let* ((builder1 (add-text-to-store %store "fixed-builder1.sh"
344 "echo -n hello > $out" '()))
345 (builder2 (add-text-to-store %store "fixed-builder2.sh"
346 "echo hey; echo -n hello > $out" '()))
347 (hash (sha256 (string->utf8 "hello")))
348 (drv1 (derivation %store "fixed"
349 %bash `(,builder1)
350 #:hash hash #:hash-algo 'sha256))
351 (drv2 (derivation %store "fixed"
352 %bash `(,builder2)
353 #:hash hash #:hash-algo 'sha256))
354 (succeeded? (build-derivations %store (list drv1 drv2))))
355 (and succeeded?
356 (equal? (derivation->output-path drv1)
357 (derivation->output-path drv2)))))
358
359 (test-assert "fixed-output derivation, recursive"
360 (let* ((builder (add-text-to-store %store "my-fixed-builder.sh"
361 "echo -n hello > $out" '()))
362 (hash (sha256 (string->utf8 "hello")))
363 (drv (derivation %store "fixed-rec"
364 %bash `(,builder)
365 #:sources (list builder)
366 #:hash (base32 "0sg9f58l1jj88w6pdrfdpj5x9b1zrwszk84j81zvby36q9whhhqa")
367 #:hash-algo 'sha256
368 #:recursive? #t))
369 (succeeded? (build-derivations %store (list drv))))
370 (and succeeded?
371 (let ((p (derivation->output-path drv)))
372 (and (equal? (string->utf8 "hello")
373 (call-with-input-file p get-bytevector-all))
374 (bytevector? (query-path-hash %store p)))))))
375
376 (test-assert "derivation with a fixed-output input"
377 ;; A derivation D using a fixed-output derivation F doesn't has the same
378 ;; output path when passed F or F', as long as F and F' have the same output
379 ;; path.
380 (let* ((builder1 (add-text-to-store %store "fixed-builder1.sh"
381 "echo -n hello > $out" '()))
382 (builder2 (add-text-to-store %store "fixed-builder2.sh"
383 "echo hey; echo -n hello > $out" '()))
384 (hash (sha256 (string->utf8 "hello")))
385 (fixed1 (derivation %store "fixed"
386 %bash `(,builder1)
387 #:hash hash #:hash-algo 'sha256))
388 (fixed2 (derivation %store "fixed"
389 %bash `(,builder2)
390 #:hash hash #:hash-algo 'sha256))
391 (fixed-out (derivation->output-path fixed1))
392 (builder3 (add-text-to-store
393 %store "final-builder.sh"
394 ;; Use Bash hackery to avoid Coreutils.
395 "echo $in ; (read -u 3 c; echo $c) 3< $in > $out" '()))
396 (final1 (derivation %store "final"
397 %bash `(,builder3)
398 #:env-vars `(("in" . ,fixed-out))
399 #:sources (list %bash builder3)
400 #:inputs (list (derivation-input fixed1))))
401 (final2 (derivation %store "final"
402 %bash `(,builder3)
403 #:env-vars `(("in" . ,fixed-out))
404 #:sources (list %bash builder3)
405 #:inputs (list (derivation-input fixed2))))
406 (succeeded? (build-derivations %store
407 (list final1 final2))))
408 (and succeeded?
409 (equal? (derivation->output-path final1)
410 (derivation->output-path final2)))))
411
412 (test-assert "derivation with duplicate fixed-output inputs"
413 ;; Here we create a derivation that has two inputs, both of which are
414 ;; fixed-output leading to the same result. This test ensures the hash of
415 ;; that derivation is correctly computed, namely that duplicate inputs are
416 ;; coalesced. See <https://bugs.gnu.org/36777>.
417 (let* ((builder1 (add-text-to-store %store "fixed-builder1.sh"
418 "echo -n hello > $out" '()))
419 (builder2 (add-text-to-store %store "fixed-builder2.sh"
420 "echo hey; echo -n hello > $out" '()))
421 (hash (sha256 (string->utf8 "hello")))
422 (fixed1 (derivation %store "fixed"
423 %bash `(,builder1)
424 #:hash hash #:hash-algo 'sha256))
425 (fixed2 (derivation %store "fixed"
426 %bash `(,builder2)
427 #:hash hash #:hash-algo 'sha256))
428 (builder3 (add-text-to-store %store "builder.sh"
429 "echo fake builder"))
430 (final (derivation %store "final"
431 %bash `(,builder3)
432 #:sources (list %bash builder3)
433 #:inputs (list (derivation-input fixed1)
434 (derivation-input fixed2)))))
435 (and (derivation? final)
436 (match (derivation-inputs final)
437 (((= derivation-input-derivation one)
438 (= derivation-input-derivation two))
439 (and (not (string=? (derivation-file-name one)
440 (derivation-file-name two)))
441 (string=? (derivation->output-path one)
442 (derivation->output-path two))))))))
443
444 (test-assert "multiple-output derivation"
445 (let* ((builder (add-text-to-store %store "my-fixed-builder.sh"
446 "echo one > $out ; echo two > $second"
447 '()))
448 (drv (derivation %store "fixed"
449 %bash `(,builder)
450 #:env-vars '(("HOME" . "/homeless")
451 ("zzz" . "Z!")
452 ("AAA" . "A!"))
453 #:sources `(,%bash ,builder)
454 #:outputs '("out" "second")))
455 (succeeded? (build-derivations %store (list drv))))
456 (and succeeded?
457 (let ((one (derivation->output-path drv "out"))
458 (two (derivation->output-path drv "second")))
459 (and (lset= equal?
460 (derivation->output-paths drv)
461 `(("out" . ,one) ("second" . ,two)))
462 (eq? 'one (call-with-input-file one read))
463 (eq? 'two (call-with-input-file two read)))))))
464
465 (test-assert "multiple-output derivation, non-alphabetic order"
466 ;; Here, the outputs are not listed in alphabetic order. Yet, the store
467 ;; path computation must reorder them first.
468 (let* ((builder (add-text-to-store %store "my-fixed-builder.sh"
469 "echo one > $out ; echo two > $AAA"
470 '()))
471 (drv (derivation %store "fixed"
472 %bash `(,builder)
473 #:sources `(,%bash ,builder)
474 #:outputs '("out" "AAA")))
475 (succeeded? (build-derivations %store (list drv))))
476 (and succeeded?
477 (let ((one (derivation->output-path drv "out"))
478 (two (derivation->output-path drv "AAA")))
479 (and (eq? 'one (call-with-input-file one read))
480 (eq? 'two (call-with-input-file two read)))))))
481
482 (test-assert "read-derivation vs. derivation"
483 ;; Make sure 'derivation' and 'read-derivation' return objects that are
484 ;; identical.
485 (let* ((sources (unfold (cut >= <> 10)
486 (lambda (n)
487 (add-text-to-store %store
488 (format #f "input~a" n)
489 (random-text)))
490 1+
491 0))
492 (inputs (map (lambda (file)
493 (derivation %store "derivation-input"
494 %bash '()
495 #:sources `(,%bash ,file)))
496 sources))
497 (builder (add-text-to-store %store "builder.sh"
498 "echo one > $one ; echo two > $two"
499 '()))
500 (drv (derivation %store "derivation"
501 %bash `(,builder)
502 #:sources `(,%bash ,builder ,@sources)
503 #:inputs (map derivation-input inputs)
504 #:outputs '("two" "one")))
505 (drv* (call-with-input-file (derivation-file-name drv)
506 read-derivation)))
507 (equal? drv* drv)))
508
509 (test-assert "multiple-output derivation, derivation-path->output-path"
510 (let* ((builder (add-text-to-store %store "builder.sh"
511 "echo one > $out ; echo two > $second"
512 '()))
513 (drv (derivation %store "multiple"
514 %bash `(,builder)
515 #:outputs '("out" "second")))
516 (drv-file (derivation-file-name drv))
517 (one (derivation->output-path drv "out"))
518 (two (derivation->output-path drv "second"))
519 (first (derivation-path->output-path drv-file "out"))
520 (second (derivation-path->output-path drv-file "second")))
521 (and (not (string=? one two))
522 (string-suffix? "-second" two)
523 (string=? first one)
524 (string=? second two))))
525
526 (test-assert "user of multiple-output derivation"
527 ;; Check whether specifying several inputs coming from the same
528 ;; multiple-output derivation works.
529 (let* ((builder1 (add-text-to-store %store "my-mo-builder.sh"
530 "echo one > $out ; echo two > $two"
531 '()))
532 (mdrv (derivation %store "multiple-output"
533 %bash `(,builder1)
534 #:sources (list %bash builder1)
535 #:outputs '("out" "two")))
536 (builder2 (add-text-to-store %store "my-mo-user-builder.sh"
537 "read x < $one;
538 read y < $two;
539 echo \"($x $y)\" > $out"
540 '()))
541 (udrv (derivation %store "multiple-output-user"
542 %bash `(,builder2)
543 #:env-vars `(("one"
544 . ,(derivation->output-path
545 mdrv "out"))
546 ("two"
547 . ,(derivation->output-path
548 mdrv "two")))
549 #:sources (list %bash builder2)
550 ;; two occurrences of MDRV:
551 #:inputs
552 (list (derivation-input mdrv)
553 (derivation-input mdrv '("two"))))))
554 (and (build-derivations %store (list (pk 'udrv udrv)))
555 (let ((p (derivation->output-path udrv)))
556 (and (valid-path? %store p)
557 (equal? '(one two) (call-with-input-file p read)))))))
558
559 (test-assert "derivation with #:references-graphs"
560 (let* ((input1 (add-text-to-store %store "foo" "hello"
561 (list %bash)))
562 (input2 (add-text-to-store %store "bar"
563 (number->string (random 7777))
564 (list input1)))
565 (builder (add-text-to-store %store "build-graph"
566 (format #f "
567 ~a $out
568 (while read l ; do echo $l ; done) < bash > $out/bash
569 (while read l ; do echo $l ; done) < input1 > $out/input1
570 (while read l ; do echo $l ; done) < input2 > $out/input2"
571 %mkdir)
572 (list %mkdir)))
573 (drv (derivation %store "closure-graphs"
574 %bash `(,builder)
575 #:references-graphs
576 `(("bash" . ,%bash)
577 ("input1" . ,input1)
578 ("input2" . ,input2))
579 #:sources (list %bash builder)))
580 (out (derivation->output-path drv)))
581 (define (deps path . deps)
582 (let ((count (length deps)))
583 (string-append path "\n\n" (number->string count) "\n"
584 (string-join (sort deps string<?) "\n")
585 (if (zero? count) "" "\n"))))
586
587 (and (build-derivations %store (list drv))
588 (equal? (directory-contents out get-string-all)
589 `(("/bash" . ,(string-append %bash "\n\n0\n"))
590 ("/input1" . ,(if (string>? input1 %bash)
591 (string-append (deps %bash)
592 (deps input1 %bash))
593 (string-append (deps input1 %bash)
594 (deps %bash))))
595 ("/input2" . ,(string-concatenate
596 (map cdr
597 (sort
598 (map (lambda (p d)
599 (cons p (apply deps p d)))
600 (list %bash input1 input2)
601 (list '() (list %bash) (list input1)))
602 (lambda (x y)
603 (match x
604 ((p1 . _)
605 (match y
606 ((p2 . _)
607 (string<? p1 p2)))))))))))))))
608
609 (test-assert "derivation #:allowed-references, ok"
610 (let ((drv (derivation %store "allowed" %bash
611 '("-c" "echo hello > $out")
612 #:sources (list %bash)
613 #:allowed-references '())))
614 (build-derivations %store (list drv))))
615
616 (test-assert "derivation #:allowed-references, not allowed"
617 (let* ((txt (add-text-to-store %store "foo" "Hello, world."))
618 (drv (derivation %store "disallowed" %bash
619 `("-c" ,(string-append "echo " txt "> $out"))
620 #:sources (list %bash txt)
621 #:allowed-references '())))
622 (guard (c ((store-protocol-error? c)
623 ;; There's no specific error message to check for.
624 #t))
625 (build-derivations %store (list drv))
626 #f)))
627
628 (test-assert "derivation #:allowed-references, self allowed"
629 (let ((drv (derivation %store "allowed" %bash
630 '("-c" "echo $out > $out")
631 #:sources (list %bash)
632 #:allowed-references '("out"))))
633 (build-derivations %store (list drv))))
634
635 (test-assert "derivation #:allowed-references, self not allowed"
636 (let ((drv (derivation %store "disallowed" %bash
637 `("-c" ,"echo $out > $out")
638 #:sources (list %bash)
639 #:allowed-references '())))
640 (guard (c ((store-protocol-error? c)
641 ;; There's no specific error message to check for.
642 #t))
643 (build-derivations %store (list drv))
644 #f)))
645
646 (test-assert "derivation #:disallowed-references, ok"
647 (let ((drv (derivation %store "disallowed" %bash
648 '("-c" "echo hello > $out")
649 #:sources (list %bash)
650 #:disallowed-references '("out"))))
651 (build-derivations %store (list drv))))
652
653 (test-assert "derivation #:disallowed-references, not ok"
654 (let* ((txt (add-text-to-store %store "foo" "Hello, world."))
655 (drv (derivation %store "disdisallowed" %bash
656 `("-c" ,(string-append "echo " txt "> $out"))
657 #:sources (list %bash txt)
658 #:disallowed-references (list txt))))
659 (guard (c ((store-protocol-error? c)
660 ;; There's no specific error message to check for.
661 #t))
662 (build-derivations %store (list drv))
663 #f)))
664
665 ;; Here we should get the value of $GUIX_STATE_DIRECTORY that the daemon sees,
666 ;; which is a unique value for each test process; this value is the same as
667 ;; the one we see in the process executing this file since it is set by
668 ;; 'test-env'.
669 (test-equal "derivation #:leaked-env-vars"
670 (getenv "GUIX_STATE_DIRECTORY")
671 (let* ((value (getenv "GUIX_STATE_DIRECTORY"))
672 (drv (derivation %store "leaked-env-vars" %bash
673 '("-c" "echo -n $GUIX_STATE_DIRECTORY > $out")
674 #:hash (sha256 (string->utf8 value))
675 #:hash-algo 'sha256
676 #:sources (list %bash)
677 #:leaked-env-vars '("GUIX_STATE_DIRECTORY"))))
678 (and (build-derivations %store (list drv))
679 (call-with-input-file (derivation->output-path drv)
680 get-string-all))))
681
682 \f
683 (define %coreutils
684 (false-if-exception
685 (and (network-reachable?)
686 (package-derivation %store %bootstrap-coreutils&co))))
687
688 (test-skip (if %coreutils 0 1))
689
690 (test-assert "build derivation with coreutils"
691 (let* ((builder
692 (add-text-to-store %store "build-with-coreutils.sh"
693 "echo $PATH ; mkdir --version ; mkdir $out ; touch $out/good"
694 '()))
695 (drv
696 (derivation %store "foo"
697 %bash `(,builder)
698 #:env-vars `(("PATH" .
699 ,(string-append
700 (derivation->output-path %coreutils)
701 "/bin")))
702 #:sources (list builder)
703 #:inputs (list (derivation-input %coreutils))))
704 (succeeded?
705 (build-derivations %store (list drv))))
706 (and succeeded?
707 (let ((p (derivation->output-path drv)))
708 (and (valid-path? %store p)
709 (file-exists? (string-append p "/good")))))))
710
711 (test-skip (if (%guile-for-build) 0 8))
712
713 (test-equal "build-expression->derivation and invalid module name"
714 '(file-search-error "guix/module/that/does/not/exist.scm")
715 (guard (c ((file-search-error? c)
716 (list 'file-search-error
717 (file-search-error-file-name c))))
718 (build-expression->derivation %store "foo" #t
719 #:modules '((guix module that
720 does not exist)))))
721
722 (test-equal "build-expression->derivation and builder encoding"
723 '("UTF-8" #t)
724 (let* ((exp '(λ (α) (+ α 1)))
725 (drv (build-expression->derivation %store "foo" exp)))
726 (match (derivation-builder-arguments drv)
727 ((... builder)
728 (with-fluids ((%default-port-encoding "UTF-8"))
729 (call-with-input-file builder
730 (lambda (port)
731 (list (port-encoding port)
732 (->bool
733 (string-contains (get-string-all port)
734 "(λ (α) (+ α 1))"))))))))))
735
736 (test-assert "build-expression->derivation and derivation-prerequisites"
737 (let ((drv (build-expression->derivation %store "fail" #f)))
738 (any (match-lambda
739 (($ <derivation-input> (= derivation-file-name path))
740 (string=? path (derivation-file-name (%guile-for-build)))))
741 (derivation-prerequisites drv))))
742
743 (test-assert "derivation-prerequisites and valid-derivation-input?"
744 (let* ((a (build-expression->derivation %store "a" '(mkdir %output)))
745 (b (build-expression->derivation %store "b" `(list ,(random-text))))
746 (c (build-expression->derivation %store "c" `(mkdir %output)
747 #:inputs `(("a" ,a) ("b" ,b)))))
748 ;; Make sure both A and %BOOTSTRAP-GUILE are built (the latter could have
749 ;; be removed by tests/guix-gc.sh.)
750 (build-derivations %store
751 (list a (package-derivation %store %bootstrap-guile)))
752
753 (match (derivation-prerequisites c
754 (cut valid-derivation-input? %store
755 <>))
756 ((($ <derivation-input> (= derivation-file-name file) ("out")))
757 (string=? file (derivation-file-name b)))
758 (x
759 (pk 'fail x #f)))))
760
761 (test-assert "build-expression->derivation without inputs"
762 (let* ((builder '(begin
763 (mkdir %output)
764 (call-with-output-file (string-append %output "/test")
765 (lambda (p)
766 (display '(hello guix) p)))))
767 (drv (build-expression->derivation %store "goo" builder))
768 (succeeded? (build-derivations %store (list drv))))
769 (and succeeded?
770 (let ((p (derivation->output-path drv)))
771 (equal? '(hello guix)
772 (call-with-input-file (string-append p "/test") read))))))
773
774 (test-assert "build-expression->derivation and max-silent-time"
775 (let* ((store (let ((s (open-connection)))
776 (set-build-options s #:max-silent-time 1)
777 s))
778 (builder '(begin (sleep 100) (mkdir %output) #t))
779 (drv (build-expression->derivation store "silent" builder))
780 (out-path (derivation->output-path drv)))
781 (guard (c ((store-protocol-error? c)
782 (and (string-contains (store-protocol-error-message c)
783 "failed")
784 (not (valid-path? store out-path)))))
785 (build-derivations store (list drv))
786 #f)))
787
788 (test-assert "build-expression->derivation and timeout"
789 (let* ((store (let ((s (open-connection)))
790 (set-build-options s #:timeout 1)
791 s))
792 (builder '(begin (sleep 100) (mkdir %output) #t))
793 (drv (build-expression->derivation store "slow" builder))
794 (out-path (derivation->output-path drv)))
795 (guard (c ((store-protocol-error? c)
796 (and (string-contains (store-protocol-error-message c)
797 "failed")
798 (not (valid-path? store out-path)))))
799 (build-derivations store (list drv))
800 #f)))
801
802 (test-assert "build-derivations with specific output"
803 (with-store store
804 (let* ((content (random-text)) ;contents of the output
805 (drv (build-expression->derivation
806 store "substitute-me"
807 `(begin ,content (exit 1)) ;would fail
808 #:outputs '("out" "one" "two")
809 #:guile-for-build
810 (package-derivation store %bootstrap-guile)))
811 (out (derivation->output-path drv)))
812 (with-derivation-substitute drv content
813 (set-build-options store #:use-substitutes? #t
814 #:substitute-urls (%test-substitute-urls))
815 (and (has-substitutes? store out)
816
817 ;; Ask for nothing but the "out" output of DRV.
818 (build-derivations store `((,drv . "out")))
819
820 ;; Synonymous:
821 (build-derivations store (list (derivation-input drv '("out"))))
822
823 (valid-path? store out)
824 (equal? (pk 'x content)
825 (pk 'y (call-with-input-file out get-string-all))))))))
826
827 (test-assert "build-expression->derivation and derivation-build-plan"
828 (let ((drv (build-expression->derivation %store "fail" #f)))
829 ;; The only direct dependency is (%guile-for-build) and it's already
830 ;; built.
831 (null? (derivation-build-plan %store (derivation-inputs drv)))))
832
833 (test-assert "derivation-build-plan when outputs already present"
834 (let* ((builder `(begin ,(random-text) (mkdir %output) #t))
835 (input-drv (build-expression->derivation %store "input" builder))
836 (input-path (derivation->output-path input-drv))
837 (drv (build-expression->derivation %store "something" builder
838 #:inputs
839 `(("i" ,input-drv))))
840 (output (derivation->output-path drv)))
841 ;; Assume these things are not already built.
842 (when (or (valid-path? %store input-path)
843 (valid-path? %store output))
844 (error "things already built" input-drv))
845
846 (and (lset= equal?
847 (map derivation-file-name
848 (derivation-build-plan %store
849 (list (derivation-input drv))))
850 (list (derivation-file-name input-drv)
851 (derivation-file-name drv)))
852
853 ;; Build DRV and delete its input.
854 (build-derivations %store (list drv))
855 (delete-paths %store (list input-path))
856 (not (valid-path? %store input-path))
857
858 ;; Now INPUT-PATH is missing, yet it shouldn't be listed as a
859 ;; prerequisite to build because DRV itself is already built.
860 (null? (derivation-build-plan %store
861 (list (derivation-input drv)))))))
862
863 (test-assert "derivation-build-plan and substitutes"
864 (let* ((store (open-connection))
865 (drv (build-expression->derivation store "prereq-subst"
866 (random 1000)))
867 (output (derivation->output-path drv)))
868
869 ;; Make sure substitutes are usable.
870 (set-build-options store #:use-substitutes? #t
871 #:substitute-urls (%test-substitute-urls))
872
873 (with-derivation-narinfo drv
874 (let-values (((build download)
875 (derivation-build-plan store
876 (list (derivation-input drv))))
877 ((build* download*)
878 (derivation-build-plan store
879 (list (derivation-input drv))
880 #:substitutable-info
881 (const #f))))
882 (and (null? build)
883 (equal? (map substitutable-path download) (list output))
884 (null? download*)
885 (equal? (list drv) build*))))))
886
887 (test-assert "derivation-build-plan and substitutes, non-substitutable build"
888 (let* ((store (open-connection))
889 (drv (build-expression->derivation store "prereq-no-subst"
890 (random 1000)
891 #:substitutable? #f))
892 (output (derivation->output-path drv)))
893
894 ;; Make sure substitutes are usable.
895 (set-build-options store #:use-substitutes? #t
896 #:substitute-urls (%test-substitute-urls))
897
898 (with-derivation-narinfo drv
899 (let-values (((build download)
900 (derivation-build-plan store
901 (list (derivation-input drv)))))
902 ;; Despite being available as a substitute, DRV will be built locally
903 ;; due to #:substitutable? #f.
904 (and (null? download)
905 (match build
906 (((= derivation-file-name build))
907 (string=? build (derivation-file-name drv)))))))))
908
909 (test-assert "derivation-build-plan and substitutes, non-substitutable dep"
910 (with-store store
911 (let* ((drv1 (build-expression->derivation store "prereq-no-subst"
912 (random 1000)
913 #:substitutable? #f))
914 (drv2 (build-expression->derivation store "substitutable"
915 (random 1000)
916 #:inputs `(("dep" ,drv1)))))
917
918 ;; Make sure substitutes are usable.
919 (set-build-options store #:use-substitutes? #t
920 #:substitute-urls (%test-substitute-urls))
921
922 (with-derivation-narinfo drv2
923 (sha256 => (make-bytevector 32 0))
924 (references => (list (derivation->output-path drv1)))
925
926 (let-values (((build download)
927 (derivation-build-plan store
928 (list (derivation-input drv2)))))
929 ;; Although DRV2 is available as a substitute, we must build its
930 ;; dependency, DRV1, due to #:substitutable? #f.
931 (and (match download
932 (((= substitutable-path item))
933 (string=? item (derivation->output-path drv2))))
934 (match build
935 (((= derivation-file-name build))
936 (string=? build (derivation-file-name drv1))))))))))
937
938 (test-assert "derivation-build-plan and substitutes, local build"
939 (with-store store
940 (let* ((drv (build-expression->derivation store "prereq-subst-local"
941 (random 1000)
942 #:local-build? #t))
943 (output (derivation->output-path drv)))
944
945 ;; Make sure substitutes are usable.
946 (set-build-options store #:use-substitutes? #t
947 #:substitute-urls (%test-substitute-urls))
948
949 (with-derivation-narinfo drv
950 (let-values (((build download)
951 (derivation-build-plan store
952 (list (derivation-input drv)))))
953 ;; #:local-build? is *not* synonymous with #:substitutable?, so we
954 ;; must be able to substitute DRV's output.
955 ;; See <http://bugs.gnu.org/18747>.
956 (and (null? build)
957 (match download
958 (((= substitutable-path item))
959 (string=? item (derivation->output-path drv))))))))))
960
961 (test-assert "derivation-build-plan in 'check' mode"
962 (with-store store
963 (let* ((dep (build-expression->derivation store "dep"
964 `(begin ,(random-text)
965 (mkdir %output))))
966 (drv (build-expression->derivation store "to-check"
967 '(mkdir %output)
968 #:inputs `(("dep" ,dep)))))
969 (build-derivations store (list drv))
970 (delete-paths store (list (derivation->output-path dep)))
971
972 ;; In 'check' mode, DEP must be rebuilt.
973 (and (null? (derivation-build-plan store
974 (list (derivation-input drv))))
975 (lset= equal?
976 (derivation-build-plan store
977 (list (derivation-input drv))
978 #:mode (build-mode check))
979 (list drv dep))))))
980
981 (test-assert "substitution-oracle and #:substitute? #f"
982 (with-store store
983 (let* ((dep (build-expression->derivation store "dep"
984 `(begin ,(random-text)
985 (mkdir %output))))
986 (drv (build-expression->derivation store "not-subst"
987 `(begin ,(random-text)
988 (mkdir %output))
989 #:substitutable? #f
990 #:inputs `(("dep" ,dep))))
991 (query #f))
992 (define (record-substitutable-path-query store paths)
993 (when query
994 (error "already called!" query))
995 (set! query paths)
996 '())
997
998 (mock ((guix store) substitutable-path-info
999 record-substitutable-path-query)
1000
1001 (let ((pred (substitution-oracle store (list drv))))
1002 (pred (derivation->output-path drv))))
1003
1004 ;; Make sure the oracle didn't try to get substitute info for DRV since
1005 ;; DRV is mark as non-substitutable. Assume that GUILE-FOR-BUILD is
1006 ;; already in store and thus not part of QUERY.
1007 (equal? (pk 'query query)
1008 (list (derivation->output-path dep))))))
1009
1010 (test-assert "build-expression->derivation with expression returning #f"
1011 (let* ((builder '(begin
1012 (mkdir %output)
1013 #f)) ; fail!
1014 (drv (build-expression->derivation %store "fail" builder))
1015 (out-path (derivation->output-path drv)))
1016 (guard (c ((store-protocol-error? c)
1017 ;; Note that the output path may exist at this point, but it
1018 ;; is invalid.
1019 (and (string-match "build .* failed"
1020 (store-protocol-error-message c))
1021 (not (valid-path? %store out-path)))))
1022 (build-derivations %store (list drv))
1023 #f)))
1024
1025 (test-assert "build-expression->derivation with two outputs"
1026 (let* ((builder '(begin
1027 (call-with-output-file (assoc-ref %outputs "out")
1028 (lambda (p)
1029 (display '(hello) p)))
1030 (call-with-output-file (assoc-ref %outputs "second")
1031 (lambda (p)
1032 (display '(world) p)))))
1033 (drv (build-expression->derivation %store "double" builder
1034 #:outputs '("out"
1035 "second")))
1036 (succeeded? (build-derivations %store (list drv))))
1037 (and succeeded?
1038 (let ((one (derivation->output-path drv))
1039 (two (derivation->output-path drv "second")))
1040 (and (equal? '(hello) (call-with-input-file one read))
1041 (equal? '(world) (call-with-input-file two read)))))))
1042
1043 (test-skip (if %coreutils 0 1))
1044 (test-assert "build-expression->derivation with one input"
1045 (let* ((builder '(call-with-output-file %output
1046 (lambda (p)
1047 (let ((cu (assoc-ref %build-inputs "cu")))
1048 (close 1)
1049 (dup2 (port->fdes p) 1)
1050 (execl (string-append cu "/bin/uname")
1051 "uname" "-a")))))
1052 (drv (build-expression->derivation %store "uname" builder
1053 #:inputs
1054 `(("cu" ,%coreutils))))
1055 (succeeded? (build-derivations %store (list drv))))
1056 (and succeeded?
1057 (let ((p (derivation->output-path drv)))
1058 (string-contains (call-with-input-file p read-line) "GNU")))))
1059
1060 (test-assert "build-expression->derivation with modules"
1061 (let* ((builder `(begin
1062 (use-modules (guix build utils))
1063 (let ((out (assoc-ref %outputs "out")))
1064 (mkdir-p (string-append out "/guile/guix/nix"))
1065 #t)))
1066 (drv (build-expression->derivation %store "test-with-modules"
1067 builder
1068 #:modules
1069 '((guix build utils)))))
1070 (and (build-derivations %store (list drv))
1071 (let* ((p (derivation->output-path drv))
1072 (s (stat (string-append p "/guile/guix/nix"))))
1073 (eq? (stat:type s) 'directory)))))
1074
1075 (test-assert "build-expression->derivation: same fixed-output path"
1076 (let* ((builder1 '(call-with-output-file %output
1077 (lambda (p)
1078 (write "hello" p))))
1079 (builder2 '(call-with-output-file (pk 'difference-here! %output)
1080 (lambda (p)
1081 (write "hello" p))))
1082 (hash (sha256 (string->utf8 "hello")))
1083 (input1 (build-expression->derivation %store "fixed" builder1
1084 #:hash hash
1085 #:hash-algo 'sha256))
1086 (input2 (build-expression->derivation %store "fixed" builder2
1087 #:hash hash
1088 #:hash-algo 'sha256))
1089 (succeeded? (build-derivations %store (list input1 input2))))
1090 (and succeeded?
1091 (not (string=? (derivation-file-name input1)
1092 (derivation-file-name input2)))
1093 (string=? (derivation->output-path input1)
1094 (derivation->output-path input2)))))
1095
1096 (test-assert "build-expression->derivation with a fixed-output input"
1097 (let* ((builder1 '(call-with-output-file %output
1098 (lambda (p)
1099 (write "hello" p))))
1100 (builder2 '(call-with-output-file (pk 'difference-here! %output)
1101 (lambda (p)
1102 (write "hello" p))))
1103 (hash (sha256 (string->utf8 "hello")))
1104 (input1 (build-expression->derivation %store "fixed" builder1
1105 #:hash hash
1106 #:hash-algo 'sha256))
1107 (input2 (build-expression->derivation %store "fixed" builder2
1108 #:hash hash
1109 #:hash-algo 'sha256))
1110 (builder3 '(let ((input (assoc-ref %build-inputs "input")))
1111 (call-with-output-file %output
1112 (lambda (out)
1113 (format #f "My input is ~a.~%" input)))))
1114 (final1 (build-expression->derivation %store "final" builder3
1115 #:inputs
1116 `(("input" ,input1))))
1117 (final2 (build-expression->derivation %store "final" builder3
1118 #:inputs
1119 `(("input" ,input2)))))
1120 (and (string=? (derivation->output-path final1)
1121 (derivation->output-path final2))
1122 (string=? (derivation->output-path final1)
1123 (derivation-path->output-path
1124 (derivation-file-name final1)))
1125 (build-derivations %store (list final1 final2)))))
1126
1127 (test-assert "build-expression->derivation produces recursive fixed-output"
1128 (let* ((builder '(begin
1129 (use-modules (srfi srfi-26))
1130 (mkdir %output)
1131 (chdir %output)
1132 (call-with-output-file "exe"
1133 (cut display "executable" <>))
1134 (chmod "exe" #o777)
1135 (symlink "exe" "symlink")
1136 (mkdir "subdir")))
1137 (drv (build-expression->derivation %store "fixed-rec" builder
1138 #:hash-algo 'sha256
1139 #:hash (base32
1140 "10k1lw41wyrjf9mxydi0is5nkpynlsvgslinics4ppir13g7d74p")
1141 #:recursive? #t)))
1142 (and (build-derivations %store (list drv))
1143 (let* ((dir (derivation->output-path drv))
1144 (exe (string-append dir "/exe"))
1145 (link (string-append dir "/symlink"))
1146 (subdir (string-append dir "/subdir")))
1147 (and (executable-file? exe)
1148 (string=? "executable"
1149 (call-with-input-file exe get-string-all))
1150 (string=? "exe" (readlink link))
1151 (file-is-directory? subdir))))))
1152
1153 (test-assert "build-expression->derivation uses recursive fixed-output"
1154 (let* ((builder '(call-with-output-file %output
1155 (lambda (port)
1156 (display "hello" port))))
1157 (fixed (build-expression->derivation %store "small-fixed-rec"
1158 builder
1159 #:hash-algo 'sha256
1160 #:hash (base32
1161 "0sg9f58l1jj88w6pdrfdpj5x9b1zrwszk84j81zvby36q9whhhqa")
1162 #:recursive? #t))
1163 (in (derivation->output-path fixed))
1164 (builder `(begin
1165 (mkdir %output)
1166 (chdir %output)
1167 (symlink ,in "symlink")))
1168 (drv (build-expression->derivation %store "fixed-rec-user"
1169 builder
1170 #:inputs `(("fixed" ,fixed)))))
1171 (and (build-derivations %store (list drv))
1172 (let ((out (derivation->output-path drv)))
1173 (string=? (readlink (string-append out "/symlink")) in)))))
1174
1175 (test-assert "build-expression->derivation with #:references-graphs"
1176 (let* ((input (add-text-to-store %store "foo" "hello"
1177 (list %bash %mkdir)))
1178 (builder '(copy-file "input" %output))
1179 (drv (build-expression->derivation %store "references-graphs"
1180 builder
1181 #:references-graphs
1182 `(("input" . ,input))))
1183 (out (derivation->output-path drv)))
1184 (define (deps path . deps)
1185 (let ((count (length deps)))
1186 (string-append path "\n\n" (number->string count) "\n"
1187 (string-join (sort deps string<?) "\n")
1188 (if (zero? count) "" "\n"))))
1189
1190 (and (build-derivations %store (list drv))
1191 (equal? (call-with-input-file out get-string-all)
1192 (string-concatenate
1193 (map cdr
1194 (sort (map (lambda (p d)
1195 (cons p (apply deps p d)))
1196 (list input %bash %mkdir)
1197 (list (list %bash %mkdir)
1198 '() '()))
1199 (lambda (x y)
1200 (match x
1201 ((p1 . _)
1202 (match y
1203 ((p2 . _)
1204 (string<? p1 p2)))))))))))))
1205
1206 (test-equal "derivation-properties"
1207 (list '() '((type . test)))
1208 (let ((drv1 (build-expression->derivation %store "bar"
1209 '(mkdir %output)))
1210 (drv2 (build-expression->derivation %store "foo"
1211 '(mkdir %output)
1212 #:properties '((type . test)))))
1213 (list (derivation-properties drv1)
1214 (derivation-properties drv2))))
1215
1216 (test-equal "map-derivation"
1217 "hello"
1218 (let* ((joke (package-derivation %store guile-1.8))
1219 (good (package-derivation %store %bootstrap-guile))
1220 (drv1 (build-expression->derivation %store "original-drv1"
1221 #f ; systematically fail
1222 #:guile-for-build joke))
1223 (drv2 (build-expression->derivation %store "original-drv2"
1224 '(call-with-output-file %output
1225 (lambda (p)
1226 (display "hello" p)))))
1227 (drv3 (build-expression->derivation %store "drv-to-remap"
1228 '(let ((in (assoc-ref
1229 %build-inputs "in")))
1230 (copy-file in %output))
1231 #:inputs `(("in" ,drv1))
1232 #:guile-for-build joke))
1233 (drv4 (map-derivation %store drv3 `((,drv1 . ,drv2)
1234 (,joke . ,good))))
1235 (out (derivation->output-path drv4)))
1236 (and (build-derivations %store (list (pk 'remapped drv4)))
1237 (call-with-input-file out get-string-all))))
1238
1239 (test-equal "map-derivation, sources"
1240 "hello"
1241 (let* ((script1 (add-text-to-store %store "fail.sh" "exit 1"))
1242 (script2 (add-text-to-store %store "hi.sh" "echo -n hello > $out"))
1243 (bash-full (package-derivation %store (@ (gnu packages bash) bash)))
1244 (drv1 (derivation %store "drv-to-remap"
1245
1246 ;; XXX: This wouldn't work in practice, but if
1247 ;; we append "/bin/bash" then we can't replace
1248 ;; it with the bootstrap bash, which is a
1249 ;; single file.
1250 (derivation->output-path bash-full)
1251
1252 `("-e" ,script1)
1253 #:sources (list script1)
1254 #:inputs
1255 (list (derivation-input bash-full '("out")))))
1256 (drv2 (map-derivation %store drv1
1257 `((,bash-full . ,%bash)
1258 (,script1 . ,script2))))
1259 (out (derivation->output-path drv2)))
1260 (and (build-derivations %store (list (pk 'remapped* drv2)))
1261 (call-with-input-file out get-string-all))))
1262
1263 (test-end)
1264
1265 ;; Local Variables:
1266 ;; eval: (put 'with-http-server 'scheme-indent-function 2)
1267 ;; End: