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