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