gnu: Use invoke and return #t from all builders.
[jackhill/guix/guix.git] / tests / packages.scm
CommitLineData
233e7676 1;;; GNU Guix --- Functional package management for GNU
29760251 2;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018 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)
fcd75bdb 45 #:use-module (gnu packages version-control)
cf81a236 46 #:use-module (gnu packages xml)
05962f29 47 #:use-module (srfi srfi-1)
6b1891b0 48 #:use-module (srfi srfi-26)
9b222abe 49 #:use-module (srfi srfi-34)
dbab5150 50 #:use-module (srfi srfi-35)
6b1891b0 51 #:use-module (srfi srfi-64)
860a6f1a 52 #:use-module (rnrs io ports)
5239f3d9 53 #:use-module (ice-9 vlist)
2e1bafb0 54 #:use-module (ice-9 regex)
6b1891b0 55 #:use-module (ice-9 match))
e3ce5d70
LC
56
57;; Test the high-level packaging layer.
58
59(define %store
c1bc358f 60 (open-connection-for-tests))
e3ce5d70 61
b4c42a4b
LC
62;; Globally disable grafting to avoid rebuilding the world ('graft-derivation'
63;; can trigger builds early.)
64(%graft? #f)
65
05962f29
LC
66\f
67(test-begin "packages")
68
2e1bafb0 69(test-assert "printer with location"
74e667d1 70 (string-match "^#<package foo@0 foo.scm:42 [[:xdigit:]]+>$"
2e1bafb0
LC
71 (with-output-to-string
72 (lambda ()
73 (write
74 (dummy-package "foo"
75 (location (make-location "foo.scm" 42 7))))))))
76
77(test-assert "printer without location"
74e667d1 78 (string-match "^#<package foo@0 [[:xdigit:]]+>$"
2e1bafb0
LC
79 (with-output-to-string
80 (lambda ()
81 (write
82 (dummy-package "foo" (location #f)))))))
83
6980511b
LC
84(test-assert "hidden-package"
85 (and (hidden-package? (hidden-package (dummy-package "foo")))
86 (not (hidden-package? (dummy-package "foo")))))
87
01afdab8
LC
88(test-assert "package-superseded"
89 (let* ((new (dummy-package "bar"))
90 (old (deprecated-package "foo" new)))
91 (and (eq? (package-superseded old) new)
92 (mock ((gnu packages) find-best-packages-by-name (const (list old)))
93 (specification->package "foo")
94 (and (eq? new (specification->package "foo"))
95 (eq? new (specification->package+output "foo")))))))
96
5239f3d9
LC
97(test-assert "transaction-upgrade-entry, zero upgrades"
98 (let* ((old (dummy-package "foo" (version "1")))
99 (tx (mock ((gnu packages) find-newest-available-packages
100 (const vlist-null))
101 ((@@ (guix scripts package) transaction-upgrade-entry)
102 (manifest-entry
103 (inherit (package->manifest-entry old))
104 (item (string-append (%store-prefix) "/"
105 (make-string 32 #\e) "-foo-1")))
106 (manifest-transaction)))))
107 (manifest-transaction-null? tx)))
108
109(test-assert "transaction-upgrade-entry, one upgrade"
110 (let* ((old (dummy-package "foo" (version "1")))
111 (new (dummy-package "foo" (version "2")))
112 (tx (mock ((gnu packages) find-newest-available-packages
113 (const (vhash-cons "foo" (list "2" new) vlist-null)))
114 ((@@ (guix scripts package) transaction-upgrade-entry)
115 (manifest-entry
116 (inherit (package->manifest-entry old))
117 (item (string-append (%store-prefix) "/"
118 (make-string 32 #\e) "-foo-1")))
119 (manifest-transaction)))))
120 (and (match (manifest-transaction-install tx)
121 ((($ <manifest-entry> "foo" "2" "out" item))
122 (eq? item new)))
123 (null? (manifest-transaction-remove tx)))))
124
01afdab8
LC
125(test-assert "transaction-upgrade-entry, superseded package"
126 (let* ((old (dummy-package "foo" (version "1")))
127 (new (dummy-package "bar" (version "2")))
128 (dep (deprecated-package "foo" new))
129 (tx (mock ((gnu packages) find-newest-available-packages
130 (const (vhash-cons "foo" (list "2" dep) vlist-null)))
131 ((@@ (guix scripts package) transaction-upgrade-entry)
132 (manifest-entry
133 (inherit (package->manifest-entry old))
134 (item (string-append (%store-prefix) "/"
135 (make-string 32 #\e) "-foo-1")))
136 (manifest-transaction)))))
137 (and (match (manifest-transaction-install tx)
138 ((($ <manifest-entry> "bar" "2" "out" item))
139 (eq? item new)))
140 (match (manifest-transaction-remove tx)
141 (((? manifest-pattern? pattern))
142 (and (string=? (manifest-pattern-name pattern) "foo")
143 (string=? (manifest-pattern-version pattern) "1")
144 (string=? (manifest-pattern-output pattern) "out")))))))
145
d66c7096
LC
146(test-assert "package-field-location"
147 (let ()
148 (define (goto port line column)
149 (unless (and (= (port-column port) (- column 1))
150 (= (port-line port) (- line 1)))
151 (unless (eof-object? (get-char port))
152 (goto port line column))))
153
154 (define read-at
155 (match-lambda
156 (($ <location> file line column)
157 (call-with-input-file (search-path %load-path file)
158 (lambda (port)
159 (goto port line column)
160 (read port))))))
161
ee48b283
LC
162 ;; Until Guile 2.0.6 included, source properties were added only to pairs.
163 ;; Thus, check against both VALUE and (FIELD VALUE).
164 (and (member (read-at (package-field-location %bootstrap-guile 'name))
165 (let ((name (package-name %bootstrap-guile)))
166 (list name `(name ,name))))
167 (member (read-at (package-field-location %bootstrap-guile 'version))
168 (let ((version (package-version %bootstrap-guile)))
169 (list version `(version ,version))))
f903dc05 170 (not (package-field-location %bootstrap-guile 'does-not-exist)))))
d66c7096 171
0b8749b7
LC
172;; Make sure we don't change the file name to an absolute file name.
173(test-equal "package-field-location, relative file name"
174 (location-file (package-location %bootstrap-guile))
175 (with-fluids ((%file-port-name-canonicalization 'absolute))
176 (location-file (package-field-location %bootstrap-guile 'version))))
177
a3d73f59
LC
178(test-assert "package-transitive-inputs"
179 (let* ((a (dummy-package "a"))
180 (b (dummy-package "b"
181 (propagated-inputs `(("a" ,a)))))
182 (c (dummy-package "c"
183 (inputs `(("a" ,a)))))
184 (d (dummy-package "d"
185 (propagated-inputs `(("x" "something.drv")))))
186 (e (dummy-package "e"
187 (inputs `(("b" ,b) ("c" ,c) ("d" ,d))))))
188 (and (null? (package-transitive-inputs a))
189 (equal? `(("a" ,a)) (package-transitive-inputs b))
190 (equal? `(("a" ,a)) (package-transitive-inputs c))
191 (equal? (package-propagated-inputs d)
192 (package-transitive-inputs d))
161094c8
LC
193 (equal? `(("b" ,b) ("c" ,c) ("d" ,d)
194 ("a" ,a) ("x" "something.drv"))
a3d73f59
LC
195 (pk 'x (package-transitive-inputs e))))))
196
161094c8
LC
197(test-assert "package-transitive-inputs, no duplicates"
198 (let* ((a (dummy-package "a"))
199 (b (dummy-package "b"
200 (inputs `(("a+" ,a)))
201 (native-inputs `(("a*" ,a)))
202 (propagated-inputs `(("a" ,a)))))
203 (c (dummy-package "c"
204 (propagated-inputs `(("b" ,b)))))
205 (d (dummy-package "d"
206 (inputs `(("a" ,a) ("c" ,c)))))
207 (e (dummy-package "e"
208 (inputs `(("b" ,b) ("c" ,c))))))
209 (and (null? (package-transitive-inputs a))
210 (equal? `(("a*" ,a) ("a+" ,a) ("a" ,a)) ;here duplicates are kept
211 (package-transitive-inputs b))
212 (equal? `(("b" ,b) ("a" ,a))
213 (package-transitive-inputs c))
214 (equal? `(("a" ,a) ("c" ,c) ("b" ,b)) ;duplicate A removed
215 (package-transitive-inputs d))
216 (equal? `(("b" ,b) ("c" ,c) ("a" ,a))
217 (package-transitive-inputs e))))) ;ditto
218
7c3c0374 219(test-equal "package-transitive-supported-systems"
c37a74bd
LC
220 '(("x" "y" "z") ;a
221 ("x" "y") ;b
222 ("y") ;c
223 ("y") ;d
224 ("y")) ;e
9bf3ced0
LC
225 ;; Use TRIVIAL-BUILD-SYSTEM because it doesn't add implicit inputs and thus
226 ;; doesn't restrict the set of supported systems.
227 (let* ((a (dummy-package "a"
228 (build-system trivial-build-system)
229 (supported-systems '("x" "y" "z"))))
230 (b (dummy-package "b"
231 (build-system trivial-build-system)
232 (supported-systems '("x" "y"))
233 (inputs `(("a" ,a)))))
234 (c (dummy-package "c"
235 (build-system trivial-build-system)
236 (supported-systems '("y" "z"))
237 (inputs `(("b" ,b)))))
238 (d (dummy-package "d"
239 (build-system trivial-build-system)
240 (supported-systems '("x" "y" "z"))
241 (inputs `(("b" ,b) ("c" ,c)))))
242 (e (dummy-package "e"
243 (build-system trivial-build-system)
244 (supported-systems '("x" "y" "z"))
245 (inputs `(("d" ,d))))))
7c3c0374
LC
246 (list (package-transitive-supported-systems a)
247 (package-transitive-supported-systems b)
c37a74bd
LC
248 (package-transitive-supported-systems c)
249 (package-transitive-supported-systems d)
250 (package-transitive-supported-systems e))))
7c3c0374 251
3b4d0103
EB
252(test-equal "origin-actual-file-name"
253 "foo-1.tar.gz"
254 (let ((o (dummy-origin (uri "http://www.example.com/foo-1.tar.gz"))))
255 (origin-actual-file-name o)))
256
257(test-equal "origin-actual-file-name, file-name"
258 "foo-1.tar.gz"
259 (let ((o (dummy-origin
260 (uri "http://www.example.com/tarball")
261 (file-name "foo-1.tar.gz"))))
262 (origin-actual-file-name o)))
263
f77bcbc3
EB
264(let* ((o (dummy-origin))
265 (u (dummy-origin))
266 (i (dummy-origin))
267 (a (dummy-package "a"))
268 (b (dummy-package "b"
269 (inputs `(("a" ,a) ("i" ,i)))))
270 (c (package (inherit b) (source o)))
271 (d (dummy-package "d"
272 (build-system trivial-build-system)
273 (source u) (inputs `(("c" ,c))))))
274 (test-assert "package-direct-sources, no source"
275 (null? (package-direct-sources a)))
276 (test-equal "package-direct-sources, #f source"
277 (list i)
278 (package-direct-sources b))
279 (test-equal "package-direct-sources, not input source"
280 (list u)
281 (package-direct-sources d))
282 (test-assert "package-direct-sources"
283 (let ((s (package-direct-sources c)))
284 (and (= (length (pk 's-sources s)) 2)
285 (member o s)
286 (member i s))))
287 (test-assert "package-transitive-sources"
288 (let ((s (package-transitive-sources d)))
289 (and (= (length (pk 'd-sources s)) 3)
290 (member o s)
291 (member i s)
292 (member u s)))))
293
a6d0b306
EB
294(test-assert "transitive-input-references"
295 (let* ((a (dummy-package "a"))
296 (b (dummy-package "b"))
297 (c (dummy-package "c"
298 (inputs `(("a" ,a)))
299 (propagated-inputs `(("boo" ,b)))))
300 (d (dummy-package "d"
301 (inputs `(("c*" ,c)))))
302 (keys (map (match-lambda
303 (('assoc-ref 'l key)
304 key))
305 (pk 'refs (transitive-input-references
306 'l (package-inputs d))))))
307 (and (= (length keys) 2)
308 (member "c*" keys)
309 (member "boo" keys))))
310
9bf3ced0
LC
311(test-equal "package-transitive-supported-systems, implicit inputs"
312 %supported-systems
313
314 ;; Here GNU-BUILD-SYSTEM adds implicit inputs that build only on
315 ;; %SUPPORTED-SYSTEMS. Thus the others must be ignored.
316 (let ((p (dummy-package "foo"
317 (build-system gnu-build-system)
318 (supported-systems
319 `("does-not-exist" "foobar" ,@%supported-systems)))))
320 (package-transitive-supported-systems p)))
321
bbceb0ef
LC
322(test-assert "supported-package?"
323 (let ((p (dummy-package "foo"
324 (build-system gnu-build-system)
325 (supported-systems '("x86_64-linux" "does-not-exist")))))
326 (and (supported-package? p "x86_64-linux")
327 (not (supported-package? p "does-not-exist"))
328 (not (supported-package? p "i686-linux")))))
329
7357138b
LC
330(test-skip (if (not %store) 8 0))
331
332(test-assert "package-source-derivation, file"
333 (let* ((file (search-path %load-path "guix.scm"))
334 (package (package (inherit (dummy-package "p"))
335 (source file)))
336 (source (package-source-derivation %store
337 (package-source package))))
338 (and (store-path? source)
339 (valid-path? %store source)
340 (equal? (call-with-input-file source get-bytevector-all)
341 (call-with-input-file file get-bytevector-all)))))
342
343(test-assert "package-source-derivation, store path"
344 (let* ((file (add-to-store %store "guix.scm" #t "sha256"
345 (search-path %load-path "guix.scm")))
346 (package (package (inherit (dummy-package "p"))
347 (source file)))
348 (source (package-source-derivation %store
349 (package-source package))))
350 (string=? file source)))
e509d152 351
f80594cc
LC
352(test-assert "package-source-derivation, indirect store path"
353 (let* ((dir (add-to-store %store "guix-build" #t "sha256"
354 (dirname (search-path %load-path
355 "guix/build/utils.scm"))))
356 (package (package (inherit (dummy-package "p"))
357 (source (string-append dir "/utils.scm"))))
358 (source (package-source-derivation %store
359 (package-source package))))
360 (and (direct-store-path? source)
361 (string-suffix? "utils.scm" source))))
362
da675305
LC
363(test-assert "package-source-derivation, local-file"
364 (let* ((file (local-file "../guix/base32.scm"))
365 (package (package (inherit (dummy-package "p"))
366 (source file)))
367 (source (package-source-derivation %store
368 (package-source package))))
369 (and (store-path? source)
370 (string-suffix? "base32.scm" source)
371 (valid-path? %store source)
372 (equal? (call-with-input-file source get-bytevector-all)
373 (call-with-input-file
374 (search-path %load-path "guix/base32.scm")
375 get-bytevector-all)))))
376
12d720fd 377(unless (network-reachable?) (test-skip 1))
f9cc8971
LC
378(test-equal "package-source-derivation, snippet"
379 "OK"
f8ec8d96 380 (let* ((source (bootstrap-origin
f9cc8971 381 (origin
f8ec8d96 382 (inherit (bootstrap-guile-origin (%current-system)))
f9cc8971
LC
383 (patch-inputs
384 `(("tar" ,%bootstrap-coreutils&co)
385 ("xz" ,%bootstrap-coreutils&co)
386 ("patch" ,%bootstrap-coreutils&co)))
7db9608d 387 (patch-guile %bootstrap-guile)
f9cc8971 388 (modules '((guix build utils)))
f9cc8971
LC
389 (snippet '(begin
390 ;; We end up in 'bin', because it's the first
391 ;; directory, alphabetically. Not a very good
392 ;; example but hey.
393 (chmod "." #o777)
394 (symlink "guile" "guile-rocks")
395 (copy-recursively "../share/guile/2.0/scripts"
d6445dff
LC
396 "scripts")
397
398 ;; Make sure '.file_list' can be created.
399 (chmod ".." #o777))))))
f9cc8971
LC
400 (package (package (inherit (dummy-package "with-snippet"))
401 (source source)
402 (build-system trivial-build-system)
403 (inputs
404 `(("tar" ,(search-bootstrap-binary "tar"
405 (%current-system)))
406 ("xz" ,(search-bootstrap-binary "xz"
407 (%current-system)))))
408 (arguments
409 `(#:guile ,%bootstrap-guile
410 #:builder
411 (let ((tar (assoc-ref %build-inputs "tar"))
412 (xz (assoc-ref %build-inputs "xz"))
413 (source (assoc-ref %build-inputs "source")))
414 (and (zero? (system* tar "xvf" source
415 "--use-compress-program" xz))
416 (string=? "guile" (readlink "bin/guile-rocks"))
417 (file-exists? "bin/scripts/compile.scm")
418 (let ((out (assoc-ref %outputs "out")))
419 (call-with-output-file out
420 (lambda (p)
421 (display "OK" p))))))))))
422 (drv (package-derivation %store package))
423 (out (derivation->output-path drv)))
424 (and (build-derivations %store (list (pk 'snippet-drv drv)))
425 (call-with-input-file out get-string-all))))
426
59688fc4
LC
427(test-assert "return value"
428 (let ((drv (package-derivation %store (dummy-package "p"))))
429 (and (derivation? drv)
430 (file-exists? (derivation-file-name drv)))))
be13fbfa 431
d510ab46
LC
432(test-assert "package-output"
433 (let* ((package (dummy-package "p"))
59688fc4
LC
434 (drv (package-derivation %store package)))
435 (and (derivation? drv)
436 (string=? (derivation->output-path drv)
d510ab46
LC
437 (package-output %store package "out")))))
438
dbab5150
LC
439(test-assert "patch not found yields a run-time error"
440 (guard (c ((condition-has-type? c &message)
441 (and (string-contains (condition-message c)
442 "does-not-exist.patch")
443 (string-contains (condition-message c)
444 "not found"))))
445 (let ((p (package
446 (inherit (dummy-package "p"))
447 (source (origin
448 (method (const #f))
449 (uri "http://whatever")
450 (patches
451 (list (search-patch "does-not-exist.patch")))
452 (sha256
453 (base32
454 "0amn0bbwqvsvvsh6drfwz20ydc2czk374lzw5kksbh6bf78k4ks4")))))))
455 (package-derivation %store p)
456 #f)))
457
76c48619
LC
458(let ((dummy (dummy-package "foo" (inputs `(("x" ,(current-module)))))))
459 (test-equal "&package-input-error"
460 (list dummy (current-module))
461 (guard (c ((package-input-error? c)
462 (list (package-error-package c)
463 (package-error-invalid-input c))))
464 (package-derivation %store dummy))))
465
f304c9c2
LC
466(test-assert "reference to non-existent output"
467 ;; See <http://bugs.gnu.org/19630>.
862abf8f
LC
468 (parameterize ((%graft? #f))
469 (let* ((dep (dummy-package "dep"))
470 (p (dummy-package "p"
471 (inputs `(("dep" ,dep "non-existent"))))))
472 (guard (c ((derivation-missing-output-error? c)
473 (and (string=? (derivation-missing-output c) "non-existent")
474 (equal? (package-derivation %store dep)
475 (derivation-error-derivation c)))))
476 (package-derivation %store p)))))
f304c9c2 477
be13fbfa
LC
478(test-assert "trivial"
479 (let* ((p (package (inherit (dummy-package "trivial"))
480 (build-system trivial-build-system)
481 (source #f)
482 (arguments
14da91e2
LC
483 `(#:guile ,%bootstrap-guile
484 #:builder
be13fbfa
LC
485 (begin
486 (mkdir %output)
487 (call-with-output-file (string-append %output "/test")
488 (lambda (p)
489 (display '(hello guix) p))))))))
490 (d (package-derivation %store p)))
491 (and (build-derivations %store (list d))
59688fc4 492 (let ((p (pk 'drv d (derivation->output-path d))))
be13fbfa
LC
493 (equal? '(hello guix)
494 (call-with-input-file (string-append p "/test") read))))))
e3ce5d70 495
860a6f1a
LC
496(test-assert "trivial with local file as input"
497 (let* ((i (search-path %load-path "ice-9/boot-9.scm"))
498 (p (package (inherit (dummy-package "trivial-with-input-file"))
499 (build-system trivial-build-system)
500 (source #f)
501 (arguments
502 `(#:guile ,%bootstrap-guile
503 #:builder (copy-file (assoc-ref %build-inputs "input")
504 %output)))
505 (inputs `(("input" ,i)))))
506 (d (package-derivation %store p)))
507 (and (build-derivations %store (list d))
59688fc4 508 (let ((p (pk 'drv d (derivation->output-path d))))
860a6f1a
LC
509 (equal? (call-with-input-file p get-bytevector-all)
510 (call-with-input-file i get-bytevector-all))))))
511
03761a44
LC
512(test-assert "trivial with source"
513 (let* ((i (search-path %load-path "ice-9/boot-9.scm"))
514 (p (package (inherit (dummy-package "trivial-with-source"))
515 (build-system trivial-build-system)
516 (source i)
517 (arguments
518 `(#:guile ,%bootstrap-guile
519 #:builder (copy-file (assoc-ref %build-inputs "source")
520 %output)))))
521 (d (package-derivation %store p)))
522 (and (build-derivations %store (list d))
523 (let ((p (derivation->output-path d)))
524 (equal? (call-with-input-file p get-bytevector-all)
525 (call-with-input-file i get-bytevector-all))))))
526
592ef6c8
LC
527(test-assert "trivial with system-dependent input"
528 (let* ((p (package (inherit (dummy-package "trivial-system-dependent-input"))
529 (build-system trivial-build-system)
530 (source #f)
531 (arguments
532 `(#:guile ,%bootstrap-guile
533 #:builder
534 (let ((out (assoc-ref %outputs "out"))
535 (bash (assoc-ref %build-inputs "bash")))
536 (zero? (system* bash "-c"
537 (format #f "echo hello > ~a" out))))))
dd6b9a37
LC
538 (inputs `(("bash" ,(search-bootstrap-binary "bash"
539 (%current-system)))))))
592ef6c8
LC
540 (d (package-derivation %store p)))
541 (and (build-derivations %store (list d))
59688fc4 542 (let ((p (pk 'drv d (derivation->output-path d))))
592ef6c8
LC
543 (eq? 'hello (call-with-input-file p read))))))
544
29760251
LC
545(test-assert "trivial with #:allowed-references"
546 (let* ((p (package
547 (inherit (dummy-package "trivial"))
548 (build-system trivial-build-system)
549 (arguments
550 `(#:guile ,%bootstrap-guile
551 #:allowed-references (,%bootstrap-guile)
552 #:builder
553 (begin
554 (mkdir %output)
555 ;; The reference to itself isn't allowed so building it
556 ;; should fail.
557 (symlink %output (string-append %output "/self")))))))
558 (d (package-derivation %store p)))
559 (guard (c ((nix-protocol-error? c) #t))
560 (build-derivations %store (list d))
561 #f)))
562
a18eda27
LC
563(test-assert "search paths"
564 (let* ((p (make-prompt-tag "return-search-paths"))
565 (s (build-system
0d5a559f 566 (name 'raw)
a18eda27 567 (description "Raw build system with direct store access")
d3d337d2
LC
568 (lower (lambda* (name #:key source inputs system target
569 #:allow-other-keys)
0d5a559f
LC
570 (bag
571 (name name)
d3d337d2 572 (system system) (target target)
0d5a559f
LC
573 (build-inputs inputs)
574 (build
575 (lambda* (store name inputs
576 #:key outputs system search-paths)
577 search-paths)))))))
a18eda27
LC
578 (x (list (search-path-specification
579 (variable "GUILE_LOAD_PATH")
af070955 580 (files '("share/guile/site/2.0")))
a18eda27
LC
581 (search-path-specification
582 (variable "GUILE_LOAD_COMPILED_PATH")
af070955 583 (files '("share/guile/site/2.0")))))
a18eda27
LC
584 (a (package (inherit (dummy-package "guile"))
585 (build-system s)
586 (native-search-paths x)))
587 (b (package (inherit (dummy-package "guile-foo"))
588 (build-system s)
589 (inputs `(("guile" ,a)))))
590 (c (package (inherit (dummy-package "guile-bar"))
591 (build-system s)
592 (inputs `(("guile" ,a)
593 ("guile-foo" ,b))))))
594 (let-syntax ((collect (syntax-rules ()
595 ((_ body ...)
596 (call-with-prompt p
597 (lambda ()
598 body ...)
599 (lambda (k search-paths)
600 search-paths))))))
601 (and (null? (collect (package-derivation %store a)))
602 (equal? x (collect (package-derivation %store b)))
603 (equal? x (collect (package-derivation %store c)))))))
604
aa8e0515
LC
605(test-assert "package-transitive-native-search-paths"
606 (let* ((sp (lambda (name)
607 (list (search-path-specification
608 (variable name)
609 (files '("foo/bar"))))))
610 (p0 (dummy-package "p0" (native-search-paths (sp "PATH0"))))
611 (p1 (dummy-package "p1" (native-search-paths (sp "PATH1"))))
612 (p2 (dummy-package "p2"
613 (native-search-paths (sp "PATH2"))
614 (inputs `(("p0" ,p0)))
615 (propagated-inputs `(("p1" ,p1)))))
616 (p3 (dummy-package "p3"
617 (native-search-paths (sp "PATH3"))
618 (native-inputs `(("p0" ,p0)))
619 (propagated-inputs `(("p2" ,p2))))))
620 (lset= string=?
621 '("PATH1" "PATH2" "PATH3")
622 (map search-path-specification-variable
623 (package-transitive-native-search-paths p3)))))
624
9c1edabd 625(test-assert "package-cross-derivation"
59688fc4
LC
626 (let ((drv (package-cross-derivation %store (dummy-package "p")
627 "mips64el-linux-gnu")))
628 (and (derivation? drv)
629 (file-exists? (derivation-file-name drv)))))
9c1edabd 630
5dce8218
LC
631(test-assert "package-cross-derivation, trivial-build-system"
632 (let ((p (package (inherit (dummy-package "p"))
633 (build-system trivial-build-system)
634 (arguments '(#:builder (exit 1))))))
59688fc4
LC
635 (let ((drv (package-cross-derivation %store p "mips64el-linux-gnu")))
636 (derivation? drv))))
5dce8218 637
9b222abe
LC
638(test-assert "package-cross-derivation, no cross builder"
639 (let* ((b (build-system (inherit trivial-build-system)
0d5a559f 640 (lower (const #f))))
9b222abe
LC
641 (p (package (inherit (dummy-package "p"))
642 (build-system b))))
643 (guard (c ((package-cross-build-system-error? c)
644 (eq? (package-error-package c) p)))
645 (package-cross-derivation %store p "mips64el-linux-gnu")
646 #f)))
647
b4c42a4b
LC
648;; XXX: The next two tests can trigger builds when the distro defines
649;; replacements on core packages, so they're disable for lack of a better
650;; solution.
651
652;; (test-equal "package-derivation, direct graft"
653;; (package-derivation %store gnu-make #:graft? #f)
654;; (let ((p (package (inherit coreutils)
655;; (replacement gnu-make))))
656;; (package-derivation %store p #:graft? #t)))
05962f29 657
b4c42a4b
LC
658;; (test-equal "package-cross-derivation, direct graft"
659;; (package-cross-derivation %store gnu-make "mips64el-linux-gnu"
660;; #:graft? #f)
661;; (let ((p (package (inherit coreutils)
662;; (replacement gnu-make))))
663;; (package-cross-derivation %store p "mips64el-linux-gnu"
664;; #:graft? #t)))
05962f29
LC
665
666(test-assert "package-grafts, indirect grafts"
667 (let* ((new (dummy-package "dep"
668 (arguments '(#:implicit-inputs? #f))))
669 (dep (package (inherit new) (version "0.0")))
670 (dep* (package (inherit dep) (replacement new)))
671 (dummy (dummy-package "dummy"
672 (arguments '(#:implicit-inputs? #f))
673 (inputs `(("dep" ,dep*))))))
674 (equal? (package-grafts %store dummy)
675 (list (graft
676 (origin (package-derivation %store dep))
677 (replacement (package-derivation %store new)))))))
678
d0025d01
LC
679;; XXX: This test would require building the cross toolchain just to see if it
680;; needs grafting, which is obviously too expensive, and thus disabled.
681;;
682;; (test-assert "package-grafts, indirect grafts, cross"
683;; (let* ((new (dummy-package "dep"
684;; (arguments '(#:implicit-inputs? #f))))
685;; (dep (package (inherit new) (version "0.0")))
686;; (dep* (package (inherit dep) (replacement new)))
687;; (dummy (dummy-package "dummy"
688;; (arguments '(#:implicit-inputs? #f))
689;; (inputs `(("dep" ,dep*)))))
690;; (target "mips64el-linux-gnu"))
691;; ;; XXX: There might be additional grafts, for instance if the distro
692;; ;; defines replacements for core packages like Perl.
693;; (member (graft
694;; (origin (package-cross-derivation %store dep target))
695;; (replacement
696;; (package-cross-derivation %store new target)))
697;; (package-grafts %store dummy #:target target))))
05962f29
LC
698
699(test-assert "package-grafts, indirect grafts, propagated inputs"
700 (let* ((new (dummy-package "dep"
701 (arguments '(#:implicit-inputs? #f))))
702 (dep (package (inherit new) (version "0.0")))
703 (dep* (package (inherit dep) (replacement new)))
704 (prop (dummy-package "propagated"
705 (propagated-inputs `(("dep" ,dep*)))
706 (arguments '(#:implicit-inputs? #f))))
707 (dummy (dummy-package "dummy"
708 (arguments '(#:implicit-inputs? #f))
709 (inputs `(("prop" ,prop))))))
710 (equal? (package-grafts %store dummy)
711 (list (graft
712 (origin (package-derivation %store dep))
713 (replacement (package-derivation %store new)))))))
714
fcadd9ff
LC
715(test-assert "package-grafts, same replacement twice"
716 (let* ((new (dummy-package "dep"
717 (version "1")
718 (arguments '(#:implicit-inputs? #f))))
719 (dep (package (inherit new) (version "0") (replacement new)))
720 (p1 (dummy-package "intermediate1"
721 (arguments '(#:implicit-inputs? #f))
722 (inputs `(("dep" ,dep)))))
723 (p2 (dummy-package "intermediate2"
724 (arguments '(#:implicit-inputs? #f))
725 ;; Here we copy DEP to have an equivalent package that is not
726 ;; 'eq?' to DEP. This is similar to what happens with
727 ;; 'package-with-explicit-inputs' & co.
728 (inputs `(("dep" ,(package (inherit dep)))))))
729 (p3 (dummy-package "final"
730 (arguments '(#:implicit-inputs? #f))
731 (inputs `(("p1" ,p1) ("p2" ,p2))))))
732 (equal? (package-grafts %store p3)
733 (list (graft
734 (origin (package-derivation %store
735 (package (inherit dep)
736 (replacement #f))))
737 (replacement (package-derivation %store new)))))))
738
d0025d01
LC
739(test-assert "replacement also grafted"
740 ;; We build a DAG as below, where dotted arrows represent replacements and
741 ;; solid arrows represent dependencies:
742 ;;
743 ;; P1 ·············> P1R
744 ;; |\__________________.
745 ;; v v
746 ;; P2 ·············> P2R
747 ;; |
748 ;; v
749 ;; P3
750 ;;
751 ;; We want to make sure that:
752 ;; grafts(P3) = (P1,P1R) + (P2, grafted(P2R, (P1,P1R)))
753 ;; where:
754 ;; (A,B) is a graft to replace A by B
755 ;; grafted(DRV,G) denoted DRV with graft G applied
756 (let* ((p1r (dummy-package "P1"
757 (build-system trivial-build-system)
758 (arguments
759 `(#:guile ,%bootstrap-guile
760 #:builder (let ((out (assoc-ref %outputs "out")))
761 (mkdir out)
762 (call-with-output-file
763 (string-append out "/replacement")
764 (const #t)))))))
765 (p1 (package
766 (inherit p1r) (name "p1") (replacement p1r)
767 (arguments
768 `(#:guile ,%bootstrap-guile
769 #:builder (mkdir (assoc-ref %outputs "out"))))))
770 (p2r (dummy-package "P2"
771 (build-system trivial-build-system)
772 (inputs `(("p1" ,p1)))
773 (arguments
774 `(#:guile ,%bootstrap-guile
775 #:builder (let ((out (assoc-ref %outputs "out")))
776 (mkdir out)
777 (chdir out)
778 (symlink (assoc-ref %build-inputs "p1") "p1")
779 (call-with-output-file (string-append out "/replacement")
780 (const #t)))))))
781 (p2 (package
782 (inherit p2r) (name "p2") (replacement p2r)
783 (arguments
784 `(#:guile ,%bootstrap-guile
785 #:builder (let ((out (assoc-ref %outputs "out")))
786 (mkdir out)
787 (chdir out)
788 (symlink (assoc-ref %build-inputs "p1")
789 "p1"))))))
790 (p3 (dummy-package "p3"
791 (build-system trivial-build-system)
792 (inputs `(("p2" ,p2)))
793 (arguments
794 `(#:guile ,%bootstrap-guile
795 #:builder (let ((out (assoc-ref %outputs "out")))
796 (mkdir out)
797 (chdir out)
798 (symlink (assoc-ref %build-inputs "p2")
799 "p2")))))))
800 (lset= equal?
801 (package-grafts %store p3)
802 (list (graft
803 (origin (package-derivation %store p1 #:graft? #f))
804 (replacement (package-derivation %store p1r)))
805 (graft
806 (origin (package-derivation %store p2 #:graft? #f))
807 (replacement
808 (package-derivation %store p2r #:graft? #t)))))))
809
c22a1324
LC
810;;; XXX: Nowadays 'graft-derivation' needs to build derivations beforehand to
811;;; find out about their run-time dependencies, so this test is no longer
812;;; applicable since it would trigger a full rebuild.
813;;
814;; (test-assert "package-derivation, indirect grafts"
815;; (let* ((new (dummy-package "dep"
816;; (arguments '(#:implicit-inputs? #f))))
817;; (dep (package (inherit new) (version "0.0")))
818;; (dep* (package (inherit dep) (replacement new)))
819;; (dummy (dummy-package "dummy"
820;; (arguments '(#:implicit-inputs? #f))
821;; (inputs `(("dep" ,dep*)))))
822;; (guile (package-derivation %store (canonical-package guile-2.0)
823;; #:graft? #f)))
824;; (equal? (package-derivation %store dummy)
825;; (graft-derivation %store
826;; (package-derivation %store dummy #:graft? #f)
827;; (package-grafts %store dummy)
828
829;; ;; Use the same Guile as 'package-derivation'.
830;; #:guile guile))))
05962f29 831
d3d337d2
LC
832(test-equal "package->bag"
833 `("foo86-hurd" #f (,(package-source gnu-make))
834 (,(canonical-package glibc)) (,(canonical-package coreutils)))
835 (let ((bag (package->bag gnu-make "foo86-hurd")))
836 (list (bag-system bag) (bag-target bag)
837 (assoc-ref (bag-build-inputs bag) "source")
838 (assoc-ref (bag-build-inputs bag) "libc")
839 (assoc-ref (bag-build-inputs bag) "coreutils"))))
840
841(test-equal "package->bag, cross-compilation"
842 `(,(%current-system) "foo86-hurd"
843 (,(package-source gnu-make))
844 (,(canonical-package glibc)) (,(canonical-package coreutils)))
845 (let ((bag (package->bag gnu-make (%current-system) "foo86-hurd")))
846 (list (bag-system bag) (bag-target bag)
847 (assoc-ref (bag-build-inputs bag) "source")
848 (assoc-ref (bag-build-inputs bag) "libc")
849 (assoc-ref (bag-build-inputs bag) "coreutils"))))
850
50373bab
LC
851(test-assert "package->bag, propagated inputs"
852 (let* ((dep (dummy-package "dep"))
853 (prop (dummy-package "prop"
854 (propagated-inputs `(("dep" ,dep)))))
855 (dummy (dummy-package "dummy"
856 (inputs `(("prop" ,prop)))))
857 (inputs (bag-transitive-inputs (package->bag dummy #:graft? #f))))
161094c8
LC
858 (match (assoc "dep" inputs)
859 (("dep" package)
50373bab
LC
860 (eq? package dep)))))
861
d3d337d2 862(test-assert "bag->derivation"
05962f29
LC
863 (parameterize ((%graft? #f))
864 (let ((bag (package->bag gnu-make))
865 (drv (package-derivation %store gnu-make)))
866 (parameterize ((%current-system "foox86-hurd")) ;should have no effect
867 (equal? drv (bag->derivation %store bag))))))
d3d337d2
LC
868
869(test-assert "bag->derivation, cross-compilation"
05962f29
LC
870 (parameterize ((%graft? #f))
871 (let* ((target "mips64el-linux-gnu")
872 (bag (package->bag gnu-make (%current-system) target))
873 (drv (package-cross-derivation %store gnu-make target)))
874 (parameterize ((%current-system "foox86-hurd") ;should have no effect
875 (%current-target-system "foo64-linux-gnu"))
876 (equal? drv (bag->derivation %store bag))))))
d3d337d2 877
b69c5c2c
LC
878(when (or (not (network-reachable?)) (shebang-too-long?))
879 (test-skip 1))
9e782349
LC
880(test-assert "GNU Make, bootstrap"
881 ;; GNU Make is the first program built during bootstrap; we choose it
882 ;; here so that the test doesn't last for too long.
bdb36958 883 (let ((gnu-make (@@ (gnu packages commencement) gnu-make-boot0)))
9e782349
LC
884 (and (package? gnu-make)
885 (or (location? (package-location gnu-make))
886 (not (package-location gnu-make)))
887 (let* ((drv (package-derivation %store gnu-make))
59688fc4 888 (out (derivation->output-path drv)))
14da91e2 889 (and (build-derivations %store (list drv))
9e782349 890 (file-exists? (string-append out "/bin/make")))))))
e3ce5d70 891
f37f2b83
LC
892(test-equal "package-mapping"
893 42
894 (let* ((dep (dummy-package "chbouib"
895 (native-inputs `(("x" ,grep)))))
896 (p0 (dummy-package "example"
897 (inputs `(("foo" ,coreutils)
898 ("bar" ,grep)
899 ("baz" ,dep)))))
900 (transform (lambda (p)
901 (package (inherit p) (source 42))))
902 (rewrite (package-mapping transform))
903 (p1 (rewrite p0)))
904 (and (eq? p1 (rewrite p0))
905 (eqv? 42 (package-source p1))
906 (match (package-inputs p1)
907 ((("foo" dep1) ("bar" dep2) ("baz" dep3))
908 (and (eq? dep1 (rewrite coreutils)) ;memoization
909 (eq? dep2 (rewrite grep))
910 (eq? dep3 (rewrite dep))
911 (eqv? 42
912 (package-source dep1) (package-source dep2)
913 (package-source dep3))
914 (match (package-native-inputs dep3)
915 ((("x" dep))
916 (and (eq? dep (rewrite grep))
917 (package-source dep))))))))))
918
2a75b0b6
LC
919(test-assert "package-input-rewriting"
920 (let* ((dep (dummy-package "chbouib"
921 (native-inputs `(("x" ,grep)))))
922 (p0 (dummy-package "example"
923 (inputs `(("foo" ,coreutils)
924 ("bar" ,grep)
925 ("baz" ,dep)))))
926 (rewrite (package-input-rewriting `((,coreutils . ,sed)
927 (,grep . ,findutils))
928 (cut string-append "r-" <>)))
929 (p1 (rewrite p0))
930 (p2 (rewrite p0)))
931 (and (not (eq? p1 p0))
932 (eq? p1 p2) ;memoization
933 (string=? "r-example" (package-name p1))
934 (match (package-inputs p1)
935 ((("foo" dep1) ("bar" dep2) ("baz" dep3))
936 (and (eq? dep1 sed)
937 (eq? dep2 findutils)
938 (string=? (package-name dep3) "r-chbouib")
939 (eq? dep3 (rewrite dep)) ;memoization
940 (match (package-native-inputs dep3)
941 ((("x" dep))
942 (eq? dep findutils)))))))))
943
ba326ce4
LC
944(test-eq "fold-packages" hello
945 (fold-packages (lambda (p r)
946 (if (string=? (package-name p) "hello")
947 p
948 r))
949 #f))
950
386b71d1
LC
951(test-assert "fold-packages, hidden package"
952 ;; There are two public variables providing "guile@2.0" ('guile-final' in
b66d6d52 953 ;; commencement.scm and 'guile-2.0' in guile.scm), but only the latter
386b71d1
LC
954 ;; should show up.
955 (match (fold-packages (lambda (p r)
956 (if (and (string=? (package-name p) "guile")
957 (string-prefix? "2.0"
958 (package-version p)))
959 (cons p r)
960 r))
961 '())
962 ((one)
b66d6d52 963 (eq? one guile-2.0))))
386b71d1 964
6b1891b0
LC
965(test-assert "find-packages-by-name"
966 (match (find-packages-by-name "hello")
967 (((? (cut eq? hello <>))) #t)
968 (wrong (pk 'find-packages-by-name wrong #f))))
969
970(test-assert "find-packages-by-name with version"
971 (match (find-packages-by-name "hello" (package-version hello))
972 (((? (cut eq? hello <>))) #t)
973 (wrong (pk 'find-packages-by-name wrong #f))))
974
cf81a236
LC
975(test-assert "--search-paths with pattern"
976 ;; Make sure 'guix package --search-paths' correctly reports environment
977 ;; variables when file patterns are used (in particular, it must follow
978 ;; symlinks when looking for 'catalog.xml'.) To do that, we rely on the
979 ;; libxml2 package specification, which contains such a definition.
980 (let* ((p1 (package
981 (name "foo") (version "0") (source #f)
982 (build-system trivial-build-system)
983 (arguments
984 `(#:guile ,%bootstrap-guile
985 #:modules ((guix build utils))
986 #:builder (begin
987 (use-modules (guix build utils))
988 (let ((out (assoc-ref %outputs "out")))
989 (mkdir-p (string-append out "/xml/bar/baz"))
990 (call-with-output-file
991 (string-append out "/xml/bar/baz/catalog.xml")
992 (lambda (port)
993 (display "xml? wat?!" port)))))))
994 (synopsis #f) (description #f)
995 (home-page #f) (license #f)))
996 (p2 (package
997 ;; Provide a fake libxml2 to avoid building the real one. This
998 ;; is OK because 'guix package' gets search path specifications
999 ;; from the same-named package found in the distro.
1000 (name "libxml2") (version "0.0.0") (source #f)
1001 (build-system trivial-build-system)
1002 (arguments
1003 `(#:guile ,%bootstrap-guile
1004 #:builder (mkdir (assoc-ref %outputs "out"))))
1005 (native-search-paths (package-native-search-paths libxml2))
1006 (synopsis #f) (description #f)
1007 (home-page #f) (license #f)))
1008 (prof (run-with-store %store
1009 (profile-derivation
1010 (manifest (map package->manifest-entry
1011 (list p1 p2)))
a6562c7e
LC
1012 #:hooks '()
1013 #:locales? #f)
cf81a236
LC
1014 #:guile-for-build (%guile-for-build))))
1015 (build-derivations %store (list prof))
1016 (string-match (format #f "^export XML_CATALOG_FILES=\"~a/xml/+bar/baz/catalog\\.xml\"\n"
77559f23 1017 (regexp-quote (derivation->output-path prof)))
cf81a236
LC
1018 (with-output-to-string
1019 (lambda ()
1020 (guix-package "-p" (derivation->output-path prof)
1021 "--search-paths"))))))
1022
fcd75bdb
LC
1023(test-assert "--search-paths with single-item search path"
1024 ;; Make sure 'guix package --search-paths' correctly reports environment
1025 ;; variables for things like 'GIT_SSL_CAINFO' that have #f as their
1026 ;; separator, meaning that the first match wins.
1027 (let* ((p1 (dummy-package "foo"
1028 (build-system trivial-build-system)
1029 (arguments
1030 `(#:guile ,%bootstrap-guile
1031 #:modules ((guix build utils))
1032 #:builder (begin
1033 (use-modules (guix build utils))
1034 (let ((out (assoc-ref %outputs "out")))
1035 (mkdir-p (string-append out "/etc/ssl/certs"))
1036 (call-with-output-file
1037 (string-append
1038 out "/etc/ssl/certs/ca-certificates.crt")
1039 (const #t))))))))
1040 (p2 (package (inherit p1) (name "bar")))
1041 (p3 (dummy-package "git"
1042 ;; Provide a fake Git to avoid building the real one.
1043 (build-system trivial-build-system)
1044 (arguments
1045 `(#:guile ,%bootstrap-guile
1046 #:builder (mkdir (assoc-ref %outputs "out"))))
1047 (native-search-paths (package-native-search-paths git))))
1048 (prof1 (run-with-store %store
1049 (profile-derivation
1050 (packages->manifest (list p1 p3))
1051 #:hooks '()
1052 #:locales? #f)
1053 #:guile-for-build (%guile-for-build)))
1054 (prof2 (run-with-store %store
1055 (profile-derivation
1056 (packages->manifest (list p2 p3))
1057 #:hooks '()
1058 #:locales? #f)
1059 #:guile-for-build (%guile-for-build))))
1060 (build-derivations %store (list prof1 prof2))
1061 (string-match (format #f "^export GIT_SSL_CAINFO=\"~a/etc/ssl/certs/ca-certificates.crt"
1062 (regexp-quote (derivation->output-path prof1)))
1063 (with-output-to-string
1064 (lambda ()
1065 (guix-package "-p" (derivation->output-path prof1)
1066 "-p" (derivation->output-path prof2)
1067 "--search-paths"))))))
1068
efb107e0
LC
1069(test-equal "specification->package when not found"
1070 'quit
1071 (catch 'quit
1072 (lambda ()
1073 ;; This should call 'leave', producing an error message.
1074 (specification->package "this-package-does-not-exist"))
1075 (lambda (key . args)
1076 key)))
1077
e3ce5d70
LC
1078(test-end "packages")
1079
e3ce5d70 1080;;; Local Variables:
a3d73f59 1081;;; eval: (put 'dummy-package 'scheme-indent-function 1)
e3ce5d70 1082;;; End: