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