gnu: Add bsnes.
[jackhill/guix/guix.git] / tests / packages.scm
CommitLineData
233e7676 1;;; GNU Guix --- Functional package management for GNU
84c5da08 2;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
0db65c16 3;;; Copyright © Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
e3ce5d70 4;;;
233e7676 5;;; This file is part of GNU Guix.
e3ce5d70 6;;;
233e7676 7;;; GNU Guix is free software; you can redistribute it and/or modify it
e3ce5d70
LC
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.
11;;;
233e7676 12;;; GNU Guix is distributed in the hope that it will be useful, but
e3ce5d70
LC
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.
16;;;
17;;; You should have received a copy of the GNU General Public License
233e7676 18;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
e3ce5d70 19
e3ce5d70 20(define-module (test-packages)
c1bc358f 21 #:use-module (guix tests)
e3ce5d70 22 #:use-module (guix store)
cf81a236 23 #:use-module (guix monads)
fcadd9ff 24 #:use-module (guix grafts)
da675305 25 #:use-module ((guix gexp) #:select (local-file local-file-file))
2e1bafb0
LC
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)
31 (else name))))
197c07a8 32 #:use-module ((gcrypt hash) #:prefix gcrypt:)
e3ce5d70
LC
33 #:use-module (guix derivations)
34 #:use-module (guix packages)
7adf9b84 35 #:use-module (guix grafts)
aa8e0515 36 #:use-module (guix search-paths)
a18eda27 37 #:use-module (guix build-system)
be13fbfa 38 #:use-module (guix build-system trivial)
a3d73f59 39 #:use-module (guix build-system gnu)
0db65c16 40 #:use-module (guix memoization)
cf81a236
LC
41 #:use-module (guix profiles)
42 #:use-module (guix scripts package)
59a43334 43 #:use-module (gnu packages)
1ffa7090 44 #:use-module (gnu packages base)
05962f29 45 #:use-module (gnu packages guile)
1ffa7090 46 #:use-module (gnu packages bootstrap)
fcd75bdb 47 #:use-module (gnu packages version-control)
cf81a236 48 #:use-module (gnu packages xml)
05962f29 49 #:use-module (srfi srfi-1)
6b1891b0 50 #:use-module (srfi srfi-26)
9b222abe 51 #:use-module (srfi srfi-34)
dbab5150 52 #:use-module (srfi srfi-35)
6b1891b0 53 #:use-module (srfi srfi-64)
ce0be567 54 #:use-module (rnrs bytevectors)
860a6f1a 55 #:use-module (rnrs io ports)
5239f3d9 56 #:use-module (ice-9 vlist)
2e1bafb0 57 #:use-module (ice-9 regex)
6b1891b0 58 #:use-module (ice-9 match))
e3ce5d70
LC
59
60;; Test the high-level packaging layer.
61
62(define %store
c1bc358f 63 (open-connection-for-tests))
e3ce5d70 64
b4c42a4b
LC
65;; Globally disable grafting to avoid rebuilding the world ('graft-derivation'
66;; can trigger builds early.)
67(%graft? #f)
68
05962f29
LC
69\f
70(test-begin "packages")
71
2e1bafb0 72(test-assert "printer with location"
74e667d1 73 (string-match "^#<package foo@0 foo.scm:42 [[:xdigit:]]+>$"
2e1bafb0
LC
74 (with-output-to-string
75 (lambda ()
76 (write
77 (dummy-package "foo"
78 (location (make-location "foo.scm" 42 7))))))))
79
80(test-assert "printer without location"
74e667d1 81 (string-match "^#<package foo@0 [[:xdigit:]]+>$"
2e1bafb0
LC
82 (with-output-to-string
83 (lambda ()
84 (write
85 (dummy-package "foo" (location #f)))))))
86
6980511b
LC
87(test-assert "hidden-package"
88 (and (hidden-package? (hidden-package (dummy-package "foo")))
89 (not (hidden-package? (dummy-package "foo")))))
90
01afdab8
LC
91(test-assert "package-superseded"
92 (let* ((new (dummy-package "bar"))
93 (old (deprecated-package "foo" new)))
94 (and (eq? (package-superseded old) new)
95 (mock ((gnu packages) find-best-packages-by-name (const (list old)))
96 (specification->package "foo")
97 (and (eq? new (specification->package "foo"))
98 (eq? new (specification->package+output "foo")))))))
99
5239f3d9
LC
100(test-assert "transaction-upgrade-entry, zero upgrades"
101 (let* ((old (dummy-package "foo" (version "1")))
465a0d65
LC
102 (tx (mock ((gnu packages) find-best-packages-by-name
103 (const '()))
84c5da08
LC
104 (transaction-upgrade-entry
105 #f ;no store access needed
5239f3d9
LC
106 (manifest-entry
107 (inherit (package->manifest-entry old))
108 (item (string-append (%store-prefix) "/"
109 (make-string 32 #\e) "-foo-1")))
110 (manifest-transaction)))))
111 (manifest-transaction-null? tx)))
112
b9c79cae
LC
113(test-assert "transaction-upgrade-entry, zero upgrades, equivalent package"
114 (let* ((old (dummy-package "foo" (version "1")))
115 (drv (package-derivation %store old))
116 (tx (mock ((gnu packages) find-best-packages-by-name
117 (const (list old)))
118 (transaction-upgrade-entry
119 %store
120 (manifest-entry
121 (inherit (package->manifest-entry old))
122 (item (derivation->output-path drv)))
123 (manifest-transaction)))))
124 (manifest-transaction-null? tx)))
125
a357849f
LC
126(test-assert "transaction-upgrade-entry, zero upgrades, propagated inputs"
127 ;; Properly detect equivalent packages even when they have propagated
128 ;; inputs. See <https://bugs.gnu.org/35872>.
129 (let* ((dep (dummy-package "dep" (version "2")))
130 (old (dummy-package "foo" (version "1")
131 (propagated-inputs `(("dep" ,dep)))))
132 (drv (package-derivation %store old))
133 (tx (mock ((gnu packages) find-best-packages-by-name
134 (const (list old)))
135 (transaction-upgrade-entry
136 %store
137 (manifest-entry
138 (inherit (package->manifest-entry old))
139 (item (derivation->output-path drv))
140 (dependencies
141 (list (manifest-entry
142 (inherit (package->manifest-entry dep))
143 (item (derivation->output-path
144 (package-derivation %store dep)))))))
145 (manifest-transaction)))))
146 (manifest-transaction-null? tx)))
147
5239f3d9
LC
148(test-assert "transaction-upgrade-entry, one upgrade"
149 (let* ((old (dummy-package "foo" (version "1")))
150 (new (dummy-package "foo" (version "2")))
465a0d65
LC
151 (tx (mock ((gnu packages) find-best-packages-by-name
152 (const (list new)))
84c5da08
LC
153 (transaction-upgrade-entry
154 #f ;no store access needed
5239f3d9
LC
155 (manifest-entry
156 (inherit (package->manifest-entry old))
157 (item (string-append (%store-prefix) "/"
158 (make-string 32 #\e) "-foo-1")))
159 (manifest-transaction)))))
160 (and (match (manifest-transaction-install tx)
161 ((($ <manifest-entry> "foo" "2" "out" item))
162 (eq? item new)))
163 (null? (manifest-transaction-remove tx)))))
164
01afdab8
LC
165(test-assert "transaction-upgrade-entry, superseded package"
166 (let* ((old (dummy-package "foo" (version "1")))
167 (new (dummy-package "bar" (version "2")))
168 (dep (deprecated-package "foo" new))
465a0d65
LC
169 (tx (mock ((gnu packages) find-best-packages-by-name
170 (const (list dep)))
84c5da08
LC
171 (transaction-upgrade-entry
172 #f ;no store access needed
01afdab8
LC
173 (manifest-entry
174 (inherit (package->manifest-entry old))
175 (item (string-append (%store-prefix) "/"
176 (make-string 32 #\e) "-foo-1")))
177 (manifest-transaction)))))
178 (and (match (manifest-transaction-install tx)
179 ((($ <manifest-entry> "bar" "2" "out" item))
180 (eq? item new)))
181 (match (manifest-transaction-remove tx)
182 (((? manifest-pattern? pattern))
183 (and (string=? (manifest-pattern-name pattern) "foo")
184 (string=? (manifest-pattern-version pattern) "1")
185 (string=? (manifest-pattern-output pattern) "out")))))))
186
a187cc56
LC
187(test-assert "transaction-upgrade-entry, grafts"
188 ;; Ensure that, when grafts are enabled, 'transaction-upgrade-entry' doesn't
189 ;; try to build stuff.
190 (with-build-handler (const 'failed!)
191 (parameterize ((%graft? #t))
192 (let* ((old (dummy-package "foo" (version "1")))
193 (bar (dummy-package "bar" (version "0")
194 (replacement old)))
195 (new (dummy-package "foo" (version "1")
196 (inputs `(("bar" ,bar)))))
197 (tx (mock ((gnu packages) find-best-packages-by-name
198 (const (list new)))
199 (transaction-upgrade-entry
200 %store
201 (manifest-entry
202 (inherit (package->manifest-entry old))
203 (item (string-append (%store-prefix) "/"
204 (make-string 32 #\e) "-foo-1")))
205 (manifest-transaction)))))
206 (and (match (manifest-transaction-install tx)
207 ((($ <manifest-entry> "foo" "1" "out" item))
208 (eq? item new)))
209 (null? (manifest-transaction-remove tx)))))))
210
d66c7096
LC
211(test-assert "package-field-location"
212 (let ()
213 (define (goto port line column)
214 (unless (and (= (port-column port) (- column 1))
215 (= (port-line port) (- line 1)))
216 (unless (eof-object? (get-char port))
217 (goto port line column))))
218
219 (define read-at
220 (match-lambda
221 (($ <location> file line column)
222 (call-with-input-file (search-path %load-path file)
223 (lambda (port)
224 (goto port line column)
225 (read port))))))
226
ee48b283
LC
227 ;; Until Guile 2.0.6 included, source properties were added only to pairs.
228 ;; Thus, check against both VALUE and (FIELD VALUE).
229 (and (member (read-at (package-field-location %bootstrap-guile 'name))
230 (let ((name (package-name %bootstrap-guile)))
231 (list name `(name ,name))))
232 (member (read-at (package-field-location %bootstrap-guile 'version))
233 (let ((version (package-version %bootstrap-guile)))
234 (list version `(version ,version))))
f903dc05 235 (not (package-field-location %bootstrap-guile 'does-not-exist)))))
d66c7096 236
0b8749b7
LC
237;; Make sure we don't change the file name to an absolute file name.
238(test-equal "package-field-location, relative file name"
239 (location-file (package-location %bootstrap-guile))
240 (with-fluids ((%file-port-name-canonicalization 'absolute))
241 (location-file (package-field-location %bootstrap-guile 'version))))
242
a3d73f59
LC
243(test-assert "package-transitive-inputs"
244 (let* ((a (dummy-package "a"))
245 (b (dummy-package "b"
246 (propagated-inputs `(("a" ,a)))))
247 (c (dummy-package "c"
248 (inputs `(("a" ,a)))))
249 (d (dummy-package "d"
250 (propagated-inputs `(("x" "something.drv")))))
251 (e (dummy-package "e"
252 (inputs `(("b" ,b) ("c" ,c) ("d" ,d))))))
253 (and (null? (package-transitive-inputs a))
254 (equal? `(("a" ,a)) (package-transitive-inputs b))
255 (equal? `(("a" ,a)) (package-transitive-inputs c))
256 (equal? (package-propagated-inputs d)
257 (package-transitive-inputs d))
161094c8
LC
258 (equal? `(("b" ,b) ("c" ,c) ("d" ,d)
259 ("a" ,a) ("x" "something.drv"))
a3d73f59
LC
260 (pk 'x (package-transitive-inputs e))))))
261
161094c8
LC
262(test-assert "package-transitive-inputs, no duplicates"
263 (let* ((a (dummy-package "a"))
264 (b (dummy-package "b"
265 (inputs `(("a+" ,a)))
266 (native-inputs `(("a*" ,a)))
267 (propagated-inputs `(("a" ,a)))))
268 (c (dummy-package "c"
269 (propagated-inputs `(("b" ,b)))))
270 (d (dummy-package "d"
271 (inputs `(("a" ,a) ("c" ,c)))))
272 (e (dummy-package "e"
273 (inputs `(("b" ,b) ("c" ,c))))))
274 (and (null? (package-transitive-inputs a))
275 (equal? `(("a*" ,a) ("a+" ,a) ("a" ,a)) ;here duplicates are kept
276 (package-transitive-inputs b))
277 (equal? `(("b" ,b) ("a" ,a))
278 (package-transitive-inputs c))
279 (equal? `(("a" ,a) ("c" ,c) ("b" ,b)) ;duplicate A removed
280 (package-transitive-inputs d))
281 (equal? `(("b" ,b) ("c" ,c) ("a" ,a))
282 (package-transitive-inputs e))))) ;ditto
283
7c3c0374 284(test-equal "package-transitive-supported-systems"
c37a74bd
LC
285 '(("x" "y" "z") ;a
286 ("x" "y") ;b
287 ("y") ;c
288 ("y") ;d
289 ("y")) ;e
9bf3ced0
LC
290 ;; Use TRIVIAL-BUILD-SYSTEM because it doesn't add implicit inputs and thus
291 ;; doesn't restrict the set of supported systems.
292 (let* ((a (dummy-package "a"
293 (build-system trivial-build-system)
294 (supported-systems '("x" "y" "z"))))
295 (b (dummy-package "b"
296 (build-system trivial-build-system)
297 (supported-systems '("x" "y"))
298 (inputs `(("a" ,a)))))
299 (c (dummy-package "c"
300 (build-system trivial-build-system)
301 (supported-systems '("y" "z"))
302 (inputs `(("b" ,b)))))
303 (d (dummy-package "d"
304 (build-system trivial-build-system)
305 (supported-systems '("x" "y" "z"))
306 (inputs `(("b" ,b) ("c" ,c)))))
307 (e (dummy-package "e"
308 (build-system trivial-build-system)
309 (supported-systems '("x" "y" "z"))
310 (inputs `(("d" ,d))))))
7c3c0374
LC
311 (list (package-transitive-supported-systems a)
312 (package-transitive-supported-systems b)
c37a74bd
LC
313 (package-transitive-supported-systems c)
314 (package-transitive-supported-systems d)
315 (package-transitive-supported-systems e))))
7c3c0374 316
3e223a22
LC
317(test-assert "package-closure"
318 (let-syntax ((dummy-package/no-implicit
319 (syntax-rules ()
320 ((_ name rest ...)
321 (package
322 (inherit (dummy-package name rest ...))
323 (build-system trivial-build-system))))))
324 (let* ((a (dummy-package/no-implicit "a"))
325 (b (dummy-package/no-implicit "b"
326 (propagated-inputs `(("a" ,a)))))
327 (c (dummy-package/no-implicit "c"
328 (inputs `(("a" ,a)))))
329 (d (dummy-package/no-implicit "d"
330 (native-inputs `(("b" ,b)))))
331 (e (dummy-package/no-implicit "e"
332 (inputs `(("c" ,c) ("d" ,d))))))
333 (lset= eq?
334 (list a b c d e)
335 (package-closure (list e))
336 (package-closure (list e d))
337 (package-closure (list e c b))))))
338
3b4d0103
EB
339(test-equal "origin-actual-file-name"
340 "foo-1.tar.gz"
341 (let ((o (dummy-origin (uri "http://www.example.com/foo-1.tar.gz"))))
342 (origin-actual-file-name o)))
343
344(test-equal "origin-actual-file-name, file-name"
345 "foo-1.tar.gz"
346 (let ((o (dummy-origin
347 (uri "http://www.example.com/tarball")
348 (file-name "foo-1.tar.gz"))))
349 (origin-actual-file-name o)))
350
f77bcbc3
EB
351(let* ((o (dummy-origin))
352 (u (dummy-origin))
353 (i (dummy-origin))
354 (a (dummy-package "a"))
355 (b (dummy-package "b"
356 (inputs `(("a" ,a) ("i" ,i)))))
357 (c (package (inherit b) (source o)))
358 (d (dummy-package "d"
359 (build-system trivial-build-system)
360 (source u) (inputs `(("c" ,c))))))
361 (test-assert "package-direct-sources, no source"
362 (null? (package-direct-sources a)))
363 (test-equal "package-direct-sources, #f source"
364 (list i)
365 (package-direct-sources b))
366 (test-equal "package-direct-sources, not input source"
367 (list u)
368 (package-direct-sources d))
369 (test-assert "package-direct-sources"
370 (let ((s (package-direct-sources c)))
371 (and (= (length (pk 's-sources s)) 2)
372 (member o s)
373 (member i s))))
374 (test-assert "package-transitive-sources"
375 (let ((s (package-transitive-sources d)))
376 (and (= (length (pk 'd-sources s)) 3)
377 (member o s)
378 (member i s)
379 (member u s)))))
380
a6d0b306
EB
381(test-assert "transitive-input-references"
382 (let* ((a (dummy-package "a"))
383 (b (dummy-package "b"))
384 (c (dummy-package "c"
385 (inputs `(("a" ,a)))
386 (propagated-inputs `(("boo" ,b)))))
387 (d (dummy-package "d"
388 (inputs `(("c*" ,c)))))
389 (keys (map (match-lambda
390 (('assoc-ref 'l key)
391 key))
392 (pk 'refs (transitive-input-references
393 'l (package-inputs d))))))
394 (and (= (length keys) 2)
395 (member "c*" keys)
396 (member "boo" keys))))
397
9bf3ced0
LC
398(test-equal "package-transitive-supported-systems, implicit inputs"
399 %supported-systems
400
0db65c16
JN
401 ;; Here GNU-BUILD-SYSTEM adds implicit inputs that build only on
402 ;; %SUPPORTED-SYSTEMS. Thus the others must be ignored.
403 (let ((p (dummy-package "foo"
404 (build-system gnu-build-system)
405 (supported-systems
406 `("does-not-exist" "foobar" ,@%supported-systems)))))
0db65c16
JN
407 (parameterize ((%current-system "armhf-linux")) ; a traditionally-bootstrapped architecture
408 (package-transitive-supported-systems p))))
409
410(test-equal "package-transitive-supported-systems: reduced binary seed, implicit inputs"
411 '("x86_64-linux" "i686-linux")
412
9bf3ced0
LC
413 ;; Here GNU-BUILD-SYSTEM adds implicit inputs that build only on
414 ;; %SUPPORTED-SYSTEMS. Thus the others must be ignored.
415 (let ((p (dummy-package "foo"
416 (build-system gnu-build-system)
417 (supported-systems
418 `("does-not-exist" "foobar" ,@%supported-systems)))))
0db65c16
JN
419 (parameterize ((%current-system "x86_64-linux"))
420 (package-transitive-supported-systems p))))
9bf3ced0 421
bbceb0ef 422(test-assert "supported-package?"
bc60349b
LC
423 (let* ((d (dummy-package "dep"
424 (build-system trivial-build-system)
425 (supported-systems '("x86_64-linux"))))
426 (p (dummy-package "foo"
427 (build-system gnu-build-system)
428 (inputs `(("d" ,d)))
429 (supported-systems '("x86_64-linux" "armhf-linux")))))
430 (and (supported-package? p "x86_64-linux")
431 (not (supported-package? p "i686-linux"))
432 (not (supported-package? p "armhf-linux")))))
433
434(test-assert "supported-package? vs. system-dependent graph"
435 ;; The inputs of a package can depend on (%current-system). Thus,
436 ;; 'supported-package?' must make sure that it binds (%current-system)
437 ;; appropriately before traversing the dependency graph. In the example
438 ;; below, 'supported-package?' must thus return true for both systems.
439 (let* ((p0a (dummy-package "foo-arm"
440 (build-system trivial-build-system)
441 (supported-systems '("armhf-linux"))))
442 (p0b (dummy-package "foo-x86_64"
443 (build-system trivial-build-system)
444 (supported-systems '("x86_64-linux"))))
445 (p (dummy-package "bar"
446 (build-system trivial-build-system)
447 (inputs
448 (if (string=? (%current-system) "armhf-linux")
449 `(("foo" ,p0a))
450 `(("foo" ,p0b)))))))
bbceb0ef 451 (and (supported-package? p "x86_64-linux")
bc60349b 452 (supported-package? p "armhf-linux"))))
bbceb0ef 453
7357138b
LC
454(test-skip (if (not %store) 8 0))
455
456(test-assert "package-source-derivation, file"
457 (let* ((file (search-path %load-path "guix.scm"))
458 (package (package (inherit (dummy-package "p"))
459 (source file)))
460 (source (package-source-derivation %store
461 (package-source package))))
462 (and (store-path? source)
463 (valid-path? %store source)
464 (equal? (call-with-input-file source get-bytevector-all)
465 (call-with-input-file file get-bytevector-all)))))
466
467(test-assert "package-source-derivation, store path"
468 (let* ((file (add-to-store %store "guix.scm" #t "sha256"
469 (search-path %load-path "guix.scm")))
470 (package (package (inherit (dummy-package "p"))
471 (source file)))
472 (source (package-source-derivation %store
473 (package-source package))))
474 (string=? file source)))
e509d152 475
f80594cc
LC
476(test-assert "package-source-derivation, indirect store path"
477 (let* ((dir (add-to-store %store "guix-build" #t "sha256"
478 (dirname (search-path %load-path
479 "guix/build/utils.scm"))))
480 (package (package (inherit (dummy-package "p"))
481 (source (string-append dir "/utils.scm"))))
482 (source (package-source-derivation %store
483 (package-source package))))
484 (and (direct-store-path? source)
485 (string-suffix? "utils.scm" source))))
486
da675305
LC
487(test-assert "package-source-derivation, local-file"
488 (let* ((file (local-file "../guix/base32.scm"))
489 (package (package (inherit (dummy-package "p"))
490 (source file)))
491 (source (package-source-derivation %store
492 (package-source package))))
493 (and (store-path? source)
494 (string-suffix? "base32.scm" source)
495 (valid-path? %store source)
496 (equal? (call-with-input-file source get-bytevector-all)
497 (call-with-input-file
498 (search-path %load-path "guix/base32.scm")
499 get-bytevector-all)))))
500
ce0be567
LC
501(test-equal "package-source-derivation, origin, sha512"
502 "hello"
503 (let* ((bash (search-bootstrap-binary "bash" (%current-system)))
504 (builder (add-text-to-store %store "my-fixed-builder.sh"
505 "echo -n hello > $out" '()))
506 (method (lambda* (url hash-algo hash #:optional name
507 #:rest rest)
508 (and (eq? hash-algo 'sha512)
509 (raw-derivation name bash (list builder)
510 #:sources (list builder)
511 #:hash hash
512 #:hash-algo hash-algo))))
513 (source (origin
514 (method method)
515 (uri "unused://")
516 (file-name "origin-sha512")
517 (hash (content-hash
197c07a8
LC
518 (gcrypt:bytevector-hash (string->utf8 "hello")
519 (gcrypt:lookup-hash-algorithm
520 'sha512))
ce0be567
LC
521 sha512))))
522 (drv (package-source-derivation %store source))
523 (output (derivation->output-path drv)))
524 (build-derivations %store (list drv))
525 (call-with-input-file output get-string-all)))
526
12d720fd 527(unless (network-reachable?) (test-skip 1))
f9cc8971
LC
528(test-equal "package-source-derivation, snippet"
529 "OK"
f8ec8d96 530 (let* ((source (bootstrap-origin
f9cc8971 531 (origin
f8ec8d96 532 (inherit (bootstrap-guile-origin (%current-system)))
f9cc8971
LC
533 (patch-inputs
534 `(("tar" ,%bootstrap-coreutils&co)
535 ("xz" ,%bootstrap-coreutils&co)
536 ("patch" ,%bootstrap-coreutils&co)))
7db9608d 537 (patch-guile %bootstrap-guile)
f9cc8971 538 (modules '((guix build utils)))
f9cc8971
LC
539 (snippet '(begin
540 ;; We end up in 'bin', because it's the first
541 ;; directory, alphabetically. Not a very good
542 ;; example but hey.
543 (chmod "." #o777)
544 (symlink "guile" "guile-rocks")
545 (copy-recursively "../share/guile/2.0/scripts"
d6445dff
LC
546 "scripts")
547
548 ;; Make sure '.file_list' can be created.
549 (chmod ".." #o777))))))
f9cc8971
LC
550 (package (package (inherit (dummy-package "with-snippet"))
551 (source source)
552 (build-system trivial-build-system)
553 (inputs
554 `(("tar" ,(search-bootstrap-binary "tar"
555 (%current-system)))
556 ("xz" ,(search-bootstrap-binary "xz"
557 (%current-system)))))
558 (arguments
559 `(#:guile ,%bootstrap-guile
1e868858 560 #:modules ((guix build utils))
f9cc8971 561 #:builder
1e868858
MW
562 (begin
563 (use-modules (guix build utils))
564 (let ((tar (assoc-ref %build-inputs "tar"))
565 (xz (assoc-ref %build-inputs "xz"))
566 (source (assoc-ref %build-inputs "source")))
567 (invoke tar "xvf" source
568 "--use-compress-program" xz)
569 (unless (and (string=? "guile" (readlink "bin/guile-rocks"))
570 (file-exists? "bin/scripts/compile.scm"))
571 (error "the snippet apparently failed"))
572 (let ((out (assoc-ref %outputs "out")))
573 (call-with-output-file out
574 (lambda (p)
575 (display "OK" p))))
576 #t))))))
f9cc8971
LC
577 (drv (package-derivation %store package))
578 (out (derivation->output-path drv)))
579 (and (build-derivations %store (list (pk 'snippet-drv drv)))
580 (call-with-input-file out get-string-all))))
581
59688fc4
LC
582(test-assert "return value"
583 (let ((drv (package-derivation %store (dummy-package "p"))))
584 (and (derivation? drv)
585 (file-exists? (derivation-file-name drv)))))
be13fbfa 586
d510ab46
LC
587(test-assert "package-output"
588 (let* ((package (dummy-package "p"))
59688fc4
LC
589 (drv (package-derivation %store package)))
590 (and (derivation? drv)
591 (string=? (derivation->output-path drv)
d510ab46
LC
592 (package-output %store package "out")))))
593
dbab5150
LC
594(test-assert "patch not found yields a run-time error"
595 (guard (c ((condition-has-type? c &message)
596 (and (string-contains (condition-message c)
597 "does-not-exist.patch")
598 (string-contains (condition-message c)
599 "not found"))))
600 (let ((p (package
601 (inherit (dummy-package "p"))
602 (source (origin
603 (method (const #f))
604 (uri "http://whatever")
605 (patches
606 (list (search-patch "does-not-exist.patch")))
607 (sha256
608 (base32
609 "0amn0bbwqvsvvsh6drfwz20ydc2czk374lzw5kksbh6bf78k4ks4")))))))
610 (package-derivation %store p)
611 #f)))
612
76c48619
LC
613(let ((dummy (dummy-package "foo" (inputs `(("x" ,(current-module)))))))
614 (test-equal "&package-input-error"
615 (list dummy (current-module))
616 (guard (c ((package-input-error? c)
617 (list (package-error-package c)
618 (package-error-invalid-input c))))
619 (package-derivation %store dummy))))
620
f304c9c2
LC
621(test-assert "reference to non-existent output"
622 ;; See <http://bugs.gnu.org/19630>.
862abf8f
LC
623 (parameterize ((%graft? #f))
624 (let* ((dep (dummy-package "dep"))
625 (p (dummy-package "p"
626 (inputs `(("dep" ,dep "non-existent"))))))
627 (guard (c ((derivation-missing-output-error? c)
628 (and (string=? (derivation-missing-output c) "non-existent")
629 (equal? (package-derivation %store dep)
630 (derivation-error-derivation c)))))
631 (package-derivation %store p)))))
f304c9c2 632
be13fbfa
LC
633(test-assert "trivial"
634 (let* ((p (package (inherit (dummy-package "trivial"))
635 (build-system trivial-build-system)
636 (source #f)
637 (arguments
14da91e2
LC
638 `(#:guile ,%bootstrap-guile
639 #:builder
be13fbfa
LC
640 (begin
641 (mkdir %output)
642 (call-with-output-file (string-append %output "/test")
643 (lambda (p)
1e868858
MW
644 (display '(hello guix) p)))
645 #t)))))
be13fbfa
LC
646 (d (package-derivation %store p)))
647 (and (build-derivations %store (list d))
59688fc4 648 (let ((p (pk 'drv d (derivation->output-path d))))
be13fbfa
LC
649 (equal? '(hello guix)
650 (call-with-input-file (string-append p "/test") read))))))
e3ce5d70 651
860a6f1a
LC
652(test-assert "trivial with local file as input"
653 (let* ((i (search-path %load-path "ice-9/boot-9.scm"))
654 (p (package (inherit (dummy-package "trivial-with-input-file"))
655 (build-system trivial-build-system)
656 (source #f)
657 (arguments
658 `(#:guile ,%bootstrap-guile
1e868858
MW
659 #:builder (begin
660 (copy-file (assoc-ref %build-inputs "input")
661 %output)
662 #t)))
860a6f1a
LC
663 (inputs `(("input" ,i)))))
664 (d (package-derivation %store p)))
665 (and (build-derivations %store (list d))
59688fc4 666 (let ((p (pk 'drv d (derivation->output-path d))))
860a6f1a
LC
667 (equal? (call-with-input-file p get-bytevector-all)
668 (call-with-input-file i get-bytevector-all))))))
669
03761a44
LC
670(test-assert "trivial with source"
671 (let* ((i (search-path %load-path "ice-9/boot-9.scm"))
672 (p (package (inherit (dummy-package "trivial-with-source"))
673 (build-system trivial-build-system)
674 (source i)
675 (arguments
676 `(#:guile ,%bootstrap-guile
1e868858
MW
677 #:builder (begin
678 (copy-file (assoc-ref %build-inputs "source")
679 %output)
680 #t)))))
03761a44
LC
681 (d (package-derivation %store p)))
682 (and (build-derivations %store (list d))
683 (let ((p (derivation->output-path d)))
684 (equal? (call-with-input-file p get-bytevector-all)
685 (call-with-input-file i get-bytevector-all))))))
686
592ef6c8
LC
687(test-assert "trivial with system-dependent input"
688 (let* ((p (package (inherit (dummy-package "trivial-system-dependent-input"))
689 (build-system trivial-build-system)
690 (source #f)
691 (arguments
692 `(#:guile ,%bootstrap-guile
1e868858 693 #:modules ((guix build utils))
592ef6c8 694 #:builder
1e868858
MW
695 (begin
696 (use-modules (guix build utils))
697 (let ((out (assoc-ref %outputs "out"))
698 (bash (assoc-ref %build-inputs "bash")))
699 (invoke bash "-c"
700 (format #f "echo hello > ~a" out))))))
dd6b9a37
LC
701 (inputs `(("bash" ,(search-bootstrap-binary "bash"
702 (%current-system)))))))
592ef6c8
LC
703 (d (package-derivation %store p)))
704 (and (build-derivations %store (list d))
59688fc4 705 (let ((p (pk 'drv d (derivation->output-path d))))
592ef6c8
LC
706 (eq? 'hello (call-with-input-file p read))))))
707
29760251
LC
708(test-assert "trivial with #:allowed-references"
709 (let* ((p (package
710 (inherit (dummy-package "trivial"))
711 (build-system trivial-build-system)
712 (arguments
713 `(#:guile ,%bootstrap-guile
714 #:allowed-references (,%bootstrap-guile)
715 #:builder
716 (begin
717 (mkdir %output)
718 ;; The reference to itself isn't allowed so building it
719 ;; should fail.
1e868858
MW
720 (symlink %output (string-append %output "/self"))
721 #t)))))
29760251 722 (d (package-derivation %store p)))
f9e8a123 723 (guard (c ((store-protocol-error? c) #t))
29760251
LC
724 (build-derivations %store (list d))
725 #f)))
726
a18eda27
LC
727(test-assert "search paths"
728 (let* ((p (make-prompt-tag "return-search-paths"))
729 (s (build-system
0d5a559f 730 (name 'raw)
a18eda27 731 (description "Raw build system with direct store access")
d3d337d2
LC
732 (lower (lambda* (name #:key source inputs system target
733 #:allow-other-keys)
0d5a559f
LC
734 (bag
735 (name name)
d3d337d2 736 (system system) (target target)
0d5a559f
LC
737 (build-inputs inputs)
738 (build
739 (lambda* (store name inputs
740 #:key outputs system search-paths)
741 search-paths)))))))
a18eda27
LC
742 (x (list (search-path-specification
743 (variable "GUILE_LOAD_PATH")
af070955 744 (files '("share/guile/site/2.0")))
a18eda27
LC
745 (search-path-specification
746 (variable "GUILE_LOAD_COMPILED_PATH")
af070955 747 (files '("share/guile/site/2.0")))))
a18eda27
LC
748 (a (package (inherit (dummy-package "guile"))
749 (build-system s)
750 (native-search-paths x)))
751 (b (package (inherit (dummy-package "guile-foo"))
752 (build-system s)
753 (inputs `(("guile" ,a)))))
754 (c (package (inherit (dummy-package "guile-bar"))
755 (build-system s)
756 (inputs `(("guile" ,a)
757 ("guile-foo" ,b))))))
758 (let-syntax ((collect (syntax-rules ()
759 ((_ body ...)
760 (call-with-prompt p
761 (lambda ()
762 body ...)
763 (lambda (k search-paths)
764 search-paths))))))
765 (and (null? (collect (package-derivation %store a)))
766 (equal? x (collect (package-derivation %store b)))
767 (equal? x (collect (package-derivation %store c)))))))
768
aa8e0515
LC
769(test-assert "package-transitive-native-search-paths"
770 (let* ((sp (lambda (name)
771 (list (search-path-specification
772 (variable name)
773 (files '("foo/bar"))))))
774 (p0 (dummy-package "p0" (native-search-paths (sp "PATH0"))))
775 (p1 (dummy-package "p1" (native-search-paths (sp "PATH1"))))
776 (p2 (dummy-package "p2"
777 (native-search-paths (sp "PATH2"))
778 (inputs `(("p0" ,p0)))
779 (propagated-inputs `(("p1" ,p1)))))
780 (p3 (dummy-package "p3"
781 (native-search-paths (sp "PATH3"))
782 (native-inputs `(("p0" ,p0)))
783 (propagated-inputs `(("p2" ,p2))))))
784 (lset= string=?
785 '("PATH1" "PATH2" "PATH3")
786 (map search-path-specification-variable
787 (package-transitive-native-search-paths p3)))))
788
9c1edabd 789(test-assert "package-cross-derivation"
59688fc4
LC
790 (let ((drv (package-cross-derivation %store (dummy-package "p")
791 "mips64el-linux-gnu")))
792 (and (derivation? drv)
793 (file-exists? (derivation-file-name drv)))))
9c1edabd 794
5dce8218
LC
795(test-assert "package-cross-derivation, trivial-build-system"
796 (let ((p (package (inherit (dummy-package "p"))
797 (build-system trivial-build-system)
798 (arguments '(#:builder (exit 1))))))
59688fc4
LC
799 (let ((drv (package-cross-derivation %store p "mips64el-linux-gnu")))
800 (derivation? drv))))
5dce8218 801
9b222abe
LC
802(test-assert "package-cross-derivation, no cross builder"
803 (let* ((b (build-system (inherit trivial-build-system)
0d5a559f 804 (lower (const #f))))
9b222abe
LC
805 (p (package (inherit (dummy-package "p"))
806 (build-system b))))
807 (guard (c ((package-cross-build-system-error? c)
808 (eq? (package-error-package c) p)))
809 (package-cross-derivation %store p "mips64el-linux-gnu")
810 #f)))
811
b4c42a4b
LC
812;; XXX: The next two tests can trigger builds when the distro defines
813;; replacements on core packages, so they're disable for lack of a better
814;; solution.
815
816;; (test-equal "package-derivation, direct graft"
817;; (package-derivation %store gnu-make #:graft? #f)
818;; (let ((p (package (inherit coreutils)
819;; (replacement gnu-make))))
820;; (package-derivation %store p #:graft? #t)))
05962f29 821
b4c42a4b
LC
822;; (test-equal "package-cross-derivation, direct graft"
823;; (package-cross-derivation %store gnu-make "mips64el-linux-gnu"
824;; #:graft? #f)
825;; (let ((p (package (inherit coreutils)
826;; (replacement gnu-make))))
827;; (package-cross-derivation %store p "mips64el-linux-gnu"
828;; #:graft? #t)))
05962f29
LC
829
830(test-assert "package-grafts, indirect grafts"
831 (let* ((new (dummy-package "dep"
832 (arguments '(#:implicit-inputs? #f))))
833 (dep (package (inherit new) (version "0.0")))
834 (dep* (package (inherit dep) (replacement new)))
835 (dummy (dummy-package "dummy"
836 (arguments '(#:implicit-inputs? #f))
837 (inputs `(("dep" ,dep*))))))
838 (equal? (package-grafts %store dummy)
839 (list (graft
840 (origin (package-derivation %store dep))
841 (replacement (package-derivation %store new)))))))
842
d0025d01
LC
843;; XXX: This test would require building the cross toolchain just to see if it
844;; needs grafting, which is obviously too expensive, and thus disabled.
845;;
846;; (test-assert "package-grafts, indirect grafts, cross"
847;; (let* ((new (dummy-package "dep"
848;; (arguments '(#:implicit-inputs? #f))))
849;; (dep (package (inherit new) (version "0.0")))
850;; (dep* (package (inherit dep) (replacement new)))
851;; (dummy (dummy-package "dummy"
852;; (arguments '(#:implicit-inputs? #f))
853;; (inputs `(("dep" ,dep*)))))
854;; (target "mips64el-linux-gnu"))
855;; ;; XXX: There might be additional grafts, for instance if the distro
856;; ;; defines replacements for core packages like Perl.
857;; (member (graft
858;; (origin (package-cross-derivation %store dep target))
859;; (replacement
860;; (package-cross-derivation %store new target)))
861;; (package-grafts %store dummy #:target target))))
05962f29
LC
862
863(test-assert "package-grafts, indirect grafts, propagated inputs"
864 (let* ((new (dummy-package "dep"
865 (arguments '(#:implicit-inputs? #f))))
866 (dep (package (inherit new) (version "0.0")))
867 (dep* (package (inherit dep) (replacement new)))
868 (prop (dummy-package "propagated"
869 (propagated-inputs `(("dep" ,dep*)))
870 (arguments '(#:implicit-inputs? #f))))
871 (dummy (dummy-package "dummy"
872 (arguments '(#:implicit-inputs? #f))
873 (inputs `(("prop" ,prop))))))
874 (equal? (package-grafts %store dummy)
875 (list (graft
876 (origin (package-derivation %store dep))
877 (replacement (package-derivation %store new)))))))
878
fcadd9ff
LC
879(test-assert "package-grafts, same replacement twice"
880 (let* ((new (dummy-package "dep"
881 (version "1")
882 (arguments '(#:implicit-inputs? #f))))
883 (dep (package (inherit new) (version "0") (replacement new)))
884 (p1 (dummy-package "intermediate1"
885 (arguments '(#:implicit-inputs? #f))
886 (inputs `(("dep" ,dep)))))
887 (p2 (dummy-package "intermediate2"
888 (arguments '(#:implicit-inputs? #f))
889 ;; Here we copy DEP to have an equivalent package that is not
890 ;; 'eq?' to DEP. This is similar to what happens with
891 ;; 'package-with-explicit-inputs' & co.
892 (inputs `(("dep" ,(package (inherit dep)))))))
893 (p3 (dummy-package "final"
894 (arguments '(#:implicit-inputs? #f))
895 (inputs `(("p1" ,p1) ("p2" ,p2))))))
896 (equal? (package-grafts %store p3)
897 (list (graft
898 (origin (package-derivation %store
899 (package (inherit dep)
900 (replacement #f))))
901 (replacement (package-derivation %store new)))))))
902
03a70e4c
LC
903(test-assert "package-grafts, dependency on several outputs"
904 ;; Make sure we get one graft per output; see <https://bugs.gnu.org/41796>.
905 (letrec* ((p0 (dummy-package "p0"
906 (version "1.0")
907 (replacement p0*)
908 (arguments '(#:implicit-inputs? #f))
909 (outputs '("out" "lib"))))
910 (p0* (package (inherit p0) (version "1.1")))
911 (p1 (dummy-package "p1"
912 (arguments '(#:implicit-inputs? #f))
913 (inputs `(("p0" ,p0)
914 ("p0:lib" ,p0 "lib"))))))
915 (lset= equal? (pk (package-grafts %store p1))
916 (list (graft
917 (origin (package-derivation %store p0))
918 (origin-output "out")
919 (replacement (package-derivation %store p0*))
920 (replacement-output "out"))
921 (graft
922 (origin (package-derivation %store p0))
923 (origin-output "lib")
924 (replacement (package-derivation %store p0*))
925 (replacement-output "lib"))))))
926
d0025d01
LC
927(test-assert "replacement also grafted"
928 ;; We build a DAG as below, where dotted arrows represent replacements and
929 ;; solid arrows represent dependencies:
930 ;;
931 ;; P1 ·············> P1R
932 ;; |\__________________.
933 ;; v v
934 ;; P2 ·············> P2R
935 ;; |
936 ;; v
937 ;; P3
938 ;;
939 ;; We want to make sure that:
940 ;; grafts(P3) = (P1,P1R) + (P2, grafted(P2R, (P1,P1R)))
941 ;; where:
942 ;; (A,B) is a graft to replace A by B
943 ;; grafted(DRV,G) denoted DRV with graft G applied
944 (let* ((p1r (dummy-package "P1"
945 (build-system trivial-build-system)
946 (arguments
947 `(#:guile ,%bootstrap-guile
948 #:builder (let ((out (assoc-ref %outputs "out")))
949 (mkdir out)
950 (call-with-output-file
951 (string-append out "/replacement")
952 (const #t)))))))
953 (p1 (package
954 (inherit p1r) (name "p1") (replacement p1r)
955 (arguments
956 `(#:guile ,%bootstrap-guile
1e868858
MW
957 #:builder (begin
958 (mkdir (assoc-ref %outputs "out"))
959 #t)))))
d0025d01
LC
960 (p2r (dummy-package "P2"
961 (build-system trivial-build-system)
962 (inputs `(("p1" ,p1)))
963 (arguments
964 `(#:guile ,%bootstrap-guile
965 #:builder (let ((out (assoc-ref %outputs "out")))
966 (mkdir out)
967 (chdir out)
968 (symlink (assoc-ref %build-inputs "p1") "p1")
969 (call-with-output-file (string-append out "/replacement")
970 (const #t)))))))
971 (p2 (package
972 (inherit p2r) (name "p2") (replacement p2r)
973 (arguments
974 `(#:guile ,%bootstrap-guile
975 #:builder (let ((out (assoc-ref %outputs "out")))
976 (mkdir out)
977 (chdir out)
978 (symlink (assoc-ref %build-inputs "p1")
1e868858
MW
979 "p1")
980 #t)))))
d0025d01
LC
981 (p3 (dummy-package "p3"
982 (build-system trivial-build-system)
983 (inputs `(("p2" ,p2)))
984 (arguments
985 `(#:guile ,%bootstrap-guile
986 #:builder (let ((out (assoc-ref %outputs "out")))
987 (mkdir out)
988 (chdir out)
989 (symlink (assoc-ref %build-inputs "p2")
1e868858
MW
990 "p2")
991 #t))))))
d0025d01
LC
992 (lset= equal?
993 (package-grafts %store p3)
994 (list (graft
995 (origin (package-derivation %store p1 #:graft? #f))
996 (replacement (package-derivation %store p1r)))
997 (graft
998 (origin (package-derivation %store p2 #:graft? #f))
999 (replacement
1000 (package-derivation %store p2r #:graft? #t)))))))
1001
c22a1324
LC
1002;;; XXX: Nowadays 'graft-derivation' needs to build derivations beforehand to
1003;;; find out about their run-time dependencies, so this test is no longer
1004;;; applicable since it would trigger a full rebuild.
1005;;
1006;; (test-assert "package-derivation, indirect grafts"
1007;; (let* ((new (dummy-package "dep"
1008;; (arguments '(#:implicit-inputs? #f))))
1009;; (dep (package (inherit new) (version "0.0")))
1010;; (dep* (package (inherit dep) (replacement new)))
1011;; (dummy (dummy-package "dummy"
1012;; (arguments '(#:implicit-inputs? #f))
1013;; (inputs `(("dep" ,dep*)))))
1014;; (guile (package-derivation %store (canonical-package guile-2.0)
1015;; #:graft? #f)))
1016;; (equal? (package-derivation %store dummy)
1017;; (graft-derivation %store
1018;; (package-derivation %store dummy #:graft? #f)
1019;; (package-grafts %store dummy)
1020
1021;; ;; Use the same Guile as 'package-derivation'.
1022;; #:guile guile))))
05962f29 1023
d3d337d2
LC
1024(test-equal "package->bag"
1025 `("foo86-hurd" #f (,(package-source gnu-make))
1026 (,(canonical-package glibc)) (,(canonical-package coreutils)))
1027 (let ((bag (package->bag gnu-make "foo86-hurd")))
1028 (list (bag-system bag) (bag-target bag)
1029 (assoc-ref (bag-build-inputs bag) "source")
1030 (assoc-ref (bag-build-inputs bag) "libc")
1031 (assoc-ref (bag-build-inputs bag) "coreutils"))))
1032
b49caaa2
LC
1033(test-assert "package->bag, sensitivity to %current-target-system"
1034 ;; https://bugs.gnu.org/41713
1035 (let* ((lower (lambda* (name #:key system target inputs native-inputs
1036 #:allow-other-keys)
1037 (and (not target)
1038 (bag (name name) (system system) (target target)
1039 (build-inputs native-inputs)
1040 (host-inputs inputs)
1041 (build (lambda* (store name inputs
1042 #:key system target
1043 #:allow-other-keys)
1044 (build-expression->derivation
1045 store "foo" '(mkdir %output))))))))
1046 (bs (build-system
1047 (name 'build-system-without-cross-compilation)
1048 (description "Does not support cross compilation.")
1049 (lower lower)))
1050 (dep (dummy-package "dep" (build-system bs)))
1051 (pkg (dummy-package "example"
1052 (native-inputs `(("dep" ,dep)))))
1053 (do-not-build (lambda (continue store lst . _) lst)))
1054 (equal? (with-build-handler do-not-build
1055 (parameterize ((%current-target-system "powerpc64le-linux-gnu")
1056 (%graft? #t))
1057 (package-cross-derivation %store pkg
1058 (%current-target-system)
1059 #:graft? #t)))
1060 (with-build-handler do-not-build
1061 (package-cross-derivation %store
1062 (package (inherit pkg))
1063 "powerpc64le-linux-gnu"
1064 #:graft? #t)))))
1065
d3d337d2
LC
1066(test-equal "package->bag, cross-compilation"
1067 `(,(%current-system) "foo86-hurd"
1068 (,(package-source gnu-make))
1069 (,(canonical-package glibc)) (,(canonical-package coreutils)))
1070 (let ((bag (package->bag gnu-make (%current-system) "foo86-hurd")))
1071 (list (bag-system bag) (bag-target bag)
1072 (assoc-ref (bag-build-inputs bag) "source")
1073 (assoc-ref (bag-build-inputs bag) "libc")
1074 (assoc-ref (bag-build-inputs bag) "coreutils"))))
1075
50373bab
LC
1076(test-assert "package->bag, propagated inputs"
1077 (let* ((dep (dummy-package "dep"))
1078 (prop (dummy-package "prop"
1079 (propagated-inputs `(("dep" ,dep)))))
1080 (dummy (dummy-package "dummy"
1081 (inputs `(("prop" ,prop)))))
1082 (inputs (bag-transitive-inputs (package->bag dummy #:graft? #f))))
161094c8
LC
1083 (match (assoc "dep" inputs)
1084 (("dep" package)
50373bab
LC
1085 (eq? package dep)))))
1086
f52fbf70
LC
1087(test-assert "package->bag, sensitivity to %current-target-system"
1088 (let* ((dep (dummy-package "dep"
1089 (propagated-inputs (if (%current-target-system)
1090 `(("libxml2" ,libxml2))
1091 '()))))
1092 (pkg (dummy-package "foo"
1093 (native-inputs `(("dep" ,dep)))))
1094 (bag (package->bag pkg (%current-system) "foo86-hurd")))
1095 (equal? (parameterize ((%current-target-system "foo64-gnu"))
1096 (bag-transitive-inputs bag))
1097 (parameterize ((%current-target-system #f))
1098 (bag-transitive-inputs bag)))))
1099
d3d337d2 1100(test-assert "bag->derivation"
05962f29
LC
1101 (parameterize ((%graft? #f))
1102 (let ((bag (package->bag gnu-make))
1103 (drv (package-derivation %store gnu-make)))
1104 (parameterize ((%current-system "foox86-hurd")) ;should have no effect
1105 (equal? drv (bag->derivation %store bag))))))
d3d337d2
LC
1106
1107(test-assert "bag->derivation, cross-compilation"
05962f29
LC
1108 (parameterize ((%graft? #f))
1109 (let* ((target "mips64el-linux-gnu")
1110 (bag (package->bag gnu-make (%current-system) target))
1111 (drv (package-cross-derivation %store gnu-make target)))
1112 (parameterize ((%current-system "foox86-hurd") ;should have no effect
1113 (%current-target-system "foo64-linux-gnu"))
1114 (equal? drv (bag->derivation %store bag))))))
d3d337d2 1115
b69c5c2c
LC
1116(when (or (not (network-reachable?)) (shebang-too-long?))
1117 (test-skip 1))
9e782349 1118(test-assert "GNU Make, bootstrap"
03d76577
LC
1119 ;; GNU-MAKE-FOR-TESTS can be built cheaply; we choose it here so that the
1120 ;; test doesn't last for too long.
1121 (let ((gnu-make gnu-make-for-tests))
9e782349
LC
1122 (and (package? gnu-make)
1123 (or (location? (package-location gnu-make))
1124 (not (package-location gnu-make)))
1125 (let* ((drv (package-derivation %store gnu-make))
59688fc4 1126 (out (derivation->output-path drv)))
14da91e2 1127 (and (build-derivations %store (list drv))
9e782349 1128 (file-exists? (string-append out "/bin/make")))))))
e3ce5d70 1129
f37f2b83
LC
1130(test-equal "package-mapping"
1131 42
1132 (let* ((dep (dummy-package "chbouib"
1133 (native-inputs `(("x" ,grep)))))
1134 (p0 (dummy-package "example"
1135 (inputs `(("foo" ,coreutils)
1136 ("bar" ,grep)
1137 ("baz" ,dep)))))
1138 (transform (lambda (p)
1139 (package (inherit p) (source 42))))
1140 (rewrite (package-mapping transform))
1141 (p1 (rewrite p0)))
1142 (and (eq? p1 (rewrite p0))
1143 (eqv? 42 (package-source p1))
1144 (match (package-inputs p1)
1145 ((("foo" dep1) ("bar" dep2) ("baz" dep3))
1146 (and (eq? dep1 (rewrite coreutils)) ;memoization
1147 (eq? dep2 (rewrite grep))
1148 (eq? dep3 (rewrite dep))
1149 (eqv? 42
1150 (package-source dep1) (package-source dep2)
1151 (package-source dep3))
1152 (match (package-native-inputs dep3)
1153 ((("x" dep))
1154 (and (eq? dep (rewrite grep))
1155 (package-source dep))))))))))
1156
2a75b0b6
LC
1157(test-assert "package-input-rewriting"
1158 (let* ((dep (dummy-package "chbouib"
1159 (native-inputs `(("x" ,grep)))))
1160 (p0 (dummy-package "example"
1161 (inputs `(("foo" ,coreutils)
1162 ("bar" ,grep)
1163 ("baz" ,dep)))))
1164 (rewrite (package-input-rewriting `((,coreutils . ,sed)
1165 (,grep . ,findutils))
1166 (cut string-append "r-" <>)))
1167 (p1 (rewrite p0))
1168 (p2 (rewrite p0)))
1169 (and (not (eq? p1 p0))
1170 (eq? p1 p2) ;memoization
1171 (string=? "r-example" (package-name p1))
1172 (match (package-inputs p1)
1173 ((("foo" dep1) ("bar" dep2) ("baz" dep3))
1174 (and (eq? dep1 sed)
1175 (eq? dep2 findutils)
1176 (string=? (package-name dep3) "r-chbouib")
1177 (eq? dep3 (rewrite dep)) ;memoization
1178 (match (package-native-inputs dep3)
1179 ((("x" dep))
1180 (eq? dep findutils)))))))))
1181
f258d886
LC
1182(test-assert "package-input-rewriting/spec"
1183 (let* ((dep (dummy-package "chbouib"
1184 (native-inputs `(("x" ,grep)))))
1185 (p0 (dummy-package "example"
1186 (inputs `(("foo" ,coreutils)
1187 ("bar" ,grep)
1188 ("baz" ,dep)))))
1189 (rewrite (package-input-rewriting/spec
1190 `(("coreutils" . ,(const sed))
1191 ("grep" . ,(const findutils)))))
1192 (p1 (rewrite p0))
1193 (p2 (rewrite p0)))
1194 (and (not (eq? p1 p0))
1195 (eq? p1 p2) ;memoization
1196 (string=? "example" (package-name p1))
1197 (match (package-inputs p1)
1198 ((("foo" dep1) ("bar" dep2) ("baz" dep3))
1199 (and (string=? (package-full-name dep1)
1200 (package-full-name sed))
1201 (string=? (package-full-name dep2)
1202 (package-full-name findutils))
1203 (string=? (package-name dep3) "chbouib")
1204 (eq? dep3 (rewrite dep)) ;memoization
1205 (match (package-native-inputs dep3)
1206 ((("x" dep))
1207 (string=? (package-full-name dep)
1208 (package-full-name findutils))))))))))
1209
1210(test-assert "package-input-rewriting/spec, partial match"
1211 (let* ((dep (dummy-package "chbouib"
1212 (version "1")
1213 (native-inputs `(("x" ,grep)))))
1214 (p0 (dummy-package "example"
1215 (inputs `(("foo" ,coreutils)
1216 ("bar" ,dep)))))
1217 (rewrite (package-input-rewriting/spec
1218 `(("chbouib@123" . ,(const sed)) ;not matched
1219 ("grep" . ,(const findutils)))))
1220 (p1 (rewrite p0)))
1221 (and (not (eq? p1 p0))
1222 (string=? "example" (package-name p1))
1223 (match (package-inputs p1)
1224 ((("foo" dep1) ("bar" dep2))
1225 (and (string=? (package-full-name dep1)
1226 (package-full-name coreutils))
1227 (eq? dep2 (rewrite dep)) ;memoization
1228 (match (package-native-inputs dep2)
1229 ((("x" dep))
1230 (string=? (package-full-name dep)
1231 (package-full-name findutils))))))))))
1232
c423ae89
LC
1233(test-equal "package-patched-vulnerabilities"
1234 '(("CVE-2015-1234")
1235 ("CVE-2016-1234" "CVE-2018-4567")
1236 ())
1237 (let ((p1 (dummy-package "pi"
1238 (source (dummy-origin
1239 (patches (list "/a/b/pi-CVE-2015-1234.patch"))))))
1240 (p2 (dummy-package "pi"
1241 (source (dummy-origin
1242 (patches (list
1243 "/a/b/pi-CVE-2016-1234-CVE-2018-4567.patch"))))))
1244 (p3 (dummy-package "pi" (source (dummy-origin)))))
1245 (map package-patched-vulnerabilities
1246 (list p1 p2 p3))))
1247
ba326ce4
LC
1248(test-eq "fold-packages" hello
1249 (fold-packages (lambda (p r)
1250 (if (string=? (package-name p) "hello")
1251 p
1252 r))
1253 #f))
1254
386b71d1
LC
1255(test-assert "fold-packages, hidden package"
1256 ;; There are two public variables providing "guile@2.0" ('guile-final' in
b66d6d52 1257 ;; commencement.scm and 'guile-2.0' in guile.scm), but only the latter
386b71d1
LC
1258 ;; should show up.
1259 (match (fold-packages (lambda (p r)
1260 (if (and (string=? (package-name p) "guile")
1261 (string-prefix? "2.0"
1262 (package-version p)))
1263 (cons p r)
1264 r))
1265 '())
1266 ((one)
b66d6d52 1267 (eq? one guile-2.0))))
386b71d1 1268
0ea939fb
LC
1269(test-assert "fold-available-packages with/without cache"
1270 (let ()
1271 (define no-cache
1272 (fold-available-packages (lambda* (name version result #:rest rest)
1273 (cons (cons* name version rest)
1274 result))
1275 '()))
1276
1277 (define from-cache
1278 (call-with-temporary-directory
1279 (lambda (cache)
1280 (generate-package-cache cache)
1281 (mock ((guix describe) current-profile (const cache))
1282 (mock ((gnu packages) cache-is-authoritative? (const #t))
1283 (fold-available-packages (lambda* (name version result
1284 #:rest rest)
1285 (cons (cons* name version rest)
1286 result))
1287 '()))))))
1288
36754eee
LC
1289 (and (equal? (delete-duplicates from-cache) from-cache)
1290 (lset= equal? no-cache from-cache))))
0ea939fb 1291
6b1891b0
LC
1292(test-assert "find-packages-by-name"
1293 (match (find-packages-by-name "hello")
1294 (((? (cut eq? hello <>))) #t)
1295 (wrong (pk 'find-packages-by-name wrong #f))))
1296
1297(test-assert "find-packages-by-name with version"
1298 (match (find-packages-by-name "hello" (package-version hello))
1299 (((? (cut eq? hello <>))) #t)
1300 (wrong (pk 'find-packages-by-name wrong #f))))
1301
5fbdc9a5
LC
1302(test-equal "find-packages-by-name with cache"
1303 (find-packages-by-name "guile")
1304 (call-with-temporary-directory
1305 (lambda (cache)
1306 (generate-package-cache cache)
1307 (mock ((guix describe) current-profile (const cache))
1308 (mock ((gnu packages) cache-is-authoritative? (const #t))
1309 (find-packages-by-name "guile"))))))
1310
1311(test-equal "find-packages-by-name + version, with cache"
1312 (find-packages-by-name "guile" "2")
1313 (call-with-temporary-directory
1314 (lambda (cache)
1315 (generate-package-cache cache)
1316 (mock ((guix describe) current-profile (const cache))
1317 (mock ((gnu packages) cache-is-authoritative? (const #t))
1318 (find-packages-by-name "guile" "2"))))))
1319
cf81a236
LC
1320(test-assert "--search-paths with pattern"
1321 ;; Make sure 'guix package --search-paths' correctly reports environment
1322 ;; variables when file patterns are used (in particular, it must follow
1323 ;; symlinks when looking for 'catalog.xml'.) To do that, we rely on the
1324 ;; libxml2 package specification, which contains such a definition.
1325 (let* ((p1 (package
1326 (name "foo") (version "0") (source #f)
1327 (build-system trivial-build-system)
1328 (arguments
1329 `(#:guile ,%bootstrap-guile
1330 #:modules ((guix build utils))
1331 #:builder (begin
1332 (use-modules (guix build utils))
1333 (let ((out (assoc-ref %outputs "out")))
1334 (mkdir-p (string-append out "/xml/bar/baz"))
1335 (call-with-output-file
1336 (string-append out "/xml/bar/baz/catalog.xml")
1337 (lambda (port)
1e868858
MW
1338 (display "xml? wat?!" port)))
1339 #t))))
cf81a236
LC
1340 (synopsis #f) (description #f)
1341 (home-page #f) (license #f)))
1342 (p2 (package
1343 ;; Provide a fake libxml2 to avoid building the real one. This
1344 ;; is OK because 'guix package' gets search path specifications
1345 ;; from the same-named package found in the distro.
1346 (name "libxml2") (version "0.0.0") (source #f)
1347 (build-system trivial-build-system)
1348 (arguments
1349 `(#:guile ,%bootstrap-guile
1e868858
MW
1350 #:builder (begin
1351 (mkdir (assoc-ref %outputs "out"))
1352 #t)))
cf81a236
LC
1353 (native-search-paths (package-native-search-paths libxml2))
1354 (synopsis #f) (description #f)
1355 (home-page #f) (license #f)))
1356 (prof (run-with-store %store
1357 (profile-derivation
1358 (manifest (map package->manifest-entry
1359 (list p1 p2)))
a6562c7e
LC
1360 #:hooks '()
1361 #:locales? #f)
cf81a236
LC
1362 #:guile-for-build (%guile-for-build))))
1363 (build-derivations %store (list prof))
1364 (string-match (format #f "^export XML_CATALOG_FILES=\"~a/xml/+bar/baz/catalog\\.xml\"\n"
77559f23 1365 (regexp-quote (derivation->output-path prof)))
cf81a236
LC
1366 (with-output-to-string
1367 (lambda ()
1368 (guix-package "-p" (derivation->output-path prof)
1369 "--search-paths"))))))
1370
fcd75bdb
LC
1371(test-assert "--search-paths with single-item search path"
1372 ;; Make sure 'guix package --search-paths' correctly reports environment
1373 ;; variables for things like 'GIT_SSL_CAINFO' that have #f as their
1374 ;; separator, meaning that the first match wins.
1375 (let* ((p1 (dummy-package "foo"
1376 (build-system trivial-build-system)
1377 (arguments
1378 `(#:guile ,%bootstrap-guile
1379 #:modules ((guix build utils))
1380 #:builder (begin
1381 (use-modules (guix build utils))
1382 (let ((out (assoc-ref %outputs "out")))
1383 (mkdir-p (string-append out "/etc/ssl/certs"))
1384 (call-with-output-file
1385 (string-append
1386 out "/etc/ssl/certs/ca-certificates.crt")
1387 (const #t))))))))
1388 (p2 (package (inherit p1) (name "bar")))
1389 (p3 (dummy-package "git"
1390 ;; Provide a fake Git to avoid building the real one.
1391 (build-system trivial-build-system)
1392 (arguments
1393 `(#:guile ,%bootstrap-guile
1e868858
MW
1394 #:builder (begin
1395 (mkdir (assoc-ref %outputs "out"))
1396 #t)))
fcd75bdb
LC
1397 (native-search-paths (package-native-search-paths git))))
1398 (prof1 (run-with-store %store
1399 (profile-derivation
1400 (packages->manifest (list p1 p3))
1401 #:hooks '()
1402 #:locales? #f)
1403 #:guile-for-build (%guile-for-build)))
1404 (prof2 (run-with-store %store
1405 (profile-derivation
1406 (packages->manifest (list p2 p3))
1407 #:hooks '()
1408 #:locales? #f)
1409 #:guile-for-build (%guile-for-build))))
1410 (build-derivations %store (list prof1 prof2))
1411 (string-match (format #f "^export GIT_SSL_CAINFO=\"~a/etc/ssl/certs/ca-certificates.crt"
1412 (regexp-quote (derivation->output-path prof1)))
1413 (with-output-to-string
1414 (lambda ()
1415 (guix-package "-p" (derivation->output-path prof1)
1416 "-p" (derivation->output-path prof2)
1417 "--search-paths"))))))
1418
efb107e0
LC
1419(test-equal "specification->package when not found"
1420 'quit
1421 (catch 'quit
1422 (lambda ()
1423 ;; This should call 'leave', producing an error message.
1424 (specification->package "this-package-does-not-exist"))
1425 (lambda (key . args)
1426 key)))
1427
066eeae1
LC
1428(test-equal "specification->package+output"
1429 `((,coreutils "out") (,coreutils "debug"))
1430 (list (call-with-values (lambda ()
1431 (specification->package+output "coreutils"))
1432 list)
1433 (call-with-values (lambda ()
1434 (specification->package+output "coreutils:debug"))
1435 list)))
1436
1437(test-equal "specification->package+output invalid output"
1438 'error
1439 (catch 'quit
1440 (lambda ()
1441 (specification->package+output "coreutils:does-not-exist"))
1442 (lambda _
1443 'error)))
1444
1445(test-equal "specification->package+output no default output"
1446 `(,coreutils #f)
1447 (call-with-values
1448 (lambda ()
1449 (specification->package+output "coreutils" #f))
1450 list))
1451
1452(test-equal "specification->package+output invalid output, no default"
1453 'error
1454 (catch 'quit
1455 (lambda ()
1456 (specification->package+output "coreutils:does-not-exist" #f))
1457 (lambda _
1458 'error)))
1459
ee8099f5
LC
1460(test-equal "find-package-locations"
1461 (map (lambda (package)
1462 (cons (package-version package)
1463 (package-location package)))
1464 (find-packages-by-name "guile"))
1465 (find-package-locations "guile"))
1466
1467(test-equal "find-package-locations with cache"
1468 (map (lambda (package)
1469 (cons (package-version package)
1470 (package-location package)))
1471 (find-packages-by-name "guile"))
1472 (call-with-temporary-directory
1473 (lambda (cache)
1474 (generate-package-cache cache)
1475 (mock ((guix describe) current-profile (const cache))
1476 (mock ((gnu packages) cache-is-authoritative? (const #t))
1477 (find-package-locations "guile"))))))
1478
1479(test-equal "specification->location"
1480 (package-location (specification->package "guile@2"))
1481 (specification->location "guile@2"))
1482
e3ce5d70
LC
1483(test-end "packages")
1484
e3ce5d70 1485;;; Local Variables:
a3d73f59 1486;;; eval: (put 'dummy-package 'scheme-indent-function 1)
3e223a22 1487;;; eval: (put 'dummy-package/no-implicit 'scheme-indent-function 1)
e3ce5d70 1488;;; End: