1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
5 ;;; This file is part of GNU Guix.
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20 (define-module (test-packages)
21 #:use-module (guix tests)
22 #:use-module (guix store)
23 #:use-module (guix monads)
24 #:use-module (guix grafts)
25 #:use-module ((guix gexp) #:select (local-file local-file-file))
26 #:use-module ((guix utils)
27 ;; Rename the 'location' binding to allow proper syntax
28 ;; matching when setting the 'location' field of a package.
29 #:renamer (lambda (name)
30 (cond ((eq? name 'location) 'make-location)
32 #:use-module (gcrypt hash)
33 #:use-module (guix derivations)
34 #:use-module (guix packages)
35 #:use-module (guix grafts)
36 #:use-module (guix search-paths)
37 #:use-module (guix build-system)
38 #:use-module (guix build-system trivial)
39 #:use-module (guix build-system gnu)
40 #:use-module (guix memoization)
41 #:use-module (guix profiles)
42 #:use-module (guix scripts package)
43 #:use-module (gnu packages)
44 #:use-module (gnu packages base)
45 #:use-module (gnu packages guile)
46 #:use-module (gnu packages bootstrap)
47 #:use-module (gnu packages version-control)
48 #:use-module (gnu packages xml)
49 #:use-module (srfi srfi-1)
50 #:use-module (srfi srfi-26)
51 #:use-module (srfi srfi-34)
52 #:use-module (srfi srfi-35)
53 #:use-module (srfi srfi-64)
54 #:use-module (rnrs io ports)
55 #:use-module (ice-9 vlist)
56 #:use-module (ice-9 regex)
57 #:use-module (ice-9 match))
59 ;; Test the high-level packaging layer.
62 (open-connection-for-tests))
64 ;; Globally disable grafting to avoid rebuilding the world ('graft-derivation'
65 ;; can trigger builds early.)
69 (test-begin "packages")
71 (test-assert "printer with location"
72 (string-match "^#<package foo@0 foo.scm:42 [[:xdigit:]]+>$"
73 (with-output-to-string
77 (location (make-location "foo.scm" 42 7))))))))
79 (test-assert "printer without location"
80 (string-match "^#<package foo@0 [[:xdigit:]]+>$"
81 (with-output-to-string
84 (dummy-package "foo" (location #f)))))))
86 (test-assert "hidden-package"
87 (and (hidden-package? (hidden-package (dummy-package "foo")))
88 (not (hidden-package? (dummy-package "foo")))))
90 (test-assert "package-superseded"
91 (let* ((new (dummy-package "bar"))
92 (old (deprecated-package "foo" new)))
93 (and (eq? (package-superseded old) new)
94 (mock ((gnu packages) find-best-packages-by-name (const (list old)))
95 (specification->package "foo")
96 (and (eq? new (specification->package "foo"))
97 (eq? new (specification->package+output "foo")))))))
99 (test-assert "transaction-upgrade-entry, zero upgrades"
100 (let* ((old (dummy-package "foo" (version "1")))
101 (tx (mock ((gnu packages) find-best-packages-by-name
103 (transaction-upgrade-entry
104 #f ;no store access needed
106 (inherit (package->manifest-entry old))
107 (item (string-append (%store-prefix) "/"
108 (make-string 32 #\e) "-foo-1")))
109 (manifest-transaction)))))
110 (manifest-transaction-null? tx)))
112 (test-assert "transaction-upgrade-entry, one upgrade"
113 (let* ((old (dummy-package "foo" (version "1")))
114 (new (dummy-package "foo" (version "2")))
115 (tx (mock ((gnu packages) find-best-packages-by-name
117 (transaction-upgrade-entry
118 #f ;no store access needed
120 (inherit (package->manifest-entry old))
121 (item (string-append (%store-prefix) "/"
122 (make-string 32 #\e) "-foo-1")))
123 (manifest-transaction)))))
124 (and (match (manifest-transaction-install tx)
125 ((($ <manifest-entry> "foo" "2" "out" item))
127 (null? (manifest-transaction-remove tx)))))
129 (test-assert "transaction-upgrade-entry, superseded package"
130 (let* ((old (dummy-package "foo" (version "1")))
131 (new (dummy-package "bar" (version "2")))
132 (dep (deprecated-package "foo" new))
133 (tx (mock ((gnu packages) find-best-packages-by-name
135 (transaction-upgrade-entry
136 #f ;no store access needed
138 (inherit (package->manifest-entry old))
139 (item (string-append (%store-prefix) "/"
140 (make-string 32 #\e) "-foo-1")))
141 (manifest-transaction)))))
142 (and (match (manifest-transaction-install tx)
143 ((($ <manifest-entry> "bar" "2" "out" item))
145 (match (manifest-transaction-remove tx)
146 (((? manifest-pattern? pattern))
147 (and (string=? (manifest-pattern-name pattern) "foo")
148 (string=? (manifest-pattern-version pattern) "1")
149 (string=? (manifest-pattern-output pattern) "out")))))))
151 (test-assert "package-field-location"
153 (define (goto port line column)
154 (unless (and (= (port-column port) (- column 1))
155 (= (port-line port) (- line 1)))
156 (unless (eof-object? (get-char port))
157 (goto port line column))))
161 (($ <location> file line column)
162 (call-with-input-file (search-path %load-path file)
164 (goto port line column)
167 ;; Until Guile 2.0.6 included, source properties were added only to pairs.
168 ;; Thus, check against both VALUE and (FIELD VALUE).
169 (and (member (read-at (package-field-location %bootstrap-guile 'name))
170 (let ((name (package-name %bootstrap-guile)))
171 (list name `(name ,name))))
172 (member (read-at (package-field-location %bootstrap-guile 'version))
173 (let ((version (package-version %bootstrap-guile)))
174 (list version `(version ,version))))
175 (not (package-field-location %bootstrap-guile 'does-not-exist)))))
177 ;; Make sure we don't change the file name to an absolute file name.
178 (test-equal "package-field-location, relative file name"
179 (location-file (package-location %bootstrap-guile))
180 (with-fluids ((%file-port-name-canonicalization 'absolute))
181 (location-file (package-field-location %bootstrap-guile 'version))))
183 (test-assert "package-transitive-inputs"
184 (let* ((a (dummy-package "a"))
185 (b (dummy-package "b"
186 (propagated-inputs `(("a" ,a)))))
187 (c (dummy-package "c"
188 (inputs `(("a" ,a)))))
189 (d (dummy-package "d"
190 (propagated-inputs `(("x" "something.drv")))))
191 (e (dummy-package "e"
192 (inputs `(("b" ,b) ("c" ,c) ("d" ,d))))))
193 (and (null? (package-transitive-inputs a))
194 (equal? `(("a" ,a)) (package-transitive-inputs b))
195 (equal? `(("a" ,a)) (package-transitive-inputs c))
196 (equal? (package-propagated-inputs d)
197 (package-transitive-inputs d))
198 (equal? `(("b" ,b) ("c" ,c) ("d" ,d)
199 ("a" ,a) ("x" "something.drv"))
200 (pk 'x (package-transitive-inputs e))))))
202 (test-assert "package-transitive-inputs, no duplicates"
203 (let* ((a (dummy-package "a"))
204 (b (dummy-package "b"
205 (inputs `(("a+" ,a)))
206 (native-inputs `(("a*" ,a)))
207 (propagated-inputs `(("a" ,a)))))
208 (c (dummy-package "c"
209 (propagated-inputs `(("b" ,b)))))
210 (d (dummy-package "d"
211 (inputs `(("a" ,a) ("c" ,c)))))
212 (e (dummy-package "e"
213 (inputs `(("b" ,b) ("c" ,c))))))
214 (and (null? (package-transitive-inputs a))
215 (equal? `(("a*" ,a) ("a+" ,a) ("a" ,a)) ;here duplicates are kept
216 (package-transitive-inputs b))
217 (equal? `(("b" ,b) ("a" ,a))
218 (package-transitive-inputs c))
219 (equal? `(("a" ,a) ("c" ,c) ("b" ,b)) ;duplicate A removed
220 (package-transitive-inputs d))
221 (equal? `(("b" ,b) ("c" ,c) ("a" ,a))
222 (package-transitive-inputs e))))) ;ditto
224 (test-equal "package-transitive-supported-systems"
230 ;; Use TRIVIAL-BUILD-SYSTEM because it doesn't add implicit inputs and thus
231 ;; doesn't restrict the set of supported systems.
232 (let* ((a (dummy-package "a"
233 (build-system trivial-build-system)
234 (supported-systems '("x" "y" "z"))))
235 (b (dummy-package "b"
236 (build-system trivial-build-system)
237 (supported-systems '("x" "y"))
238 (inputs `(("a" ,a)))))
239 (c (dummy-package "c"
240 (build-system trivial-build-system)
241 (supported-systems '("y" "z"))
242 (inputs `(("b" ,b)))))
243 (d (dummy-package "d"
244 (build-system trivial-build-system)
245 (supported-systems '("x" "y" "z"))
246 (inputs `(("b" ,b) ("c" ,c)))))
247 (e (dummy-package "e"
248 (build-system trivial-build-system)
249 (supported-systems '("x" "y" "z"))
250 (inputs `(("d" ,d))))))
251 (list (package-transitive-supported-systems a)
252 (package-transitive-supported-systems b)
253 (package-transitive-supported-systems c)
254 (package-transitive-supported-systems d)
255 (package-transitive-supported-systems e))))
257 (test-assert "package-closure"
258 (let-syntax ((dummy-package/no-implicit
262 (inherit (dummy-package name rest ...))
263 (build-system trivial-build-system))))))
264 (let* ((a (dummy-package/no-implicit "a"))
265 (b (dummy-package/no-implicit "b"
266 (propagated-inputs `(("a" ,a)))))
267 (c (dummy-package/no-implicit "c"
268 (inputs `(("a" ,a)))))
269 (d (dummy-package/no-implicit "d"
270 (native-inputs `(("b" ,b)))))
271 (e (dummy-package/no-implicit "e"
272 (inputs `(("c" ,c) ("d" ,d))))))
275 (package-closure (list e))
276 (package-closure (list e d))
277 (package-closure (list e c b))))))
279 (test-equal "origin-actual-file-name"
281 (let ((o (dummy-origin (uri "http://www.example.com/foo-1.tar.gz"))))
282 (origin-actual-file-name o)))
284 (test-equal "origin-actual-file-name, file-name"
286 (let ((o (dummy-origin
287 (uri "http://www.example.com/tarball")
288 (file-name "foo-1.tar.gz"))))
289 (origin-actual-file-name o)))
291 (let* ((o (dummy-origin))
294 (a (dummy-package "a"))
295 (b (dummy-package "b"
296 (inputs `(("a" ,a) ("i" ,i)))))
297 (c (package (inherit b) (source o)))
298 (d (dummy-package "d"
299 (build-system trivial-build-system)
300 (source u) (inputs `(("c" ,c))))))
301 (test-assert "package-direct-sources, no source"
302 (null? (package-direct-sources a)))
303 (test-equal "package-direct-sources, #f source"
305 (package-direct-sources b))
306 (test-equal "package-direct-sources, not input source"
308 (package-direct-sources d))
309 (test-assert "package-direct-sources"
310 (let ((s (package-direct-sources c)))
311 (and (= (length (pk 's-sources s)) 2)
314 (test-assert "package-transitive-sources"
315 (let ((s (package-transitive-sources d)))
316 (and (= (length (pk 'd-sources s)) 3)
321 (test-assert "transitive-input-references"
322 (let* ((a (dummy-package "a"))
323 (b (dummy-package "b"))
324 (c (dummy-package "c"
326 (propagated-inputs `(("boo" ,b)))))
327 (d (dummy-package "d"
328 (inputs `(("c*" ,c)))))
329 (keys (map (match-lambda
332 (pk 'refs (transitive-input-references
333 'l (package-inputs d))))))
334 (and (= (length keys) 2)
336 (member "boo" keys))))
338 (test-equal "package-transitive-supported-systems, implicit inputs"
341 ;; Here GNU-BUILD-SYSTEM adds implicit inputs that build only on
342 ;; %SUPPORTED-SYSTEMS. Thus the others must be ignored.
343 (let ((p (dummy-package "foo"
344 (build-system gnu-build-system)
346 `("does-not-exist" "foobar" ,@%supported-systems)))))
347 (parameterize ((%current-system "armhf-linux")) ; a traditionally-bootstrapped architecture
348 (package-transitive-supported-systems p))))
350 (test-equal "package-transitive-supported-systems: reduced binary seed, implicit inputs"
351 '("x86_64-linux" "i686-linux")
353 ;; Here GNU-BUILD-SYSTEM adds implicit inputs that build only on
354 ;; %SUPPORTED-SYSTEMS. Thus the others must be ignored.
355 (let ((p (dummy-package "foo"
356 (build-system gnu-build-system)
358 `("does-not-exist" "foobar" ,@%supported-systems)))))
359 (parameterize ((%current-system "x86_64-linux"))
360 (package-transitive-supported-systems p))))
362 (test-assert "supported-package?"
363 (let* ((d (dummy-package "dep"
364 (build-system trivial-build-system)
365 (supported-systems '("x86_64-linux"))))
366 (p (dummy-package "foo"
367 (build-system gnu-build-system)
369 (supported-systems '("x86_64-linux" "armhf-linux")))))
370 (and (supported-package? p "x86_64-linux")
371 (not (supported-package? p "i686-linux"))
372 (not (supported-package? p "armhf-linux")))))
374 (test-assert "supported-package? vs. system-dependent graph"
375 ;; The inputs of a package can depend on (%current-system). Thus,
376 ;; 'supported-package?' must make sure that it binds (%current-system)
377 ;; appropriately before traversing the dependency graph. In the example
378 ;; below, 'supported-package?' must thus return true for both systems.
379 (let* ((p0a (dummy-package "foo-arm"
380 (build-system trivial-build-system)
381 (supported-systems '("armhf-linux"))))
382 (p0b (dummy-package "foo-x86_64"
383 (build-system trivial-build-system)
384 (supported-systems '("x86_64-linux"))))
385 (p (dummy-package "bar"
386 (build-system trivial-build-system)
388 (if (string=? (%current-system) "armhf-linux")
391 (and (supported-package? p "x86_64-linux")
392 (supported-package? p "armhf-linux"))))
394 (test-skip (if (not %store) 8 0))
396 (test-assert "package-source-derivation, file"
397 (let* ((file (search-path %load-path "guix.scm"))
398 (package (package (inherit (dummy-package "p"))
400 (source (package-source-derivation %store
401 (package-source package))))
402 (and (store-path? source)
403 (valid-path? %store source)
404 (equal? (call-with-input-file source get-bytevector-all)
405 (call-with-input-file file get-bytevector-all)))))
407 (test-assert "package-source-derivation, store path"
408 (let* ((file (add-to-store %store "guix.scm" #t "sha256"
409 (search-path %load-path "guix.scm")))
410 (package (package (inherit (dummy-package "p"))
412 (source (package-source-derivation %store
413 (package-source package))))
414 (string=? file source)))
416 (test-assert "package-source-derivation, indirect store path"
417 (let* ((dir (add-to-store %store "guix-build" #t "sha256"
418 (dirname (search-path %load-path
419 "guix/build/utils.scm"))))
420 (package (package (inherit (dummy-package "p"))
421 (source (string-append dir "/utils.scm"))))
422 (source (package-source-derivation %store
423 (package-source package))))
424 (and (direct-store-path? source)
425 (string-suffix? "utils.scm" source))))
427 (test-assert "package-source-derivation, local-file"
428 (let* ((file (local-file "../guix/base32.scm"))
429 (package (package (inherit (dummy-package "p"))
431 (source (package-source-derivation %store
432 (package-source package))))
433 (and (store-path? source)
434 (string-suffix? "base32.scm" source)
435 (valid-path? %store source)
436 (equal? (call-with-input-file source get-bytevector-all)
437 (call-with-input-file
438 (search-path %load-path "guix/base32.scm")
439 get-bytevector-all)))))
441 (unless (network-reachable?) (test-skip 1))
442 (test-equal "package-source-derivation, snippet"
444 (let* ((source (bootstrap-origin
446 (inherit (bootstrap-guile-origin (%current-system)))
448 `(("tar" ,%bootstrap-coreutils&co)
449 ("xz" ,%bootstrap-coreutils&co)
450 ("patch" ,%bootstrap-coreutils&co)))
451 (patch-guile %bootstrap-guile)
452 (modules '((guix build utils)))
454 ;; We end up in 'bin', because it's the first
455 ;; directory, alphabetically. Not a very good
458 (symlink "guile" "guile-rocks")
459 (copy-recursively "../share/guile/2.0/scripts"
462 ;; Make sure '.file_list' can be created.
463 (chmod ".." #o777))))))
464 (package (package (inherit (dummy-package "with-snippet"))
466 (build-system trivial-build-system)
468 `(("tar" ,(search-bootstrap-binary "tar"
470 ("xz" ,(search-bootstrap-binary "xz"
471 (%current-system)))))
473 `(#:guile ,%bootstrap-guile
474 #:modules ((guix build utils))
477 (use-modules (guix build utils))
478 (let ((tar (assoc-ref %build-inputs "tar"))
479 (xz (assoc-ref %build-inputs "xz"))
480 (source (assoc-ref %build-inputs "source")))
481 (invoke tar "xvf" source
482 "--use-compress-program" xz)
483 (unless (and (string=? "guile" (readlink "bin/guile-rocks"))
484 (file-exists? "bin/scripts/compile.scm"))
485 (error "the snippet apparently failed"))
486 (let ((out (assoc-ref %outputs "out")))
487 (call-with-output-file out
491 (drv (package-derivation %store package))
492 (out (derivation->output-path drv)))
493 (and (build-derivations %store (list (pk 'snippet-drv drv)))
494 (call-with-input-file out get-string-all))))
496 (test-assert "return value"
497 (let ((drv (package-derivation %store (dummy-package "p"))))
498 (and (derivation? drv)
499 (file-exists? (derivation-file-name drv)))))
501 (test-assert "package-output"
502 (let* ((package (dummy-package "p"))
503 (drv (package-derivation %store package)))
504 (and (derivation? drv)
505 (string=? (derivation->output-path drv)
506 (package-output %store package "out")))))
508 (test-assert "patch not found yields a run-time error"
509 (guard (c ((condition-has-type? c &message)
510 (and (string-contains (condition-message c)
511 "does-not-exist.patch")
512 (string-contains (condition-message c)
515 (inherit (dummy-package "p"))
518 (uri "http://whatever")
520 (list (search-patch "does-not-exist.patch")))
523 "0amn0bbwqvsvvsh6drfwz20ydc2czk374lzw5kksbh6bf78k4ks4")))))))
524 (package-derivation %store p)
527 (let ((dummy (dummy-package "foo" (inputs `(("x" ,(current-module)))))))
528 (test-equal "&package-input-error"
529 (list dummy (current-module))
530 (guard (c ((package-input-error? c)
531 (list (package-error-package c)
532 (package-error-invalid-input c))))
533 (package-derivation %store dummy))))
535 (test-assert "reference to non-existent output"
536 ;; See <http://bugs.gnu.org/19630>.
537 (parameterize ((%graft? #f))
538 (let* ((dep (dummy-package "dep"))
539 (p (dummy-package "p"
540 (inputs `(("dep" ,dep "non-existent"))))))
541 (guard (c ((derivation-missing-output-error? c)
542 (and (string=? (derivation-missing-output c) "non-existent")
543 (equal? (package-derivation %store dep)
544 (derivation-error-derivation c)))))
545 (package-derivation %store p)))))
547 (test-assert "trivial"
548 (let* ((p (package (inherit (dummy-package "trivial"))
549 (build-system trivial-build-system)
552 `(#:guile ,%bootstrap-guile
556 (call-with-output-file (string-append %output "/test")
558 (display '(hello guix) p)))
560 (d (package-derivation %store p)))
561 (and (build-derivations %store (list d))
562 (let ((p (pk 'drv d (derivation->output-path d))))
563 (equal? '(hello guix)
564 (call-with-input-file (string-append p "/test") read))))))
566 (test-assert "trivial with local file as input"
567 (let* ((i (search-path %load-path "ice-9/boot-9.scm"))
568 (p (package (inherit (dummy-package "trivial-with-input-file"))
569 (build-system trivial-build-system)
572 `(#:guile ,%bootstrap-guile
574 (copy-file (assoc-ref %build-inputs "input")
577 (inputs `(("input" ,i)))))
578 (d (package-derivation %store p)))
579 (and (build-derivations %store (list d))
580 (let ((p (pk 'drv d (derivation->output-path d))))
581 (equal? (call-with-input-file p get-bytevector-all)
582 (call-with-input-file i get-bytevector-all))))))
584 (test-assert "trivial with source"
585 (let* ((i (search-path %load-path "ice-9/boot-9.scm"))
586 (p (package (inherit (dummy-package "trivial-with-source"))
587 (build-system trivial-build-system)
590 `(#:guile ,%bootstrap-guile
592 (copy-file (assoc-ref %build-inputs "source")
595 (d (package-derivation %store p)))
596 (and (build-derivations %store (list d))
597 (let ((p (derivation->output-path d)))
598 (equal? (call-with-input-file p get-bytevector-all)
599 (call-with-input-file i get-bytevector-all))))))
601 (test-assert "trivial with system-dependent input"
602 (let* ((p (package (inherit (dummy-package "trivial-system-dependent-input"))
603 (build-system trivial-build-system)
606 `(#:guile ,%bootstrap-guile
607 #:modules ((guix build utils))
610 (use-modules (guix build utils))
611 (let ((out (assoc-ref %outputs "out"))
612 (bash (assoc-ref %build-inputs "bash")))
614 (format #f "echo hello > ~a" out))))))
615 (inputs `(("bash" ,(search-bootstrap-binary "bash"
616 (%current-system)))))))
617 (d (package-derivation %store p)))
618 (and (build-derivations %store (list d))
619 (let ((p (pk 'drv d (derivation->output-path d))))
620 (eq? 'hello (call-with-input-file p read))))))
622 (test-assert "trivial with #:allowed-references"
624 (inherit (dummy-package "trivial"))
625 (build-system trivial-build-system)
627 `(#:guile ,%bootstrap-guile
628 #:allowed-references (,%bootstrap-guile)
632 ;; The reference to itself isn't allowed so building it
634 (symlink %output (string-append %output "/self"))
636 (d (package-derivation %store p)))
637 (guard (c ((store-protocol-error? c) #t))
638 (build-derivations %store (list d))
641 (test-assert "search paths"
642 (let* ((p (make-prompt-tag "return-search-paths"))
645 (description "Raw build system with direct store access")
646 (lower (lambda* (name #:key source inputs system target
650 (system system) (target target)
651 (build-inputs inputs)
653 (lambda* (store name inputs
654 #:key outputs system search-paths)
656 (x (list (search-path-specification
657 (variable "GUILE_LOAD_PATH")
658 (files '("share/guile/site/2.0")))
659 (search-path-specification
660 (variable "GUILE_LOAD_COMPILED_PATH")
661 (files '("share/guile/site/2.0")))))
662 (a (package (inherit (dummy-package "guile"))
664 (native-search-paths x)))
665 (b (package (inherit (dummy-package "guile-foo"))
667 (inputs `(("guile" ,a)))))
668 (c (package (inherit (dummy-package "guile-bar"))
670 (inputs `(("guile" ,a)
671 ("guile-foo" ,b))))))
672 (let-syntax ((collect (syntax-rules ()
677 (lambda (k search-paths)
679 (and (null? (collect (package-derivation %store a)))
680 (equal? x (collect (package-derivation %store b)))
681 (equal? x (collect (package-derivation %store c)))))))
683 (test-assert "package-transitive-native-search-paths"
684 (let* ((sp (lambda (name)
685 (list (search-path-specification
687 (files '("foo/bar"))))))
688 (p0 (dummy-package "p0" (native-search-paths (sp "PATH0"))))
689 (p1 (dummy-package "p1" (native-search-paths (sp "PATH1"))))
690 (p2 (dummy-package "p2"
691 (native-search-paths (sp "PATH2"))
692 (inputs `(("p0" ,p0)))
693 (propagated-inputs `(("p1" ,p1)))))
694 (p3 (dummy-package "p3"
695 (native-search-paths (sp "PATH3"))
696 (native-inputs `(("p0" ,p0)))
697 (propagated-inputs `(("p2" ,p2))))))
699 '("PATH1" "PATH2" "PATH3")
700 (map search-path-specification-variable
701 (package-transitive-native-search-paths p3)))))
703 (test-assert "package-cross-derivation"
704 (let ((drv (package-cross-derivation %store (dummy-package "p")
705 "mips64el-linux-gnu")))
706 (and (derivation? drv)
707 (file-exists? (derivation-file-name drv)))))
709 (test-assert "package-cross-derivation, trivial-build-system"
710 (let ((p (package (inherit (dummy-package "p"))
711 (build-system trivial-build-system)
712 (arguments '(#:builder (exit 1))))))
713 (let ((drv (package-cross-derivation %store p "mips64el-linux-gnu")))
716 (test-assert "package-cross-derivation, no cross builder"
717 (let* ((b (build-system (inherit trivial-build-system)
719 (p (package (inherit (dummy-package "p"))
721 (guard (c ((package-cross-build-system-error? c)
722 (eq? (package-error-package c) p)))
723 (package-cross-derivation %store p "mips64el-linux-gnu")
726 ;; XXX: The next two tests can trigger builds when the distro defines
727 ;; replacements on core packages, so they're disable for lack of a better
730 ;; (test-equal "package-derivation, direct graft"
731 ;; (package-derivation %store gnu-make #:graft? #f)
732 ;; (let ((p (package (inherit coreutils)
733 ;; (replacement gnu-make))))
734 ;; (package-derivation %store p #:graft? #t)))
736 ;; (test-equal "package-cross-derivation, direct graft"
737 ;; (package-cross-derivation %store gnu-make "mips64el-linux-gnu"
739 ;; (let ((p (package (inherit coreutils)
740 ;; (replacement gnu-make))))
741 ;; (package-cross-derivation %store p "mips64el-linux-gnu"
744 (test-assert "package-grafts, indirect grafts"
745 (let* ((new (dummy-package "dep"
746 (arguments '(#:implicit-inputs? #f))))
747 (dep (package (inherit new) (version "0.0")))
748 (dep* (package (inherit dep) (replacement new)))
749 (dummy (dummy-package "dummy"
750 (arguments '(#:implicit-inputs? #f))
751 (inputs `(("dep" ,dep*))))))
752 (equal? (package-grafts %store dummy)
754 (origin (package-derivation %store dep))
755 (replacement (package-derivation %store new)))))))
757 ;; XXX: This test would require building the cross toolchain just to see if it
758 ;; needs grafting, which is obviously too expensive, and thus disabled.
760 ;; (test-assert "package-grafts, indirect grafts, cross"
761 ;; (let* ((new (dummy-package "dep"
762 ;; (arguments '(#:implicit-inputs? #f))))
763 ;; (dep (package (inherit new) (version "0.0")))
764 ;; (dep* (package (inherit dep) (replacement new)))
765 ;; (dummy (dummy-package "dummy"
766 ;; (arguments '(#:implicit-inputs? #f))
767 ;; (inputs `(("dep" ,dep*)))))
768 ;; (target "mips64el-linux-gnu"))
769 ;; ;; XXX: There might be additional grafts, for instance if the distro
770 ;; ;; defines replacements for core packages like Perl.
772 ;; (origin (package-cross-derivation %store dep target))
774 ;; (package-cross-derivation %store new target)))
775 ;; (package-grafts %store dummy #:target target))))
777 (test-assert "package-grafts, indirect grafts, propagated inputs"
778 (let* ((new (dummy-package "dep"
779 (arguments '(#:implicit-inputs? #f))))
780 (dep (package (inherit new) (version "0.0")))
781 (dep* (package (inherit dep) (replacement new)))
782 (prop (dummy-package "propagated"
783 (propagated-inputs `(("dep" ,dep*)))
784 (arguments '(#:implicit-inputs? #f))))
785 (dummy (dummy-package "dummy"
786 (arguments '(#:implicit-inputs? #f))
787 (inputs `(("prop" ,prop))))))
788 (equal? (package-grafts %store dummy)
790 (origin (package-derivation %store dep))
791 (replacement (package-derivation %store new)))))))
793 (test-assert "package-grafts, same replacement twice"
794 (let* ((new (dummy-package "dep"
796 (arguments '(#:implicit-inputs? #f))))
797 (dep (package (inherit new) (version "0") (replacement new)))
798 (p1 (dummy-package "intermediate1"
799 (arguments '(#:implicit-inputs? #f))
800 (inputs `(("dep" ,dep)))))
801 (p2 (dummy-package "intermediate2"
802 (arguments '(#:implicit-inputs? #f))
803 ;; Here we copy DEP to have an equivalent package that is not
804 ;; 'eq?' to DEP. This is similar to what happens with
805 ;; 'package-with-explicit-inputs' & co.
806 (inputs `(("dep" ,(package (inherit dep)))))))
807 (p3 (dummy-package "final"
808 (arguments '(#:implicit-inputs? #f))
809 (inputs `(("p1" ,p1) ("p2" ,p2))))))
810 (equal? (package-grafts %store p3)
812 (origin (package-derivation %store
813 (package (inherit dep)
815 (replacement (package-derivation %store new)))))))
817 (test-assert "replacement also grafted"
818 ;; We build a DAG as below, where dotted arrows represent replacements and
819 ;; solid arrows represent dependencies:
821 ;; P1 ·············> P1R
822 ;; |\__________________.
824 ;; P2 ·············> P2R
829 ;; We want to make sure that:
830 ;; grafts(P3) = (P1,P1R) + (P2, grafted(P2R, (P1,P1R)))
832 ;; (A,B) is a graft to replace A by B
833 ;; grafted(DRV,G) denoted DRV with graft G applied
834 (let* ((p1r (dummy-package "P1"
835 (build-system trivial-build-system)
837 `(#:guile ,%bootstrap-guile
838 #:builder (let ((out (assoc-ref %outputs "out")))
840 (call-with-output-file
841 (string-append out "/replacement")
844 (inherit p1r) (name "p1") (replacement p1r)
846 `(#:guile ,%bootstrap-guile
848 (mkdir (assoc-ref %outputs "out"))
850 (p2r (dummy-package "P2"
851 (build-system trivial-build-system)
852 (inputs `(("p1" ,p1)))
854 `(#:guile ,%bootstrap-guile
855 #:builder (let ((out (assoc-ref %outputs "out")))
858 (symlink (assoc-ref %build-inputs "p1") "p1")
859 (call-with-output-file (string-append out "/replacement")
862 (inherit p2r) (name "p2") (replacement p2r)
864 `(#:guile ,%bootstrap-guile
865 #:builder (let ((out (assoc-ref %outputs "out")))
868 (symlink (assoc-ref %build-inputs "p1")
871 (p3 (dummy-package "p3"
872 (build-system trivial-build-system)
873 (inputs `(("p2" ,p2)))
875 `(#:guile ,%bootstrap-guile
876 #:builder (let ((out (assoc-ref %outputs "out")))
879 (symlink (assoc-ref %build-inputs "p2")
883 (package-grafts %store p3)
885 (origin (package-derivation %store p1 #:graft? #f))
886 (replacement (package-derivation %store p1r)))
888 (origin (package-derivation %store p2 #:graft? #f))
890 (package-derivation %store p2r #:graft? #t)))))))
892 ;;; XXX: Nowadays 'graft-derivation' needs to build derivations beforehand to
893 ;;; find out about their run-time dependencies, so this test is no longer
894 ;;; applicable since it would trigger a full rebuild.
896 ;; (test-assert "package-derivation, indirect grafts"
897 ;; (let* ((new (dummy-package "dep"
898 ;; (arguments '(#:implicit-inputs? #f))))
899 ;; (dep (package (inherit new) (version "0.0")))
900 ;; (dep* (package (inherit dep) (replacement new)))
901 ;; (dummy (dummy-package "dummy"
902 ;; (arguments '(#:implicit-inputs? #f))
903 ;; (inputs `(("dep" ,dep*)))))
904 ;; (guile (package-derivation %store (canonical-package guile-2.0)
906 ;; (equal? (package-derivation %store dummy)
907 ;; (graft-derivation %store
908 ;; (package-derivation %store dummy #:graft? #f)
909 ;; (package-grafts %store dummy)
911 ;; ;; Use the same Guile as 'package-derivation'.
914 (test-equal "package->bag"
915 `("foo86-hurd" #f (,(package-source gnu-make))
916 (,(canonical-package glibc)) (,(canonical-package coreutils)))
917 (let ((bag (package->bag gnu-make "foo86-hurd")))
918 (list (bag-system bag) (bag-target bag)
919 (assoc-ref (bag-build-inputs bag) "source")
920 (assoc-ref (bag-build-inputs bag) "libc")
921 (assoc-ref (bag-build-inputs bag) "coreutils"))))
923 (test-equal "package->bag, cross-compilation"
924 `(,(%current-system) "foo86-hurd"
925 (,(package-source gnu-make))
926 (,(canonical-package glibc)) (,(canonical-package coreutils)))
927 (let ((bag (package->bag gnu-make (%current-system) "foo86-hurd")))
928 (list (bag-system bag) (bag-target bag)
929 (assoc-ref (bag-build-inputs bag) "source")
930 (assoc-ref (bag-build-inputs bag) "libc")
931 (assoc-ref (bag-build-inputs bag) "coreutils"))))
933 (test-assert "package->bag, propagated inputs"
934 (let* ((dep (dummy-package "dep"))
935 (prop (dummy-package "prop"
936 (propagated-inputs `(("dep" ,dep)))))
937 (dummy (dummy-package "dummy"
938 (inputs `(("prop" ,prop)))))
939 (inputs (bag-transitive-inputs (package->bag dummy #:graft? #f))))
940 (match (assoc "dep" inputs)
942 (eq? package dep)))))
944 (test-assert "bag->derivation"
945 (parameterize ((%graft? #f))
946 (let ((bag (package->bag gnu-make))
947 (drv (package-derivation %store gnu-make)))
948 (parameterize ((%current-system "foox86-hurd")) ;should have no effect
949 (equal? drv (bag->derivation %store bag))))))
951 (test-assert "bag->derivation, cross-compilation"
952 (parameterize ((%graft? #f))
953 (let* ((target "mips64el-linux-gnu")
954 (bag (package->bag gnu-make (%current-system) target))
955 (drv (package-cross-derivation %store gnu-make target)))
956 (parameterize ((%current-system "foox86-hurd") ;should have no effect
957 (%current-target-system "foo64-linux-gnu"))
958 (equal? drv (bag->derivation %store bag))))))
960 (when (or (not (network-reachable?)) (shebang-too-long?))
962 (test-assert "GNU Make, bootstrap"
963 ;; GNU-MAKE-FOR-TESTS can be built cheaply; we choose it here so that the
964 ;; test doesn't last for too long.
965 (let ((gnu-make gnu-make-for-tests))
966 (and (package? gnu-make)
967 (or (location? (package-location gnu-make))
968 (not (package-location gnu-make)))
969 (let* ((drv (package-derivation %store gnu-make))
970 (out (derivation->output-path drv)))
971 (and (build-derivations %store (list drv))
972 (file-exists? (string-append out "/bin/make")))))))
974 (test-equal "package-mapping"
976 (let* ((dep (dummy-package "chbouib"
977 (native-inputs `(("x" ,grep)))))
978 (p0 (dummy-package "example"
979 (inputs `(("foo" ,coreutils)
982 (transform (lambda (p)
983 (package (inherit p) (source 42))))
984 (rewrite (package-mapping transform))
986 (and (eq? p1 (rewrite p0))
987 (eqv? 42 (package-source p1))
988 (match (package-inputs p1)
989 ((("foo" dep1) ("bar" dep2) ("baz" dep3))
990 (and (eq? dep1 (rewrite coreutils)) ;memoization
991 (eq? dep2 (rewrite grep))
992 (eq? dep3 (rewrite dep))
994 (package-source dep1) (package-source dep2)
995 (package-source dep3))
996 (match (package-native-inputs dep3)
998 (and (eq? dep (rewrite grep))
999 (package-source dep))))))))))
1001 (test-assert "package-input-rewriting"
1002 (let* ((dep (dummy-package "chbouib"
1003 (native-inputs `(("x" ,grep)))))
1004 (p0 (dummy-package "example"
1005 (inputs `(("foo" ,coreutils)
1008 (rewrite (package-input-rewriting `((,coreutils . ,sed)
1009 (,grep . ,findutils))
1010 (cut string-append "r-" <>)))
1013 (and (not (eq? p1 p0))
1014 (eq? p1 p2) ;memoization
1015 (string=? "r-example" (package-name p1))
1016 (match (package-inputs p1)
1017 ((("foo" dep1) ("bar" dep2) ("baz" dep3))
1019 (eq? dep2 findutils)
1020 (string=? (package-name dep3) "r-chbouib")
1021 (eq? dep3 (rewrite dep)) ;memoization
1022 (match (package-native-inputs dep3)
1024 (eq? dep findutils)))))))))
1026 (test-assert "package-input-rewriting/spec"
1027 (let* ((dep (dummy-package "chbouib"
1028 (native-inputs `(("x" ,grep)))))
1029 (p0 (dummy-package "example"
1030 (inputs `(("foo" ,coreutils)
1033 (rewrite (package-input-rewriting/spec
1034 `(("coreutils" . ,(const sed))
1035 ("grep" . ,(const findutils)))))
1038 (and (not (eq? p1 p0))
1039 (eq? p1 p2) ;memoization
1040 (string=? "example" (package-name p1))
1041 (match (package-inputs p1)
1042 ((("foo" dep1) ("bar" dep2) ("baz" dep3))
1043 (and (string=? (package-full-name dep1)
1044 (package-full-name sed))
1045 (string=? (package-full-name dep2)
1046 (package-full-name findutils))
1047 (string=? (package-name dep3) "chbouib")
1048 (eq? dep3 (rewrite dep)) ;memoization
1049 (match (package-native-inputs dep3)
1051 (string=? (package-full-name dep)
1052 (package-full-name findutils))))))))))
1054 (test-assert "package-input-rewriting/spec, partial match"
1055 (let* ((dep (dummy-package "chbouib"
1057 (native-inputs `(("x" ,grep)))))
1058 (p0 (dummy-package "example"
1059 (inputs `(("foo" ,coreutils)
1061 (rewrite (package-input-rewriting/spec
1062 `(("chbouib@123" . ,(const sed)) ;not matched
1063 ("grep" . ,(const findutils)))))
1065 (and (not (eq? p1 p0))
1066 (string=? "example" (package-name p1))
1067 (match (package-inputs p1)
1068 ((("foo" dep1) ("bar" dep2))
1069 (and (string=? (package-full-name dep1)
1070 (package-full-name coreutils))
1071 (eq? dep2 (rewrite dep)) ;memoization
1072 (match (package-native-inputs dep2)
1074 (string=? (package-full-name dep)
1075 (package-full-name findutils))))))))))
1077 (test-equal "package-patched-vulnerabilities"
1079 ("CVE-2016-1234" "CVE-2018-4567")
1081 (let ((p1 (dummy-package "pi"
1082 (source (dummy-origin
1083 (patches (list "/a/b/pi-CVE-2015-1234.patch"))))))
1084 (p2 (dummy-package "pi"
1085 (source (dummy-origin
1087 "/a/b/pi-CVE-2016-1234-CVE-2018-4567.patch"))))))
1088 (p3 (dummy-package "pi" (source (dummy-origin)))))
1089 (map package-patched-vulnerabilities
1092 (test-eq "fold-packages" hello
1093 (fold-packages (lambda (p r)
1094 (if (string=? (package-name p) "hello")
1099 (test-assert "fold-packages, hidden package"
1100 ;; There are two public variables providing "guile@2.0" ('guile-final' in
1101 ;; commencement.scm and 'guile-2.0' in guile.scm), but only the latter
1103 (match (fold-packages (lambda (p r)
1104 (if (and (string=? (package-name p) "guile")
1105 (string-prefix? "2.0"
1106 (package-version p)))
1111 (eq? one guile-2.0))))
1113 (test-assert "fold-available-packages with/without cache"
1116 (fold-available-packages (lambda* (name version result #:rest rest)
1117 (cons (cons* name version rest)
1122 (call-with-temporary-directory
1124 (generate-package-cache cache)
1125 (mock ((guix describe) current-profile (const cache))
1126 (mock ((gnu packages) cache-is-authoritative? (const #t))
1127 (fold-available-packages (lambda* (name version result
1129 (cons (cons* name version rest)
1133 (and (equal? (delete-duplicates from-cache) from-cache)
1134 (lset= equal? no-cache from-cache))))
1136 (test-assert "find-packages-by-name"
1137 (match (find-packages-by-name "hello")
1138 (((? (cut eq? hello <>))) #t)
1139 (wrong (pk 'find-packages-by-name wrong #f))))
1141 (test-assert "find-packages-by-name with version"
1142 (match (find-packages-by-name "hello" (package-version hello))
1143 (((? (cut eq? hello <>))) #t)
1144 (wrong (pk 'find-packages-by-name wrong #f))))
1146 (test-equal "find-packages-by-name with cache"
1147 (find-packages-by-name "guile")
1148 (call-with-temporary-directory
1150 (generate-package-cache cache)
1151 (mock ((guix describe) current-profile (const cache))
1152 (mock ((gnu packages) cache-is-authoritative? (const #t))
1153 (find-packages-by-name "guile"))))))
1155 (test-equal "find-packages-by-name + version, with cache"
1156 (find-packages-by-name "guile" "2")
1157 (call-with-temporary-directory
1159 (generate-package-cache cache)
1160 (mock ((guix describe) current-profile (const cache))
1161 (mock ((gnu packages) cache-is-authoritative? (const #t))
1162 (find-packages-by-name "guile" "2"))))))
1164 (test-assert "--search-paths with pattern"
1165 ;; Make sure 'guix package --search-paths' correctly reports environment
1166 ;; variables when file patterns are used (in particular, it must follow
1167 ;; symlinks when looking for 'catalog.xml'.) To do that, we rely on the
1168 ;; libxml2 package specification, which contains such a definition.
1170 (name "foo") (version "0") (source #f)
1171 (build-system trivial-build-system)
1173 `(#:guile ,%bootstrap-guile
1174 #:modules ((guix build utils))
1176 (use-modules (guix build utils))
1177 (let ((out (assoc-ref %outputs "out")))
1178 (mkdir-p (string-append out "/xml/bar/baz"))
1179 (call-with-output-file
1180 (string-append out "/xml/bar/baz/catalog.xml")
1182 (display "xml? wat?!" port)))
1184 (synopsis #f) (description #f)
1185 (home-page #f) (license #f)))
1187 ;; Provide a fake libxml2 to avoid building the real one. This
1188 ;; is OK because 'guix package' gets search path specifications
1189 ;; from the same-named package found in the distro.
1190 (name "libxml2") (version "0.0.0") (source #f)
1191 (build-system trivial-build-system)
1193 `(#:guile ,%bootstrap-guile
1195 (mkdir (assoc-ref %outputs "out"))
1197 (native-search-paths (package-native-search-paths libxml2))
1198 (synopsis #f) (description #f)
1199 (home-page #f) (license #f)))
1200 (prof (run-with-store %store
1202 (manifest (map package->manifest-entry
1206 #:guile-for-build (%guile-for-build))))
1207 (build-derivations %store (list prof))
1208 (string-match (format #f "^export XML_CATALOG_FILES=\"~a/xml/+bar/baz/catalog\\.xml\"\n"
1209 (regexp-quote (derivation->output-path prof)))
1210 (with-output-to-string
1212 (guix-package "-p" (derivation->output-path prof)
1213 "--search-paths"))))))
1215 (test-assert "--search-paths with single-item search path"
1216 ;; Make sure 'guix package --search-paths' correctly reports environment
1217 ;; variables for things like 'GIT_SSL_CAINFO' that have #f as their
1218 ;; separator, meaning that the first match wins.
1219 (let* ((p1 (dummy-package "foo"
1220 (build-system trivial-build-system)
1222 `(#:guile ,%bootstrap-guile
1223 #:modules ((guix build utils))
1225 (use-modules (guix build utils))
1226 (let ((out (assoc-ref %outputs "out")))
1227 (mkdir-p (string-append out "/etc/ssl/certs"))
1228 (call-with-output-file
1230 out "/etc/ssl/certs/ca-certificates.crt")
1232 (p2 (package (inherit p1) (name "bar")))
1233 (p3 (dummy-package "git"
1234 ;; Provide a fake Git to avoid building the real one.
1235 (build-system trivial-build-system)
1237 `(#:guile ,%bootstrap-guile
1239 (mkdir (assoc-ref %outputs "out"))
1241 (native-search-paths (package-native-search-paths git))))
1242 (prof1 (run-with-store %store
1244 (packages->manifest (list p1 p3))
1247 #:guile-for-build (%guile-for-build)))
1248 (prof2 (run-with-store %store
1250 (packages->manifest (list p2 p3))
1253 #:guile-for-build (%guile-for-build))))
1254 (build-derivations %store (list prof1 prof2))
1255 (string-match (format #f "^export GIT_SSL_CAINFO=\"~a/etc/ssl/certs/ca-certificates.crt"
1256 (regexp-quote (derivation->output-path prof1)))
1257 (with-output-to-string
1259 (guix-package "-p" (derivation->output-path prof1)
1260 "-p" (derivation->output-path prof2)
1261 "--search-paths"))))))
1263 (test-equal "specification->package when not found"
1267 ;; This should call 'leave', producing an error message.
1268 (specification->package "this-package-does-not-exist"))
1269 (lambda (key . args)
1272 (test-equal "specification->package+output"
1273 `((,coreutils "out") (,coreutils "debug"))
1274 (list (call-with-values (lambda ()
1275 (specification->package+output "coreutils"))
1277 (call-with-values (lambda ()
1278 (specification->package+output "coreutils:debug"))
1281 (test-equal "specification->package+output invalid output"
1285 (specification->package+output "coreutils:does-not-exist"))
1289 (test-equal "specification->package+output no default output"
1293 (specification->package+output "coreutils" #f))
1296 (test-equal "specification->package+output invalid output, no default"
1300 (specification->package+output "coreutils:does-not-exist" #f))
1304 (test-equal "find-package-locations"
1305 (map (lambda (package)
1306 (cons (package-version package)
1307 (package-location package)))
1308 (find-packages-by-name "guile"))
1309 (find-package-locations "guile"))
1311 (test-equal "find-package-locations with cache"
1312 (map (lambda (package)
1313 (cons (package-version package)
1314 (package-location package)))
1315 (find-packages-by-name "guile"))
1316 (call-with-temporary-directory
1318 (generate-package-cache cache)
1319 (mock ((guix describe) current-profile (const cache))
1320 (mock ((gnu packages) cache-is-authoritative? (const #t))
1321 (find-package-locations "guile"))))))
1323 (test-equal "specification->location"
1324 (package-location (specification->package "guile@2"))
1325 (specification->location "guile@2"))
1327 (test-end "packages")
1329 ;;; Local Variables:
1330 ;;; eval: (put 'dummy-package 'scheme-indent-function 1)
1331 ;;; eval: (put 'dummy-package/no-implicit 'scheme-indent-function 1)