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