gnu: Add asciinema.
[jackhill/guix/guix.git] / tests / packages.scm
CommitLineData
233e7676 1;;; GNU Guix --- Functional package management for GNU
7adf9b84 2;;; Copyright © 2012, 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
e3ce5d70 3;;;
233e7676 4;;; This file is part of GNU Guix.
e3ce5d70 5;;;
233e7676 6;;; GNU Guix is free software; you can redistribute it and/or modify it
e3ce5d70
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
e3ce5d70
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/>.
e3ce5d70 18
e3ce5d70 19(define-module (test-packages)
c1bc358f 20 #:use-module (guix tests)
e3ce5d70 21 #:use-module (guix store)
cf81a236 22 #:use-module (guix monads)
fcadd9ff 23 #:use-module (guix grafts)
da675305 24 #:use-module ((guix gexp) #:select (local-file local-file-file))
2e1bafb0
LC
25 #:use-module ((guix utils)
26 ;; Rename the 'location' binding to allow proper syntax
27 ;; matching when setting the 'location' field of a package.
28 #:renamer (lambda (name)
29 (cond ((eq? name 'location) 'make-location)
30 (else name))))
f9cc8971 31 #:use-module (guix hash)
e3ce5d70
LC
32 #:use-module (guix derivations)
33 #:use-module (guix packages)
7adf9b84 34 #:use-module (guix grafts)
aa8e0515 35 #:use-module (guix search-paths)
a18eda27 36 #:use-module (guix build-system)
be13fbfa 37 #:use-module (guix build-system trivial)
a3d73f59 38 #:use-module (guix build-system gnu)
cf81a236
LC
39 #:use-module (guix profiles)
40 #:use-module (guix scripts package)
59a43334 41 #:use-module (gnu packages)
1ffa7090 42 #:use-module (gnu packages base)
05962f29 43 #:use-module (gnu packages guile)
1ffa7090 44 #:use-module (gnu packages bootstrap)
cf81a236 45 #:use-module (gnu packages xml)
05962f29 46 #:use-module (srfi srfi-1)
6b1891b0 47 #:use-module (srfi srfi-26)
9b222abe 48 #:use-module (srfi srfi-34)
dbab5150 49 #:use-module (srfi srfi-35)
6b1891b0 50 #:use-module (srfi srfi-64)
860a6f1a 51 #:use-module (rnrs io ports)
2e1bafb0 52 #:use-module (ice-9 regex)
6b1891b0 53 #:use-module (ice-9 match))
e3ce5d70
LC
54
55;; Test the high-level packaging layer.
56
57(define %store
c1bc358f 58 (open-connection-for-tests))
e3ce5d70 59
b4c42a4b
LC
60;; Globally disable grafting to avoid rebuilding the world ('graft-derivation'
61;; can trigger builds early.)
62(%graft? #f)
63
05962f29
LC
64\f
65(test-begin "packages")
66
2e1bafb0 67(test-assert "printer with location"
74e667d1 68 (string-match "^#<package foo@0 foo.scm:42 [[:xdigit:]]+>$"
2e1bafb0
LC
69 (with-output-to-string
70 (lambda ()
71 (write
72 (dummy-package "foo"
73 (location (make-location "foo.scm" 42 7))))))))
74
75(test-assert "printer without location"
74e667d1 76 (string-match "^#<package foo@0 [[:xdigit:]]+>$"
2e1bafb0
LC
77 (with-output-to-string
78 (lambda ()
79 (write
80 (dummy-package "foo" (location #f)))))))
81
d66c7096
LC
82(test-assert "package-field-location"
83 (let ()
84 (define (goto port line column)
85 (unless (and (= (port-column port) (- column 1))
86 (= (port-line port) (- line 1)))
87 (unless (eof-object? (get-char port))
88 (goto port line column))))
89
90 (define read-at
91 (match-lambda
92 (($ <location> file line column)
93 (call-with-input-file (search-path %load-path file)
94 (lambda (port)
95 (goto port line column)
96 (read port))))))
97
ee48b283
LC
98 ;; Until Guile 2.0.6 included, source properties were added only to pairs.
99 ;; Thus, check against both VALUE and (FIELD VALUE).
100 (and (member (read-at (package-field-location %bootstrap-guile 'name))
101 (let ((name (package-name %bootstrap-guile)))
102 (list name `(name ,name))))
103 (member (read-at (package-field-location %bootstrap-guile 'version))
104 (let ((version (package-version %bootstrap-guile)))
105 (list version `(version ,version))))
f903dc05 106 (not (package-field-location %bootstrap-guile 'does-not-exist)))))
d66c7096 107
0b8749b7
LC
108;; Make sure we don't change the file name to an absolute file name.
109(test-equal "package-field-location, relative file name"
110 (location-file (package-location %bootstrap-guile))
111 (with-fluids ((%file-port-name-canonicalization 'absolute))
112 (location-file (package-field-location %bootstrap-guile 'version))))
113
a3d73f59
LC
114(test-assert "package-transitive-inputs"
115 (let* ((a (dummy-package "a"))
116 (b (dummy-package "b"
117 (propagated-inputs `(("a" ,a)))))
118 (c (dummy-package "c"
119 (inputs `(("a" ,a)))))
120 (d (dummy-package "d"
121 (propagated-inputs `(("x" "something.drv")))))
122 (e (dummy-package "e"
123 (inputs `(("b" ,b) ("c" ,c) ("d" ,d))))))
124 (and (null? (package-transitive-inputs a))
125 (equal? `(("a" ,a)) (package-transitive-inputs b))
126 (equal? `(("a" ,a)) (package-transitive-inputs c))
127 (equal? (package-propagated-inputs d)
128 (package-transitive-inputs d))
161094c8
LC
129 (equal? `(("b" ,b) ("c" ,c) ("d" ,d)
130 ("a" ,a) ("x" "something.drv"))
a3d73f59
LC
131 (pk 'x (package-transitive-inputs e))))))
132
161094c8
LC
133(test-assert "package-transitive-inputs, no duplicates"
134 (let* ((a (dummy-package "a"))
135 (b (dummy-package "b"
136 (inputs `(("a+" ,a)))
137 (native-inputs `(("a*" ,a)))
138 (propagated-inputs `(("a" ,a)))))
139 (c (dummy-package "c"
140 (propagated-inputs `(("b" ,b)))))
141 (d (dummy-package "d"
142 (inputs `(("a" ,a) ("c" ,c)))))
143 (e (dummy-package "e"
144 (inputs `(("b" ,b) ("c" ,c))))))
145 (and (null? (package-transitive-inputs a))
146 (equal? `(("a*" ,a) ("a+" ,a) ("a" ,a)) ;here duplicates are kept
147 (package-transitive-inputs b))
148 (equal? `(("b" ,b) ("a" ,a))
149 (package-transitive-inputs c))
150 (equal? `(("a" ,a) ("c" ,c) ("b" ,b)) ;duplicate A removed
151 (package-transitive-inputs d))
152 (equal? `(("b" ,b) ("c" ,c) ("a" ,a))
153 (package-transitive-inputs e))))) ;ditto
154
7c3c0374 155(test-equal "package-transitive-supported-systems"
c37a74bd
LC
156 '(("x" "y" "z") ;a
157 ("x" "y") ;b
158 ("y") ;c
159 ("y") ;d
160 ("y")) ;e
9bf3ced0
LC
161 ;; Use TRIVIAL-BUILD-SYSTEM because it doesn't add implicit inputs and thus
162 ;; doesn't restrict the set of supported systems.
163 (let* ((a (dummy-package "a"
164 (build-system trivial-build-system)
165 (supported-systems '("x" "y" "z"))))
166 (b (dummy-package "b"
167 (build-system trivial-build-system)
168 (supported-systems '("x" "y"))
169 (inputs `(("a" ,a)))))
170 (c (dummy-package "c"
171 (build-system trivial-build-system)
172 (supported-systems '("y" "z"))
173 (inputs `(("b" ,b)))))
174 (d (dummy-package "d"
175 (build-system trivial-build-system)
176 (supported-systems '("x" "y" "z"))
177 (inputs `(("b" ,b) ("c" ,c)))))
178 (e (dummy-package "e"
179 (build-system trivial-build-system)
180 (supported-systems '("x" "y" "z"))
181 (inputs `(("d" ,d))))))
7c3c0374
LC
182 (list (package-transitive-supported-systems a)
183 (package-transitive-supported-systems b)
c37a74bd
LC
184 (package-transitive-supported-systems c)
185 (package-transitive-supported-systems d)
186 (package-transitive-supported-systems e))))
7c3c0374 187
3b4d0103
EB
188(test-equal "origin-actual-file-name"
189 "foo-1.tar.gz"
190 (let ((o (dummy-origin (uri "http://www.example.com/foo-1.tar.gz"))))
191 (origin-actual-file-name o)))
192
193(test-equal "origin-actual-file-name, file-name"
194 "foo-1.tar.gz"
195 (let ((o (dummy-origin
196 (uri "http://www.example.com/tarball")
197 (file-name "foo-1.tar.gz"))))
198 (origin-actual-file-name o)))
199
f77bcbc3
EB
200(let* ((o (dummy-origin))
201 (u (dummy-origin))
202 (i (dummy-origin))
203 (a (dummy-package "a"))
204 (b (dummy-package "b"
205 (inputs `(("a" ,a) ("i" ,i)))))
206 (c (package (inherit b) (source o)))
207 (d (dummy-package "d"
208 (build-system trivial-build-system)
209 (source u) (inputs `(("c" ,c))))))
210 (test-assert "package-direct-sources, no source"
211 (null? (package-direct-sources a)))
212 (test-equal "package-direct-sources, #f source"
213 (list i)
214 (package-direct-sources b))
215 (test-equal "package-direct-sources, not input source"
216 (list u)
217 (package-direct-sources d))
218 (test-assert "package-direct-sources"
219 (let ((s (package-direct-sources c)))
220 (and (= (length (pk 's-sources s)) 2)
221 (member o s)
222 (member i s))))
223 (test-assert "package-transitive-sources"
224 (let ((s (package-transitive-sources d)))
225 (and (= (length (pk 'd-sources s)) 3)
226 (member o s)
227 (member i s)
228 (member u s)))))
229
a6d0b306
EB
230(test-assert "transitive-input-references"
231 (let* ((a (dummy-package "a"))
232 (b (dummy-package "b"))
233 (c (dummy-package "c"
234 (inputs `(("a" ,a)))
235 (propagated-inputs `(("boo" ,b)))))
236 (d (dummy-package "d"
237 (inputs `(("c*" ,c)))))
238 (keys (map (match-lambda
239 (('assoc-ref 'l key)
240 key))
241 (pk 'refs (transitive-input-references
242 'l (package-inputs d))))))
243 (and (= (length keys) 2)
244 (member "c*" keys)
245 (member "boo" keys))))
246
9bf3ced0
LC
247(test-equal "package-transitive-supported-systems, implicit inputs"
248 %supported-systems
249
250 ;; Here GNU-BUILD-SYSTEM adds implicit inputs that build only on
251 ;; %SUPPORTED-SYSTEMS. Thus the others must be ignored.
252 (let ((p (dummy-package "foo"
253 (build-system gnu-build-system)
254 (supported-systems
255 `("does-not-exist" "foobar" ,@%supported-systems)))))
256 (package-transitive-supported-systems p)))
257
bbceb0ef
LC
258(test-assert "supported-package?"
259 (let ((p (dummy-package "foo"
260 (build-system gnu-build-system)
261 (supported-systems '("x86_64-linux" "does-not-exist")))))
262 (and (supported-package? p "x86_64-linux")
263 (not (supported-package? p "does-not-exist"))
264 (not (supported-package? p "i686-linux")))))
265
7357138b
LC
266(test-skip (if (not %store) 8 0))
267
268(test-assert "package-source-derivation, file"
269 (let* ((file (search-path %load-path "guix.scm"))
270 (package (package (inherit (dummy-package "p"))
271 (source file)))
272 (source (package-source-derivation %store
273 (package-source package))))
274 (and (store-path? source)
275 (valid-path? %store source)
276 (equal? (call-with-input-file source get-bytevector-all)
277 (call-with-input-file file get-bytevector-all)))))
278
279(test-assert "package-source-derivation, store path"
280 (let* ((file (add-to-store %store "guix.scm" #t "sha256"
281 (search-path %load-path "guix.scm")))
282 (package (package (inherit (dummy-package "p"))
283 (source file)))
284 (source (package-source-derivation %store
285 (package-source package))))
286 (string=? file source)))
e509d152 287
f80594cc
LC
288(test-assert "package-source-derivation, indirect store path"
289 (let* ((dir (add-to-store %store "guix-build" #t "sha256"
290 (dirname (search-path %load-path
291 "guix/build/utils.scm"))))
292 (package (package (inherit (dummy-package "p"))
293 (source (string-append dir "/utils.scm"))))
294 (source (package-source-derivation %store
295 (package-source package))))
296 (and (direct-store-path? source)
297 (string-suffix? "utils.scm" source))))
298
da675305
LC
299(test-assert "package-source-derivation, local-file"
300 (let* ((file (local-file "../guix/base32.scm"))
301 (package (package (inherit (dummy-package "p"))
302 (source file)))
303 (source (package-source-derivation %store
304 (package-source package))))
305 (and (store-path? source)
306 (string-suffix? "base32.scm" source)
307 (valid-path? %store source)
308 (equal? (call-with-input-file source get-bytevector-all)
309 (call-with-input-file
310 (search-path %load-path "guix/base32.scm")
311 get-bytevector-all)))))
312
12d720fd 313(unless (network-reachable?) (test-skip 1))
f9cc8971
LC
314(test-equal "package-source-derivation, snippet"
315 "OK"
5cfc17cb
MW
316 (let* ((file (search-bootstrap-binary (match (%current-system)
317 ("armhf-linux"
318 "guile-2.0.11.tar.xz")
319 (_
320 "guile-2.0.9.tar.xz"))
f9cc8971
LC
321 (%current-system)))
322 (sha256 (call-with-input-file file port-sha256))
f220a838 323 (fetch (lambda* (url hash-algo hash
f9cc8971
LC
324 #:optional name #:key system)
325 (pk 'fetch url hash-algo hash name system)
f220a838 326 (interned-file url)))
f9cc8971
LC
327 (source (bootstrap-origin
328 (origin
329 (method fetch)
330 (uri file)
331 (sha256 sha256)
332 (patch-inputs
333 `(("tar" ,%bootstrap-coreutils&co)
334 ("xz" ,%bootstrap-coreutils&co)
335 ("patch" ,%bootstrap-coreutils&co)))
7db9608d 336 (patch-guile %bootstrap-guile)
f9cc8971 337 (modules '((guix build utils)))
f9cc8971
LC
338 (snippet '(begin
339 ;; We end up in 'bin', because it's the first
340 ;; directory, alphabetically. Not a very good
341 ;; example but hey.
342 (chmod "." #o777)
343 (symlink "guile" "guile-rocks")
344 (copy-recursively "../share/guile/2.0/scripts"
d6445dff
LC
345 "scripts")
346
347 ;; Make sure '.file_list' can be created.
348 (chmod ".." #o777))))))
f9cc8971
LC
349 (package (package (inherit (dummy-package "with-snippet"))
350 (source source)
351 (build-system trivial-build-system)
352 (inputs
353 `(("tar" ,(search-bootstrap-binary "tar"
354 (%current-system)))
355 ("xz" ,(search-bootstrap-binary "xz"
356 (%current-system)))))
357 (arguments
358 `(#:guile ,%bootstrap-guile
359 #:builder
360 (let ((tar (assoc-ref %build-inputs "tar"))
361 (xz (assoc-ref %build-inputs "xz"))
362 (source (assoc-ref %build-inputs "source")))
363 (and (zero? (system* tar "xvf" source
364 "--use-compress-program" xz))
365 (string=? "guile" (readlink "bin/guile-rocks"))
366 (file-exists? "bin/scripts/compile.scm")
367 (let ((out (assoc-ref %outputs "out")))
368 (call-with-output-file out
369 (lambda (p)
370 (display "OK" p))))))))))
371 (drv (package-derivation %store package))
372 (out (derivation->output-path drv)))
373 (and (build-derivations %store (list (pk 'snippet-drv drv)))
374 (call-with-input-file out get-string-all))))
375
59688fc4
LC
376(test-assert "return value"
377 (let ((drv (package-derivation %store (dummy-package "p"))))
378 (and (derivation? drv)
379 (file-exists? (derivation-file-name drv)))))
be13fbfa 380
d510ab46
LC
381(test-assert "package-output"
382 (let* ((package (dummy-package "p"))
59688fc4
LC
383 (drv (package-derivation %store package)))
384 (and (derivation? drv)
385 (string=? (derivation->output-path drv)
d510ab46
LC
386 (package-output %store package "out")))))
387
dbab5150
LC
388(test-assert "patch not found yields a run-time error"
389 (guard (c ((condition-has-type? c &message)
390 (and (string-contains (condition-message c)
391 "does-not-exist.patch")
392 (string-contains (condition-message c)
393 "not found"))))
394 (let ((p (package
395 (inherit (dummy-package "p"))
396 (source (origin
397 (method (const #f))
398 (uri "http://whatever")
399 (patches
400 (list (search-patch "does-not-exist.patch")))
401 (sha256
402 (base32
403 "0amn0bbwqvsvvsh6drfwz20ydc2czk374lzw5kksbh6bf78k4ks4")))))))
404 (package-derivation %store p)
405 #f)))
406
f304c9c2
LC
407(test-assert "reference to non-existent output"
408 ;; See <http://bugs.gnu.org/19630>.
862abf8f
LC
409 (parameterize ((%graft? #f))
410 (let* ((dep (dummy-package "dep"))
411 (p (dummy-package "p"
412 (inputs `(("dep" ,dep "non-existent"))))))
413 (guard (c ((derivation-missing-output-error? c)
414 (and (string=? (derivation-missing-output c) "non-existent")
415 (equal? (package-derivation %store dep)
416 (derivation-error-derivation c)))))
417 (package-derivation %store p)))))
f304c9c2 418
be13fbfa
LC
419(test-assert "trivial"
420 (let* ((p (package (inherit (dummy-package "trivial"))
421 (build-system trivial-build-system)
422 (source #f)
423 (arguments
14da91e2
LC
424 `(#:guile ,%bootstrap-guile
425 #:builder
be13fbfa
LC
426 (begin
427 (mkdir %output)
428 (call-with-output-file (string-append %output "/test")
429 (lambda (p)
430 (display '(hello guix) p))))))))
431 (d (package-derivation %store p)))
432 (and (build-derivations %store (list d))
59688fc4 433 (let ((p (pk 'drv d (derivation->output-path d))))
be13fbfa
LC
434 (equal? '(hello guix)
435 (call-with-input-file (string-append p "/test") read))))))
e3ce5d70 436
860a6f1a
LC
437(test-assert "trivial with local file as input"
438 (let* ((i (search-path %load-path "ice-9/boot-9.scm"))
439 (p (package (inherit (dummy-package "trivial-with-input-file"))
440 (build-system trivial-build-system)
441 (source #f)
442 (arguments
443 `(#:guile ,%bootstrap-guile
444 #:builder (copy-file (assoc-ref %build-inputs "input")
445 %output)))
446 (inputs `(("input" ,i)))))
447 (d (package-derivation %store p)))
448 (and (build-derivations %store (list d))
59688fc4 449 (let ((p (pk 'drv d (derivation->output-path d))))
860a6f1a
LC
450 (equal? (call-with-input-file p get-bytevector-all)
451 (call-with-input-file i get-bytevector-all))))))
452
03761a44
LC
453(test-assert "trivial with source"
454 (let* ((i (search-path %load-path "ice-9/boot-9.scm"))
455 (p (package (inherit (dummy-package "trivial-with-source"))
456 (build-system trivial-build-system)
457 (source i)
458 (arguments
459 `(#:guile ,%bootstrap-guile
460 #:builder (copy-file (assoc-ref %build-inputs "source")
461 %output)))))
462 (d (package-derivation %store p)))
463 (and (build-derivations %store (list d))
464 (let ((p (derivation->output-path d)))
465 (equal? (call-with-input-file p get-bytevector-all)
466 (call-with-input-file i get-bytevector-all))))))
467
592ef6c8
LC
468(test-assert "trivial with system-dependent input"
469 (let* ((p (package (inherit (dummy-package "trivial-system-dependent-input"))
470 (build-system trivial-build-system)
471 (source #f)
472 (arguments
473 `(#:guile ,%bootstrap-guile
474 #:builder
475 (let ((out (assoc-ref %outputs "out"))
476 (bash (assoc-ref %build-inputs "bash")))
477 (zero? (system* bash "-c"
478 (format #f "echo hello > ~a" out))))))
dd6b9a37
LC
479 (inputs `(("bash" ,(search-bootstrap-binary "bash"
480 (%current-system)))))))
592ef6c8
LC
481 (d (package-derivation %store p)))
482 (and (build-derivations %store (list d))
59688fc4 483 (let ((p (pk 'drv d (derivation->output-path d))))
592ef6c8
LC
484 (eq? 'hello (call-with-input-file p read))))))
485
a18eda27
LC
486(test-assert "search paths"
487 (let* ((p (make-prompt-tag "return-search-paths"))
488 (s (build-system
0d5a559f 489 (name 'raw)
a18eda27 490 (description "Raw build system with direct store access")
d3d337d2
LC
491 (lower (lambda* (name #:key source inputs system target
492 #:allow-other-keys)
0d5a559f
LC
493 (bag
494 (name name)
d3d337d2 495 (system system) (target target)
0d5a559f
LC
496 (build-inputs inputs)
497 (build
498 (lambda* (store name inputs
499 #:key outputs system search-paths)
500 search-paths)))))))
a18eda27
LC
501 (x (list (search-path-specification
502 (variable "GUILE_LOAD_PATH")
af070955 503 (files '("share/guile/site/2.0")))
a18eda27
LC
504 (search-path-specification
505 (variable "GUILE_LOAD_COMPILED_PATH")
af070955 506 (files '("share/guile/site/2.0")))))
a18eda27
LC
507 (a (package (inherit (dummy-package "guile"))
508 (build-system s)
509 (native-search-paths x)))
510 (b (package (inherit (dummy-package "guile-foo"))
511 (build-system s)
512 (inputs `(("guile" ,a)))))
513 (c (package (inherit (dummy-package "guile-bar"))
514 (build-system s)
515 (inputs `(("guile" ,a)
516 ("guile-foo" ,b))))))
517 (let-syntax ((collect (syntax-rules ()
518 ((_ body ...)
519 (call-with-prompt p
520 (lambda ()
521 body ...)
522 (lambda (k search-paths)
523 search-paths))))))
524 (and (null? (collect (package-derivation %store a)))
525 (equal? x (collect (package-derivation %store b)))
526 (equal? x (collect (package-derivation %store c)))))))
527
aa8e0515
LC
528(test-assert "package-transitive-native-search-paths"
529 (let* ((sp (lambda (name)
530 (list (search-path-specification
531 (variable name)
532 (files '("foo/bar"))))))
533 (p0 (dummy-package "p0" (native-search-paths (sp "PATH0"))))
534 (p1 (dummy-package "p1" (native-search-paths (sp "PATH1"))))
535 (p2 (dummy-package "p2"
536 (native-search-paths (sp "PATH2"))
537 (inputs `(("p0" ,p0)))
538 (propagated-inputs `(("p1" ,p1)))))
539 (p3 (dummy-package "p3"
540 (native-search-paths (sp "PATH3"))
541 (native-inputs `(("p0" ,p0)))
542 (propagated-inputs `(("p2" ,p2))))))
543 (lset= string=?
544 '("PATH1" "PATH2" "PATH3")
545 (map search-path-specification-variable
546 (package-transitive-native-search-paths p3)))))
547
9c1edabd 548(test-assert "package-cross-derivation"
59688fc4
LC
549 (let ((drv (package-cross-derivation %store (dummy-package "p")
550 "mips64el-linux-gnu")))
551 (and (derivation? drv)
552 (file-exists? (derivation-file-name drv)))))
9c1edabd 553
5dce8218
LC
554(test-assert "package-cross-derivation, trivial-build-system"
555 (let ((p (package (inherit (dummy-package "p"))
556 (build-system trivial-build-system)
557 (arguments '(#:builder (exit 1))))))
59688fc4
LC
558 (let ((drv (package-cross-derivation %store p "mips64el-linux-gnu")))
559 (derivation? drv))))
5dce8218 560
9b222abe
LC
561(test-assert "package-cross-derivation, no cross builder"
562 (let* ((b (build-system (inherit trivial-build-system)
0d5a559f 563 (lower (const #f))))
9b222abe
LC
564 (p (package (inherit (dummy-package "p"))
565 (build-system b))))
566 (guard (c ((package-cross-build-system-error? c)
567 (eq? (package-error-package c) p)))
568 (package-cross-derivation %store p "mips64el-linux-gnu")
569 #f)))
570
b4c42a4b
LC
571;; XXX: The next two tests can trigger builds when the distro defines
572;; replacements on core packages, so they're disable for lack of a better
573;; solution.
574
575;; (test-equal "package-derivation, direct graft"
576;; (package-derivation %store gnu-make #:graft? #f)
577;; (let ((p (package (inherit coreutils)
578;; (replacement gnu-make))))
579;; (package-derivation %store p #:graft? #t)))
05962f29 580
b4c42a4b
LC
581;; (test-equal "package-cross-derivation, direct graft"
582;; (package-cross-derivation %store gnu-make "mips64el-linux-gnu"
583;; #:graft? #f)
584;; (let ((p (package (inherit coreutils)
585;; (replacement gnu-make))))
586;; (package-cross-derivation %store p "mips64el-linux-gnu"
587;; #:graft? #t)))
05962f29
LC
588
589(test-assert "package-grafts, indirect grafts"
590 (let* ((new (dummy-package "dep"
591 (arguments '(#:implicit-inputs? #f))))
592 (dep (package (inherit new) (version "0.0")))
593 (dep* (package (inherit dep) (replacement new)))
594 (dummy (dummy-package "dummy"
595 (arguments '(#:implicit-inputs? #f))
596 (inputs `(("dep" ,dep*))))))
597 (equal? (package-grafts %store dummy)
598 (list (graft
599 (origin (package-derivation %store dep))
600 (replacement (package-derivation %store new)))))))
601
602(test-assert "package-grafts, indirect grafts, cross"
603 (let* ((new (dummy-package "dep"
604 (arguments '(#:implicit-inputs? #f))))
605 (dep (package (inherit new) (version "0.0")))
606 (dep* (package (inherit dep) (replacement new)))
607 (dummy (dummy-package "dummy"
608 (arguments '(#:implicit-inputs? #f))
609 (inputs `(("dep" ,dep*)))))
610 (target "mips64el-linux-gnu"))
b4c42a4b
LC
611 ;; XXX: There might be additional grafts, for instance if the distro
612 ;; defines replacements for core packages like Perl.
613 (member (graft
614 (origin (package-cross-derivation %store dep target))
615 (replacement
616 (package-cross-derivation %store new target)))
617 (package-grafts %store dummy #:target target))))
05962f29
LC
618
619(test-assert "package-grafts, indirect grafts, propagated inputs"
620 (let* ((new (dummy-package "dep"
621 (arguments '(#:implicit-inputs? #f))))
622 (dep (package (inherit new) (version "0.0")))
623 (dep* (package (inherit dep) (replacement new)))
624 (prop (dummy-package "propagated"
625 (propagated-inputs `(("dep" ,dep*)))
626 (arguments '(#:implicit-inputs? #f))))
627 (dummy (dummy-package "dummy"
628 (arguments '(#:implicit-inputs? #f))
629 (inputs `(("prop" ,prop))))))
630 (equal? (package-grafts %store dummy)
631 (list (graft
632 (origin (package-derivation %store dep))
633 (replacement (package-derivation %store new)))))))
634
fcadd9ff
LC
635(test-assert "package-grafts, same replacement twice"
636 (let* ((new (dummy-package "dep"
637 (version "1")
638 (arguments '(#:implicit-inputs? #f))))
639 (dep (package (inherit new) (version "0") (replacement new)))
640 (p1 (dummy-package "intermediate1"
641 (arguments '(#:implicit-inputs? #f))
642 (inputs `(("dep" ,dep)))))
643 (p2 (dummy-package "intermediate2"
644 (arguments '(#:implicit-inputs? #f))
645 ;; Here we copy DEP to have an equivalent package that is not
646 ;; 'eq?' to DEP. This is similar to what happens with
647 ;; 'package-with-explicit-inputs' & co.
648 (inputs `(("dep" ,(package (inherit dep)))))))
649 (p3 (dummy-package "final"
650 (arguments '(#:implicit-inputs? #f))
651 (inputs `(("p1" ,p1) ("p2" ,p2))))))
652 (equal? (package-grafts %store p3)
653 (list (graft
654 (origin (package-derivation %store
655 (package (inherit dep)
656 (replacement #f))))
657 (replacement (package-derivation %store new)))))))
658
c22a1324
LC
659;;; XXX: Nowadays 'graft-derivation' needs to build derivations beforehand to
660;;; find out about their run-time dependencies, so this test is no longer
661;;; applicable since it would trigger a full rebuild.
662;;
663;; (test-assert "package-derivation, indirect grafts"
664;; (let* ((new (dummy-package "dep"
665;; (arguments '(#:implicit-inputs? #f))))
666;; (dep (package (inherit new) (version "0.0")))
667;; (dep* (package (inherit dep) (replacement new)))
668;; (dummy (dummy-package "dummy"
669;; (arguments '(#:implicit-inputs? #f))
670;; (inputs `(("dep" ,dep*)))))
671;; (guile (package-derivation %store (canonical-package guile-2.0)
672;; #:graft? #f)))
673;; (equal? (package-derivation %store dummy)
674;; (graft-derivation %store
675;; (package-derivation %store dummy #:graft? #f)
676;; (package-grafts %store dummy)
677
678;; ;; Use the same Guile as 'package-derivation'.
679;; #:guile guile))))
05962f29 680
d3d337d2
LC
681(test-equal "package->bag"
682 `("foo86-hurd" #f (,(package-source gnu-make))
683 (,(canonical-package glibc)) (,(canonical-package coreutils)))
684 (let ((bag (package->bag gnu-make "foo86-hurd")))
685 (list (bag-system bag) (bag-target bag)
686 (assoc-ref (bag-build-inputs bag) "source")
687 (assoc-ref (bag-build-inputs bag) "libc")
688 (assoc-ref (bag-build-inputs bag) "coreutils"))))
689
690(test-equal "package->bag, cross-compilation"
691 `(,(%current-system) "foo86-hurd"
692 (,(package-source gnu-make))
693 (,(canonical-package glibc)) (,(canonical-package coreutils)))
694 (let ((bag (package->bag gnu-make (%current-system) "foo86-hurd")))
695 (list (bag-system bag) (bag-target bag)
696 (assoc-ref (bag-build-inputs bag) "source")
697 (assoc-ref (bag-build-inputs bag) "libc")
698 (assoc-ref (bag-build-inputs bag) "coreutils"))))
699
50373bab
LC
700(test-assert "package->bag, propagated inputs"
701 (let* ((dep (dummy-package "dep"))
702 (prop (dummy-package "prop"
703 (propagated-inputs `(("dep" ,dep)))))
704 (dummy (dummy-package "dummy"
705 (inputs `(("prop" ,prop)))))
706 (inputs (bag-transitive-inputs (package->bag dummy #:graft? #f))))
161094c8
LC
707 (match (assoc "dep" inputs)
708 (("dep" package)
50373bab
LC
709 (eq? package dep)))))
710
d3d337d2 711(test-assert "bag->derivation"
05962f29
LC
712 (parameterize ((%graft? #f))
713 (let ((bag (package->bag gnu-make))
714 (drv (package-derivation %store gnu-make)))
715 (parameterize ((%current-system "foox86-hurd")) ;should have no effect
716 (equal? drv (bag->derivation %store bag))))))
d3d337d2
LC
717
718(test-assert "bag->derivation, cross-compilation"
05962f29
LC
719 (parameterize ((%graft? #f))
720 (let* ((target "mips64el-linux-gnu")
721 (bag (package->bag gnu-make (%current-system) target))
722 (drv (package-cross-derivation %store gnu-make target)))
723 (parameterize ((%current-system "foox86-hurd") ;should have no effect
724 (%current-target-system "foo64-linux-gnu"))
725 (equal? drv (bag->derivation %store bag))))))
d3d337d2 726
b69c5c2c
LC
727(when (or (not (network-reachable?)) (shebang-too-long?))
728 (test-skip 1))
9e782349
LC
729(test-assert "GNU Make, bootstrap"
730 ;; GNU Make is the first program built during bootstrap; we choose it
731 ;; here so that the test doesn't last for too long.
bdb36958 732 (let ((gnu-make (@@ (gnu packages commencement) gnu-make-boot0)))
9e782349
LC
733 (and (package? gnu-make)
734 (or (location? (package-location gnu-make))
735 (not (package-location gnu-make)))
736 (let* ((drv (package-derivation %store gnu-make))
59688fc4 737 (out (derivation->output-path drv)))
14da91e2 738 (and (build-derivations %store (list drv))
9e782349 739 (file-exists? (string-append out "/bin/make")))))))
e3ce5d70 740
ba326ce4
LC
741(test-eq "fold-packages" hello
742 (fold-packages (lambda (p r)
743 (if (string=? (package-name p) "hello")
744 p
745 r))
746 #f))
747
6b1891b0
LC
748(test-assert "find-packages-by-name"
749 (match (find-packages-by-name "hello")
750 (((? (cut eq? hello <>))) #t)
751 (wrong (pk 'find-packages-by-name wrong #f))))
752
753(test-assert "find-packages-by-name with version"
754 (match (find-packages-by-name "hello" (package-version hello))
755 (((? (cut eq? hello <>))) #t)
756 (wrong (pk 'find-packages-by-name wrong #f))))
757
cf81a236
LC
758(test-assert "--search-paths with pattern"
759 ;; Make sure 'guix package --search-paths' correctly reports environment
760 ;; variables when file patterns are used (in particular, it must follow
761 ;; symlinks when looking for 'catalog.xml'.) To do that, we rely on the
762 ;; libxml2 package specification, which contains such a definition.
763 (let* ((p1 (package
764 (name "foo") (version "0") (source #f)
765 (build-system trivial-build-system)
766 (arguments
767 `(#:guile ,%bootstrap-guile
768 #:modules ((guix build utils))
769 #:builder (begin
770 (use-modules (guix build utils))
771 (let ((out (assoc-ref %outputs "out")))
772 (mkdir-p (string-append out "/xml/bar/baz"))
773 (call-with-output-file
774 (string-append out "/xml/bar/baz/catalog.xml")
775 (lambda (port)
776 (display "xml? wat?!" port)))))))
777 (synopsis #f) (description #f)
778 (home-page #f) (license #f)))
779 (p2 (package
780 ;; Provide a fake libxml2 to avoid building the real one. This
781 ;; is OK because 'guix package' gets search path specifications
782 ;; from the same-named package found in the distro.
783 (name "libxml2") (version "0.0.0") (source #f)
784 (build-system trivial-build-system)
785 (arguments
786 `(#:guile ,%bootstrap-guile
787 #:builder (mkdir (assoc-ref %outputs "out"))))
788 (native-search-paths (package-native-search-paths libxml2))
789 (synopsis #f) (description #f)
790 (home-page #f) (license #f)))
791 (prof (run-with-store %store
792 (profile-derivation
793 (manifest (map package->manifest-entry
794 (list p1 p2)))
aa46a028 795 #:hooks '())
cf81a236
LC
796 #:guile-for-build (%guile-for-build))))
797 (build-derivations %store (list prof))
798 (string-match (format #f "^export XML_CATALOG_FILES=\"~a/xml/+bar/baz/catalog\\.xml\"\n"
77559f23 799 (regexp-quote (derivation->output-path prof)))
cf81a236
LC
800 (with-output-to-string
801 (lambda ()
802 (guix-package "-p" (derivation->output-path prof)
803 "--search-paths"))))))
804
efb107e0
LC
805(test-equal "specification->package when not found"
806 'quit
807 (catch 'quit
808 (lambda ()
809 ;; This should call 'leave', producing an error message.
810 (specification->package "this-package-does-not-exist"))
811 (lambda (key . args)
812 key)))
813
e3ce5d70
LC
814(test-end "packages")
815
e3ce5d70 816;;; Local Variables:
a3d73f59 817;;; eval: (put 'dummy-package 'scheme-indent-function 1)
e3ce5d70 818;;; End: