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