1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 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 ((@@ (guix scripts package) transaction-upgrade-entry)
105 (inherit (package->manifest-entry old))
106 (item (string-append (%store-prefix) "/"
107 (make-string 32 #\e) "-foo-1")))
108 (manifest-transaction)))))
109 (manifest-transaction-null? tx)))
111 (test-assert "transaction-upgrade-entry, one upgrade"
112 (let* ((old (dummy-package "foo" (version "1")))
113 (new (dummy-package "foo" (version "2")))
114 (tx (mock ((gnu packages) find-best-packages-by-name
116 ((@@ (guix scripts package) transaction-upgrade-entry)
118 (inherit (package->manifest-entry old))
119 (item (string-append (%store-prefix) "/"
120 (make-string 32 #\e) "-foo-1")))
121 (manifest-transaction)))))
122 (and (match (manifest-transaction-install tx)
123 ((($ <manifest-entry> "foo" "2" "out" item))
125 (null? (manifest-transaction-remove tx)))))
127 (test-assert "transaction-upgrade-entry, superseded package"
128 (let* ((old (dummy-package "foo" (version "1")))
129 (new (dummy-package "bar" (version "2")))
130 (dep (deprecated-package "foo" new))
131 (tx (mock ((gnu packages) find-best-packages-by-name
133 ((@@ (guix scripts package) transaction-upgrade-entry)
135 (inherit (package->manifest-entry old))
136 (item (string-append (%store-prefix) "/"
137 (make-string 32 #\e) "-foo-1")))
138 (manifest-transaction)))))
139 (and (match (manifest-transaction-install tx)
140 ((($ <manifest-entry> "bar" "2" "out" item))
142 (match (manifest-transaction-remove tx)
143 (((? manifest-pattern? pattern))
144 (and (string=? (manifest-pattern-name pattern) "foo")
145 (string=? (manifest-pattern-version pattern) "1")
146 (string=? (manifest-pattern-output pattern) "out")))))))
148 (test-assert "package-field-location"
150 (define (goto port line column)
151 (unless (and (= (port-column port) (- column 1))
152 (= (port-line port) (- line 1)))
153 (unless (eof-object? (get-char port))
154 (goto port line column))))
158 (($ <location> file line column)
159 (call-with-input-file (search-path %load-path file)
161 (goto port line column)
164 ;; Until Guile 2.0.6 included, source properties were added only to pairs.
165 ;; Thus, check against both VALUE and (FIELD VALUE).
166 (and (member (read-at (package-field-location %bootstrap-guile 'name))
167 (let ((name (package-name %bootstrap-guile)))
168 (list name `(name ,name))))
169 (member (read-at (package-field-location %bootstrap-guile 'version))
170 (let ((version (package-version %bootstrap-guile)))
171 (list version `(version ,version))))
172 (not (package-field-location %bootstrap-guile 'does-not-exist)))))
174 ;; Make sure we don't change the file name to an absolute file name.
175 (test-equal "package-field-location, relative file name"
176 (location-file (package-location %bootstrap-guile))
177 (with-fluids ((%file-port-name-canonicalization 'absolute))
178 (location-file (package-field-location %bootstrap-guile 'version))))
180 (test-assert "package-transitive-inputs"
181 (let* ((a (dummy-package "a"))
182 (b (dummy-package "b"
183 (propagated-inputs `(("a" ,a)))))
184 (c (dummy-package "c"
185 (inputs `(("a" ,a)))))
186 (d (dummy-package "d"
187 (propagated-inputs `(("x" "something.drv")))))
188 (e (dummy-package "e"
189 (inputs `(("b" ,b) ("c" ,c) ("d" ,d))))))
190 (and (null? (package-transitive-inputs a))
191 (equal? `(("a" ,a)) (package-transitive-inputs b))
192 (equal? `(("a" ,a)) (package-transitive-inputs c))
193 (equal? (package-propagated-inputs d)
194 (package-transitive-inputs d))
195 (equal? `(("b" ,b) ("c" ,c) ("d" ,d)
196 ("a" ,a) ("x" "something.drv"))
197 (pk 'x (package-transitive-inputs e))))))
199 (test-assert "package-transitive-inputs, no duplicates"
200 (let* ((a (dummy-package "a"))
201 (b (dummy-package "b"
202 (inputs `(("a+" ,a)))
203 (native-inputs `(("a*" ,a)))
204 (propagated-inputs `(("a" ,a)))))
205 (c (dummy-package "c"
206 (propagated-inputs `(("b" ,b)))))
207 (d (dummy-package "d"
208 (inputs `(("a" ,a) ("c" ,c)))))
209 (e (dummy-package "e"
210 (inputs `(("b" ,b) ("c" ,c))))))
211 (and (null? (package-transitive-inputs a))
212 (equal? `(("a*" ,a) ("a+" ,a) ("a" ,a)) ;here duplicates are kept
213 (package-transitive-inputs b))
214 (equal? `(("b" ,b) ("a" ,a))
215 (package-transitive-inputs c))
216 (equal? `(("a" ,a) ("c" ,c) ("b" ,b)) ;duplicate A removed
217 (package-transitive-inputs d))
218 (equal? `(("b" ,b) ("c" ,c) ("a" ,a))
219 (package-transitive-inputs e))))) ;ditto
221 (test-equal "package-transitive-supported-systems"
227 ;; Use TRIVIAL-BUILD-SYSTEM because it doesn't add implicit inputs and thus
228 ;; doesn't restrict the set of supported systems.
229 (let* ((a (dummy-package "a"
230 (build-system trivial-build-system)
231 (supported-systems '("x" "y" "z"))))
232 (b (dummy-package "b"
233 (build-system trivial-build-system)
234 (supported-systems '("x" "y"))
235 (inputs `(("a" ,a)))))
236 (c (dummy-package "c"
237 (build-system trivial-build-system)
238 (supported-systems '("y" "z"))
239 (inputs `(("b" ,b)))))
240 (d (dummy-package "d"
241 (build-system trivial-build-system)
242 (supported-systems '("x" "y" "z"))
243 (inputs `(("b" ,b) ("c" ,c)))))
244 (e (dummy-package "e"
245 (build-system trivial-build-system)
246 (supported-systems '("x" "y" "z"))
247 (inputs `(("d" ,d))))))
248 (list (package-transitive-supported-systems a)
249 (package-transitive-supported-systems b)
250 (package-transitive-supported-systems c)
251 (package-transitive-supported-systems d)
252 (package-transitive-supported-systems e))))
254 (test-assert "package-closure"
255 (let-syntax ((dummy-package/no-implicit
259 (inherit (dummy-package name rest ...))
260 (build-system trivial-build-system))))))
261 (let* ((a (dummy-package/no-implicit "a"))
262 (b (dummy-package/no-implicit "b"
263 (propagated-inputs `(("a" ,a)))))
264 (c (dummy-package/no-implicit "c"
265 (inputs `(("a" ,a)))))
266 (d (dummy-package/no-implicit "d"
267 (native-inputs `(("b" ,b)))))
268 (e (dummy-package/no-implicit "e"
269 (inputs `(("c" ,c) ("d" ,d))))))
272 (package-closure (list e))
273 (package-closure (list e d))
274 (package-closure (list e c b))))))
276 (test-equal "origin-actual-file-name"
278 (let ((o (dummy-origin (uri "http://www.example.com/foo-1.tar.gz"))))
279 (origin-actual-file-name o)))
281 (test-equal "origin-actual-file-name, file-name"
283 (let ((o (dummy-origin
284 (uri "http://www.example.com/tarball")
285 (file-name "foo-1.tar.gz"))))
286 (origin-actual-file-name o)))
288 (let* ((o (dummy-origin))
291 (a (dummy-package "a"))
292 (b (dummy-package "b"
293 (inputs `(("a" ,a) ("i" ,i)))))
294 (c (package (inherit b) (source o)))
295 (d (dummy-package "d"
296 (build-system trivial-build-system)
297 (source u) (inputs `(("c" ,c))))))
298 (test-assert "package-direct-sources, no source"
299 (null? (package-direct-sources a)))
300 (test-equal "package-direct-sources, #f source"
302 (package-direct-sources b))
303 (test-equal "package-direct-sources, not input source"
305 (package-direct-sources d))
306 (test-assert "package-direct-sources"
307 (let ((s (package-direct-sources c)))
308 (and (= (length (pk 's-sources s)) 2)
311 (test-assert "package-transitive-sources"
312 (let ((s (package-transitive-sources d)))
313 (and (= (length (pk 'd-sources s)) 3)
318 (test-assert "transitive-input-references"
319 (let* ((a (dummy-package "a"))
320 (b (dummy-package "b"))
321 (c (dummy-package "c"
323 (propagated-inputs `(("boo" ,b)))))
324 (d (dummy-package "d"
325 (inputs `(("c*" ,c)))))
326 (keys (map (match-lambda
329 (pk 'refs (transitive-input-references
330 'l (package-inputs d))))))
331 (and (= (length keys) 2)
333 (member "boo" keys))))
335 (test-equal "package-transitive-supported-systems, implicit inputs"
338 ;; Here GNU-BUILD-SYSTEM adds implicit inputs that build only on
339 ;; %SUPPORTED-SYSTEMS. Thus the others must be ignored.
340 (let ((p (dummy-package "foo"
341 (build-system gnu-build-system)
343 `("does-not-exist" "foobar" ,@%supported-systems)))))
344 (invalidate-memoization! package-transitive-supported-systems)
345 (parameterize ((%current-system "armhf-linux")) ; a traditionally-bootstrapped architecture
346 (package-transitive-supported-systems p))))
348 (test-equal "package-transitive-supported-systems: reduced binary seed, implicit inputs"
349 '("x86_64-linux" "i686-linux")
351 ;; Here GNU-BUILD-SYSTEM adds implicit inputs that build only on
352 ;; %SUPPORTED-SYSTEMS. Thus the others must be ignored.
353 (let ((p (dummy-package "foo"
354 (build-system gnu-build-system)
356 `("does-not-exist" "foobar" ,@%supported-systems)))))
357 (invalidate-memoization! package-transitive-supported-systems)
358 (parameterize ((%current-system "x86_64-linux"))
359 (package-transitive-supported-systems p))))
361 (test-assert "supported-package?"
362 (let ((p (dummy-package "foo"
363 (build-system gnu-build-system)
364 (supported-systems '("x86_64-linux" "does-not-exist")))))
365 (and (supported-package? p "x86_64-linux")
366 (not (supported-package? p "does-not-exist"))
367 (not (supported-package? p "i686-linux")))))
369 (test-skip (if (not %store) 8 0))
371 (test-assert "package-source-derivation, file"
372 (let* ((file (search-path %load-path "guix.scm"))
373 (package (package (inherit (dummy-package "p"))
375 (source (package-source-derivation %store
376 (package-source package))))
377 (and (store-path? source)
378 (valid-path? %store source)
379 (equal? (call-with-input-file source get-bytevector-all)
380 (call-with-input-file file get-bytevector-all)))))
382 (test-assert "package-source-derivation, store path"
383 (let* ((file (add-to-store %store "guix.scm" #t "sha256"
384 (search-path %load-path "guix.scm")))
385 (package (package (inherit (dummy-package "p"))
387 (source (package-source-derivation %store
388 (package-source package))))
389 (string=? file source)))
391 (test-assert "package-source-derivation, indirect store path"
392 (let* ((dir (add-to-store %store "guix-build" #t "sha256"
393 (dirname (search-path %load-path
394 "guix/build/utils.scm"))))
395 (package (package (inherit (dummy-package "p"))
396 (source (string-append dir "/utils.scm"))))
397 (source (package-source-derivation %store
398 (package-source package))))
399 (and (direct-store-path? source)
400 (string-suffix? "utils.scm" source))))
402 (test-assert "package-source-derivation, local-file"
403 (let* ((file (local-file "../guix/base32.scm"))
404 (package (package (inherit (dummy-package "p"))
406 (source (package-source-derivation %store
407 (package-source package))))
408 (and (store-path? source)
409 (string-suffix? "base32.scm" source)
410 (valid-path? %store source)
411 (equal? (call-with-input-file source get-bytevector-all)
412 (call-with-input-file
413 (search-path %load-path "guix/base32.scm")
414 get-bytevector-all)))))
416 (unless (network-reachable?) (test-skip 1))
417 (test-equal "package-source-derivation, snippet"
419 (let* ((source (bootstrap-origin
421 (inherit (bootstrap-guile-origin (%current-system)))
423 `(("tar" ,%bootstrap-coreutils&co)
424 ("xz" ,%bootstrap-coreutils&co)
425 ("patch" ,%bootstrap-coreutils&co)))
426 (patch-guile %bootstrap-guile)
427 (modules '((guix build utils)))
429 ;; We end up in 'bin', because it's the first
430 ;; directory, alphabetically. Not a very good
433 (symlink "guile" "guile-rocks")
434 (copy-recursively "../share/guile/2.0/scripts"
437 ;; Make sure '.file_list' can be created.
438 (chmod ".." #o777))))))
439 (package (package (inherit (dummy-package "with-snippet"))
441 (build-system trivial-build-system)
443 `(("tar" ,(search-bootstrap-binary "tar"
445 ("xz" ,(search-bootstrap-binary "xz"
446 (%current-system)))))
448 `(#:guile ,%bootstrap-guile
449 #:modules ((guix build utils))
452 (use-modules (guix build utils))
453 (let ((tar (assoc-ref %build-inputs "tar"))
454 (xz (assoc-ref %build-inputs "xz"))
455 (source (assoc-ref %build-inputs "source")))
456 (invoke tar "xvf" source
457 "--use-compress-program" xz)
458 (unless (and (string=? "guile" (readlink "bin/guile-rocks"))
459 (file-exists? "bin/scripts/compile.scm"))
460 (error "the snippet apparently failed"))
461 (let ((out (assoc-ref %outputs "out")))
462 (call-with-output-file out
466 (drv (package-derivation %store package))
467 (out (derivation->output-path drv)))
468 (and (build-derivations %store (list (pk 'snippet-drv drv)))
469 (call-with-input-file out get-string-all))))
471 (test-assert "return value"
472 (let ((drv (package-derivation %store (dummy-package "p"))))
473 (and (derivation? drv)
474 (file-exists? (derivation-file-name drv)))))
476 (test-assert "package-output"
477 (let* ((package (dummy-package "p"))
478 (drv (package-derivation %store package)))
479 (and (derivation? drv)
480 (string=? (derivation->output-path drv)
481 (package-output %store package "out")))))
483 (test-assert "patch not found yields a run-time error"
484 (guard (c ((condition-has-type? c &message)
485 (and (string-contains (condition-message c)
486 "does-not-exist.patch")
487 (string-contains (condition-message c)
490 (inherit (dummy-package "p"))
493 (uri "http://whatever")
495 (list (search-patch "does-not-exist.patch")))
498 "0amn0bbwqvsvvsh6drfwz20ydc2czk374lzw5kksbh6bf78k4ks4")))))))
499 (package-derivation %store p)
502 (let ((dummy (dummy-package "foo" (inputs `(("x" ,(current-module)))))))
503 (test-equal "&package-input-error"
504 (list dummy (current-module))
505 (guard (c ((package-input-error? c)
506 (list (package-error-package c)
507 (package-error-invalid-input c))))
508 (package-derivation %store dummy))))
510 (test-assert "reference to non-existent output"
511 ;; See <http://bugs.gnu.org/19630>.
512 (parameterize ((%graft? #f))
513 (let* ((dep (dummy-package "dep"))
514 (p (dummy-package "p"
515 (inputs `(("dep" ,dep "non-existent"))))))
516 (guard (c ((derivation-missing-output-error? c)
517 (and (string=? (derivation-missing-output c) "non-existent")
518 (equal? (package-derivation %store dep)
519 (derivation-error-derivation c)))))
520 (package-derivation %store p)))))
522 (test-assert "trivial"
523 (let* ((p (package (inherit (dummy-package "trivial"))
524 (build-system trivial-build-system)
527 `(#:guile ,%bootstrap-guile
531 (call-with-output-file (string-append %output "/test")
533 (display '(hello guix) p)))
535 (d (package-derivation %store p)))
536 (and (build-derivations %store (list d))
537 (let ((p (pk 'drv d (derivation->output-path d))))
538 (equal? '(hello guix)
539 (call-with-input-file (string-append p "/test") read))))))
541 (test-assert "trivial with local file as input"
542 (let* ((i (search-path %load-path "ice-9/boot-9.scm"))
543 (p (package (inherit (dummy-package "trivial-with-input-file"))
544 (build-system trivial-build-system)
547 `(#:guile ,%bootstrap-guile
549 (copy-file (assoc-ref %build-inputs "input")
552 (inputs `(("input" ,i)))))
553 (d (package-derivation %store p)))
554 (and (build-derivations %store (list d))
555 (let ((p (pk 'drv d (derivation->output-path d))))
556 (equal? (call-with-input-file p get-bytevector-all)
557 (call-with-input-file i get-bytevector-all))))))
559 (test-assert "trivial with source"
560 (let* ((i (search-path %load-path "ice-9/boot-9.scm"))
561 (p (package (inherit (dummy-package "trivial-with-source"))
562 (build-system trivial-build-system)
565 `(#:guile ,%bootstrap-guile
567 (copy-file (assoc-ref %build-inputs "source")
570 (d (package-derivation %store p)))
571 (and (build-derivations %store (list d))
572 (let ((p (derivation->output-path d)))
573 (equal? (call-with-input-file p get-bytevector-all)
574 (call-with-input-file i get-bytevector-all))))))
576 (test-assert "trivial with system-dependent input"
577 (let* ((p (package (inherit (dummy-package "trivial-system-dependent-input"))
578 (build-system trivial-build-system)
581 `(#:guile ,%bootstrap-guile
582 #:modules ((guix build utils))
585 (use-modules (guix build utils))
586 (let ((out (assoc-ref %outputs "out"))
587 (bash (assoc-ref %build-inputs "bash")))
589 (format #f "echo hello > ~a" out))))))
590 (inputs `(("bash" ,(search-bootstrap-binary "bash"
591 (%current-system)))))))
592 (d (package-derivation %store p)))
593 (and (build-derivations %store (list d))
594 (let ((p (pk 'drv d (derivation->output-path d))))
595 (eq? 'hello (call-with-input-file p read))))))
597 (test-assert "trivial with #:allowed-references"
599 (inherit (dummy-package "trivial"))
600 (build-system trivial-build-system)
602 `(#:guile ,%bootstrap-guile
603 #:allowed-references (,%bootstrap-guile)
607 ;; The reference to itself isn't allowed so building it
609 (symlink %output (string-append %output "/self"))
611 (d (package-derivation %store p)))
612 (guard (c ((store-protocol-error? c) #t))
613 (build-derivations %store (list d))
616 (test-assert "search paths"
617 (let* ((p (make-prompt-tag "return-search-paths"))
620 (description "Raw build system with direct store access")
621 (lower (lambda* (name #:key source inputs system target
625 (system system) (target target)
626 (build-inputs inputs)
628 (lambda* (store name inputs
629 #:key outputs system search-paths)
631 (x (list (search-path-specification
632 (variable "GUILE_LOAD_PATH")
633 (files '("share/guile/site/2.0")))
634 (search-path-specification
635 (variable "GUILE_LOAD_COMPILED_PATH")
636 (files '("share/guile/site/2.0")))))
637 (a (package (inherit (dummy-package "guile"))
639 (native-search-paths x)))
640 (b (package (inherit (dummy-package "guile-foo"))
642 (inputs `(("guile" ,a)))))
643 (c (package (inherit (dummy-package "guile-bar"))
645 (inputs `(("guile" ,a)
646 ("guile-foo" ,b))))))
647 (let-syntax ((collect (syntax-rules ()
652 (lambda (k search-paths)
654 (and (null? (collect (package-derivation %store a)))
655 (equal? x (collect (package-derivation %store b)))
656 (equal? x (collect (package-derivation %store c)))))))
658 (test-assert "package-transitive-native-search-paths"
659 (let* ((sp (lambda (name)
660 (list (search-path-specification
662 (files '("foo/bar"))))))
663 (p0 (dummy-package "p0" (native-search-paths (sp "PATH0"))))
664 (p1 (dummy-package "p1" (native-search-paths (sp "PATH1"))))
665 (p2 (dummy-package "p2"
666 (native-search-paths (sp "PATH2"))
667 (inputs `(("p0" ,p0)))
668 (propagated-inputs `(("p1" ,p1)))))
669 (p3 (dummy-package "p3"
670 (native-search-paths (sp "PATH3"))
671 (native-inputs `(("p0" ,p0)))
672 (propagated-inputs `(("p2" ,p2))))))
674 '("PATH1" "PATH2" "PATH3")
675 (map search-path-specification-variable
676 (package-transitive-native-search-paths p3)))))
678 (test-assert "package-cross-derivation"
679 (let ((drv (package-cross-derivation %store (dummy-package "p")
680 "mips64el-linux-gnu")))
681 (and (derivation? drv)
682 (file-exists? (derivation-file-name drv)))))
684 (test-assert "package-cross-derivation, trivial-build-system"
685 (let ((p (package (inherit (dummy-package "p"))
686 (build-system trivial-build-system)
687 (arguments '(#:builder (exit 1))))))
688 (let ((drv (package-cross-derivation %store p "mips64el-linux-gnu")))
691 (test-assert "package-cross-derivation, no cross builder"
692 (let* ((b (build-system (inherit trivial-build-system)
694 (p (package (inherit (dummy-package "p"))
696 (guard (c ((package-cross-build-system-error? c)
697 (eq? (package-error-package c) p)))
698 (package-cross-derivation %store p "mips64el-linux-gnu")
701 ;; XXX: The next two tests can trigger builds when the distro defines
702 ;; replacements on core packages, so they're disable for lack of a better
705 ;; (test-equal "package-derivation, direct graft"
706 ;; (package-derivation %store gnu-make #:graft? #f)
707 ;; (let ((p (package (inherit coreutils)
708 ;; (replacement gnu-make))))
709 ;; (package-derivation %store p #:graft? #t)))
711 ;; (test-equal "package-cross-derivation, direct graft"
712 ;; (package-cross-derivation %store gnu-make "mips64el-linux-gnu"
714 ;; (let ((p (package (inherit coreutils)
715 ;; (replacement gnu-make))))
716 ;; (package-cross-derivation %store p "mips64el-linux-gnu"
719 (test-assert "package-grafts, indirect grafts"
720 (let* ((new (dummy-package "dep"
721 (arguments '(#:implicit-inputs? #f))))
722 (dep (package (inherit new) (version "0.0")))
723 (dep* (package (inherit dep) (replacement new)))
724 (dummy (dummy-package "dummy"
725 (arguments '(#:implicit-inputs? #f))
726 (inputs `(("dep" ,dep*))))))
727 (equal? (package-grafts %store dummy)
729 (origin (package-derivation %store dep))
730 (replacement (package-derivation %store new)))))))
732 ;; XXX: This test would require building the cross toolchain just to see if it
733 ;; needs grafting, which is obviously too expensive, and thus disabled.
735 ;; (test-assert "package-grafts, indirect grafts, cross"
736 ;; (let* ((new (dummy-package "dep"
737 ;; (arguments '(#:implicit-inputs? #f))))
738 ;; (dep (package (inherit new) (version "0.0")))
739 ;; (dep* (package (inherit dep) (replacement new)))
740 ;; (dummy (dummy-package "dummy"
741 ;; (arguments '(#:implicit-inputs? #f))
742 ;; (inputs `(("dep" ,dep*)))))
743 ;; (target "mips64el-linux-gnu"))
744 ;; ;; XXX: There might be additional grafts, for instance if the distro
745 ;; ;; defines replacements for core packages like Perl.
747 ;; (origin (package-cross-derivation %store dep target))
749 ;; (package-cross-derivation %store new target)))
750 ;; (package-grafts %store dummy #:target target))))
752 (test-assert "package-grafts, indirect grafts, propagated inputs"
753 (let* ((new (dummy-package "dep"
754 (arguments '(#:implicit-inputs? #f))))
755 (dep (package (inherit new) (version "0.0")))
756 (dep* (package (inherit dep) (replacement new)))
757 (prop (dummy-package "propagated"
758 (propagated-inputs `(("dep" ,dep*)))
759 (arguments '(#:implicit-inputs? #f))))
760 (dummy (dummy-package "dummy"
761 (arguments '(#:implicit-inputs? #f))
762 (inputs `(("prop" ,prop))))))
763 (equal? (package-grafts %store dummy)
765 (origin (package-derivation %store dep))
766 (replacement (package-derivation %store new)))))))
768 (test-assert "package-grafts, same replacement twice"
769 (let* ((new (dummy-package "dep"
771 (arguments '(#:implicit-inputs? #f))))
772 (dep (package (inherit new) (version "0") (replacement new)))
773 (p1 (dummy-package "intermediate1"
774 (arguments '(#:implicit-inputs? #f))
775 (inputs `(("dep" ,dep)))))
776 (p2 (dummy-package "intermediate2"
777 (arguments '(#:implicit-inputs? #f))
778 ;; Here we copy DEP to have an equivalent package that is not
779 ;; 'eq?' to DEP. This is similar to what happens with
780 ;; 'package-with-explicit-inputs' & co.
781 (inputs `(("dep" ,(package (inherit dep)))))))
782 (p3 (dummy-package "final"
783 (arguments '(#:implicit-inputs? #f))
784 (inputs `(("p1" ,p1) ("p2" ,p2))))))
785 (equal? (package-grafts %store p3)
787 (origin (package-derivation %store
788 (package (inherit dep)
790 (replacement (package-derivation %store new)))))))
792 (test-assert "replacement also grafted"
793 ;; We build a DAG as below, where dotted arrows represent replacements and
794 ;; solid arrows represent dependencies:
796 ;; P1 ·············> P1R
797 ;; |\__________________.
799 ;; P2 ·············> P2R
804 ;; We want to make sure that:
805 ;; grafts(P3) = (P1,P1R) + (P2, grafted(P2R, (P1,P1R)))
807 ;; (A,B) is a graft to replace A by B
808 ;; grafted(DRV,G) denoted DRV with graft G applied
809 (let* ((p1r (dummy-package "P1"
810 (build-system trivial-build-system)
812 `(#:guile ,%bootstrap-guile
813 #:builder (let ((out (assoc-ref %outputs "out")))
815 (call-with-output-file
816 (string-append out "/replacement")
819 (inherit p1r) (name "p1") (replacement p1r)
821 `(#:guile ,%bootstrap-guile
823 (mkdir (assoc-ref %outputs "out"))
825 (p2r (dummy-package "P2"
826 (build-system trivial-build-system)
827 (inputs `(("p1" ,p1)))
829 `(#:guile ,%bootstrap-guile
830 #:builder (let ((out (assoc-ref %outputs "out")))
833 (symlink (assoc-ref %build-inputs "p1") "p1")
834 (call-with-output-file (string-append out "/replacement")
837 (inherit p2r) (name "p2") (replacement p2r)
839 `(#:guile ,%bootstrap-guile
840 #:builder (let ((out (assoc-ref %outputs "out")))
843 (symlink (assoc-ref %build-inputs "p1")
846 (p3 (dummy-package "p3"
847 (build-system trivial-build-system)
848 (inputs `(("p2" ,p2)))
850 `(#:guile ,%bootstrap-guile
851 #:builder (let ((out (assoc-ref %outputs "out")))
854 (symlink (assoc-ref %build-inputs "p2")
858 (package-grafts %store p3)
860 (origin (package-derivation %store p1 #:graft? #f))
861 (replacement (package-derivation %store p1r)))
863 (origin (package-derivation %store p2 #:graft? #f))
865 (package-derivation %store p2r #:graft? #t)))))))
867 ;;; XXX: Nowadays 'graft-derivation' needs to build derivations beforehand to
868 ;;; find out about their run-time dependencies, so this test is no longer
869 ;;; applicable since it would trigger a full rebuild.
871 ;; (test-assert "package-derivation, indirect grafts"
872 ;; (let* ((new (dummy-package "dep"
873 ;; (arguments '(#:implicit-inputs? #f))))
874 ;; (dep (package (inherit new) (version "0.0")))
875 ;; (dep* (package (inherit dep) (replacement new)))
876 ;; (dummy (dummy-package "dummy"
877 ;; (arguments '(#:implicit-inputs? #f))
878 ;; (inputs `(("dep" ,dep*)))))
879 ;; (guile (package-derivation %store (canonical-package guile-2.0)
881 ;; (equal? (package-derivation %store dummy)
882 ;; (graft-derivation %store
883 ;; (package-derivation %store dummy #:graft? #f)
884 ;; (package-grafts %store dummy)
886 ;; ;; Use the same Guile as 'package-derivation'.
889 (test-equal "package->bag"
890 `("foo86-hurd" #f (,(package-source gnu-make))
891 (,(canonical-package glibc)) (,(canonical-package coreutils)))
892 (let ((bag (package->bag gnu-make "foo86-hurd")))
893 (list (bag-system bag) (bag-target bag)
894 (assoc-ref (bag-build-inputs bag) "source")
895 (assoc-ref (bag-build-inputs bag) "libc")
896 (assoc-ref (bag-build-inputs bag) "coreutils"))))
898 (test-equal "package->bag, cross-compilation"
899 `(,(%current-system) "foo86-hurd"
900 (,(package-source gnu-make))
901 (,(canonical-package glibc)) (,(canonical-package coreutils)))
902 (let ((bag (package->bag gnu-make (%current-system) "foo86-hurd")))
903 (list (bag-system bag) (bag-target bag)
904 (assoc-ref (bag-build-inputs bag) "source")
905 (assoc-ref (bag-build-inputs bag) "libc")
906 (assoc-ref (bag-build-inputs bag) "coreutils"))))
908 (test-assert "package->bag, propagated inputs"
909 (let* ((dep (dummy-package "dep"))
910 (prop (dummy-package "prop"
911 (propagated-inputs `(("dep" ,dep)))))
912 (dummy (dummy-package "dummy"
913 (inputs `(("prop" ,prop)))))
914 (inputs (bag-transitive-inputs (package->bag dummy #:graft? #f))))
915 (match (assoc "dep" inputs)
917 (eq? package dep)))))
919 (test-assert "bag->derivation"
920 (parameterize ((%graft? #f))
921 (let ((bag (package->bag gnu-make))
922 (drv (package-derivation %store gnu-make)))
923 (parameterize ((%current-system "foox86-hurd")) ;should have no effect
924 (equal? drv (bag->derivation %store bag))))))
926 (test-assert "bag->derivation, cross-compilation"
927 (parameterize ((%graft? #f))
928 (let* ((target "mips64el-linux-gnu")
929 (bag (package->bag gnu-make (%current-system) target))
930 (drv (package-cross-derivation %store gnu-make target)))
931 (parameterize ((%current-system "foox86-hurd") ;should have no effect
932 (%current-target-system "foo64-linux-gnu"))
933 (equal? drv (bag->derivation %store bag))))))
935 (when (or (not (network-reachable?)) (shebang-too-long?))
937 (test-assert "GNU Make, bootstrap"
938 ;; GNU-MAKE-FOR-TESTS can be built cheaply; we choose it here so that the
939 ;; test doesn't last for too long.
940 (let ((gnu-make gnu-make-for-tests))
941 (and (package? gnu-make)
942 (or (location? (package-location gnu-make))
943 (not (package-location gnu-make)))
944 (let* ((drv (package-derivation %store gnu-make))
945 (out (derivation->output-path drv)))
946 (and (build-derivations %store (list drv))
947 (file-exists? (string-append out "/bin/make")))))))
949 (test-equal "package-mapping"
951 (let* ((dep (dummy-package "chbouib"
952 (native-inputs `(("x" ,grep)))))
953 (p0 (dummy-package "example"
954 (inputs `(("foo" ,coreutils)
957 (transform (lambda (p)
958 (package (inherit p) (source 42))))
959 (rewrite (package-mapping transform))
961 (and (eq? p1 (rewrite p0))
962 (eqv? 42 (package-source p1))
963 (match (package-inputs p1)
964 ((("foo" dep1) ("bar" dep2) ("baz" dep3))
965 (and (eq? dep1 (rewrite coreutils)) ;memoization
966 (eq? dep2 (rewrite grep))
967 (eq? dep3 (rewrite dep))
969 (package-source dep1) (package-source dep2)
970 (package-source dep3))
971 (match (package-native-inputs dep3)
973 (and (eq? dep (rewrite grep))
974 (package-source dep))))))))))
976 (test-assert "package-input-rewriting"
977 (let* ((dep (dummy-package "chbouib"
978 (native-inputs `(("x" ,grep)))))
979 (p0 (dummy-package "example"
980 (inputs `(("foo" ,coreutils)
983 (rewrite (package-input-rewriting `((,coreutils . ,sed)
984 (,grep . ,findutils))
985 (cut string-append "r-" <>)))
988 (and (not (eq? p1 p0))
989 (eq? p1 p2) ;memoization
990 (string=? "r-example" (package-name p1))
991 (match (package-inputs p1)
992 ((("foo" dep1) ("bar" dep2) ("baz" dep3))
995 (string=? (package-name dep3) "r-chbouib")
996 (eq? dep3 (rewrite dep)) ;memoization
997 (match (package-native-inputs dep3)
999 (eq? dep findutils)))))))))
1001 (test-assert "package-input-rewriting/spec"
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/spec
1009 `(("coreutils" . ,(const sed))
1010 ("grep" . ,(const findutils)))))
1013 (and (not (eq? p1 p0))
1014 (eq? p1 p2) ;memoization
1015 (string=? "example" (package-name p1))
1016 (match (package-inputs p1)
1017 ((("foo" dep1) ("bar" dep2) ("baz" dep3))
1018 (and (string=? (package-full-name dep1)
1019 (package-full-name sed))
1020 (string=? (package-full-name dep2)
1021 (package-full-name findutils))
1022 (string=? (package-name dep3) "chbouib")
1023 (eq? dep3 (rewrite dep)) ;memoization
1024 (match (package-native-inputs dep3)
1026 (string=? (package-full-name dep)
1027 (package-full-name findutils))))))))))
1029 (test-assert "package-input-rewriting/spec, partial match"
1030 (let* ((dep (dummy-package "chbouib"
1032 (native-inputs `(("x" ,grep)))))
1033 (p0 (dummy-package "example"
1034 (inputs `(("foo" ,coreutils)
1036 (rewrite (package-input-rewriting/spec
1037 `(("chbouib@123" . ,(const sed)) ;not matched
1038 ("grep" . ,(const findutils)))))
1040 (and (not (eq? p1 p0))
1041 (string=? "example" (package-name p1))
1042 (match (package-inputs p1)
1043 ((("foo" dep1) ("bar" dep2))
1044 (and (string=? (package-full-name dep1)
1045 (package-full-name coreutils))
1046 (eq? dep2 (rewrite dep)) ;memoization
1047 (match (package-native-inputs dep2)
1049 (string=? (package-full-name dep)
1050 (package-full-name findutils))))))))))
1052 (test-equal "package-patched-vulnerabilities"
1054 ("CVE-2016-1234" "CVE-2018-4567")
1056 (let ((p1 (dummy-package "pi"
1057 (source (dummy-origin
1058 (patches (list "/a/b/pi-CVE-2015-1234.patch"))))))
1059 (p2 (dummy-package "pi"
1060 (source (dummy-origin
1062 "/a/b/pi-CVE-2016-1234-CVE-2018-4567.patch"))))))
1063 (p3 (dummy-package "pi" (source (dummy-origin)))))
1064 (map package-patched-vulnerabilities
1067 (test-eq "fold-packages" hello
1068 (fold-packages (lambda (p r)
1069 (if (string=? (package-name p) "hello")
1074 (test-assert "fold-packages, hidden package"
1075 ;; There are two public variables providing "guile@2.0" ('guile-final' in
1076 ;; commencement.scm and 'guile-2.0' in guile.scm), but only the latter
1078 (match (fold-packages (lambda (p r)
1079 (if (and (string=? (package-name p) "guile")
1080 (string-prefix? "2.0"
1081 (package-version p)))
1086 (eq? one guile-2.0))))
1088 (test-assert "fold-available-packages with/without cache"
1091 (fold-available-packages (lambda* (name version result #:rest rest)
1092 (cons (cons* name version rest)
1097 (call-with-temporary-directory
1099 (generate-package-cache cache)
1100 (mock ((guix describe) current-profile (const cache))
1101 (mock ((gnu packages) cache-is-authoritative? (const #t))
1102 (fold-available-packages (lambda* (name version result
1104 (cons (cons* name version rest)
1108 (and (equal? (delete-duplicates from-cache) from-cache)
1109 (lset= equal? no-cache from-cache))))
1111 (test-assert "find-packages-by-name"
1112 (match (find-packages-by-name "hello")
1113 (((? (cut eq? hello <>))) #t)
1114 (wrong (pk 'find-packages-by-name wrong #f))))
1116 (test-assert "find-packages-by-name with version"
1117 (match (find-packages-by-name "hello" (package-version hello))
1118 (((? (cut eq? hello <>))) #t)
1119 (wrong (pk 'find-packages-by-name wrong #f))))
1121 (test-equal "find-packages-by-name with cache"
1122 (find-packages-by-name "guile")
1123 (call-with-temporary-directory
1125 (generate-package-cache cache)
1126 (mock ((guix describe) current-profile (const cache))
1127 (mock ((gnu packages) cache-is-authoritative? (const #t))
1128 (find-packages-by-name "guile"))))))
1130 (test-equal "find-packages-by-name + version, with cache"
1131 (find-packages-by-name "guile" "2")
1132 (call-with-temporary-directory
1134 (generate-package-cache cache)
1135 (mock ((guix describe) current-profile (const cache))
1136 (mock ((gnu packages) cache-is-authoritative? (const #t))
1137 (find-packages-by-name "guile" "2"))))))
1139 (test-assert "--search-paths with pattern"
1140 ;; Make sure 'guix package --search-paths' correctly reports environment
1141 ;; variables when file patterns are used (in particular, it must follow
1142 ;; symlinks when looking for 'catalog.xml'.) To do that, we rely on the
1143 ;; libxml2 package specification, which contains such a definition.
1145 (name "foo") (version "0") (source #f)
1146 (build-system trivial-build-system)
1148 `(#:guile ,%bootstrap-guile
1149 #:modules ((guix build utils))
1151 (use-modules (guix build utils))
1152 (let ((out (assoc-ref %outputs "out")))
1153 (mkdir-p (string-append out "/xml/bar/baz"))
1154 (call-with-output-file
1155 (string-append out "/xml/bar/baz/catalog.xml")
1157 (display "xml? wat?!" port)))
1159 (synopsis #f) (description #f)
1160 (home-page #f) (license #f)))
1162 ;; Provide a fake libxml2 to avoid building the real one. This
1163 ;; is OK because 'guix package' gets search path specifications
1164 ;; from the same-named package found in the distro.
1165 (name "libxml2") (version "0.0.0") (source #f)
1166 (build-system trivial-build-system)
1168 `(#:guile ,%bootstrap-guile
1170 (mkdir (assoc-ref %outputs "out"))
1172 (native-search-paths (package-native-search-paths libxml2))
1173 (synopsis #f) (description #f)
1174 (home-page #f) (license #f)))
1175 (prof (run-with-store %store
1177 (manifest (map package->manifest-entry
1181 #:guile-for-build (%guile-for-build))))
1182 (build-derivations %store (list prof))
1183 (string-match (format #f "^export XML_CATALOG_FILES=\"~a/xml/+bar/baz/catalog\\.xml\"\n"
1184 (regexp-quote (derivation->output-path prof)))
1185 (with-output-to-string
1187 (guix-package "-p" (derivation->output-path prof)
1188 "--search-paths"))))))
1190 (test-assert "--search-paths with single-item search path"
1191 ;; Make sure 'guix package --search-paths' correctly reports environment
1192 ;; variables for things like 'GIT_SSL_CAINFO' that have #f as their
1193 ;; separator, meaning that the first match wins.
1194 (let* ((p1 (dummy-package "foo"
1195 (build-system trivial-build-system)
1197 `(#:guile ,%bootstrap-guile
1198 #:modules ((guix build utils))
1200 (use-modules (guix build utils))
1201 (let ((out (assoc-ref %outputs "out")))
1202 (mkdir-p (string-append out "/etc/ssl/certs"))
1203 (call-with-output-file
1205 out "/etc/ssl/certs/ca-certificates.crt")
1207 (p2 (package (inherit p1) (name "bar")))
1208 (p3 (dummy-package "git"
1209 ;; Provide a fake Git to avoid building the real one.
1210 (build-system trivial-build-system)
1212 `(#:guile ,%bootstrap-guile
1214 (mkdir (assoc-ref %outputs "out"))
1216 (native-search-paths (package-native-search-paths git))))
1217 (prof1 (run-with-store %store
1219 (packages->manifest (list p1 p3))
1222 #:guile-for-build (%guile-for-build)))
1223 (prof2 (run-with-store %store
1225 (packages->manifest (list p2 p3))
1228 #:guile-for-build (%guile-for-build))))
1229 (build-derivations %store (list prof1 prof2))
1230 (string-match (format #f "^export GIT_SSL_CAINFO=\"~a/etc/ssl/certs/ca-certificates.crt"
1231 (regexp-quote (derivation->output-path prof1)))
1232 (with-output-to-string
1234 (guix-package "-p" (derivation->output-path prof1)
1235 "-p" (derivation->output-path prof2)
1236 "--search-paths"))))))
1238 (test-equal "specification->package when not found"
1242 ;; This should call 'leave', producing an error message.
1243 (specification->package "this-package-does-not-exist"))
1244 (lambda (key . args)
1247 (test-equal "specification->package+output"
1248 `((,coreutils "out") (,coreutils "debug"))
1249 (list (call-with-values (lambda ()
1250 (specification->package+output "coreutils"))
1252 (call-with-values (lambda ()
1253 (specification->package+output "coreutils:debug"))
1256 (test-equal "specification->package+output invalid output"
1260 (specification->package+output "coreutils:does-not-exist"))
1264 (test-equal "specification->package+output no default output"
1268 (specification->package+output "coreutils" #f))
1271 (test-equal "specification->package+output invalid output, no default"
1275 (specification->package+output "coreutils:does-not-exist" #f))
1279 (test-equal "find-package-locations"
1280 (map (lambda (package)
1281 (cons (package-version package)
1282 (package-location package)))
1283 (find-packages-by-name "guile"))
1284 (find-package-locations "guile"))
1286 (test-equal "find-package-locations with cache"
1287 (map (lambda (package)
1288 (cons (package-version package)
1289 (package-location package)))
1290 (find-packages-by-name "guile"))
1291 (call-with-temporary-directory
1293 (generate-package-cache cache)
1294 (mock ((guix describe) current-profile (const cache))
1295 (mock ((gnu packages) cache-is-authoritative? (const #t))
1296 (find-package-locations "guile"))))))
1298 (test-equal "specification->location"
1299 (package-location (specification->package "guile@2"))
1300 (specification->location "guile@2"))
1302 (test-end "packages")
1304 ;;; Local Variables:
1305 ;;; eval: (put 'dummy-package 'scheme-indent-function 1)
1306 ;;; eval: (put 'dummy-package/no-implicit 'scheme-indent-function 1)