gnu: ccl: Fix inputs on non-Intel platforms.
[jackhill/guix/guix.git] / tests / packages.scm
CommitLineData
233e7676 1;;; GNU Guix --- Functional package management for GNU
f220a838 2;;; Copyright © 2012, 2013, 2014, 2015 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)
2e1bafb0
LC
23 #:use-module ((guix utils)
24 ;; Rename the 'location' binding to allow proper syntax
25 ;; matching when setting the 'location' field of a package.
26 #:renamer (lambda (name)
27 (cond ((eq? name 'location) 'make-location)
28 (else name))))
f9cc8971 29 #:use-module (guix hash)
e3ce5d70
LC
30 #:use-module (guix derivations)
31 #:use-module (guix packages)
a18eda27 32 #:use-module (guix build-system)
be13fbfa 33 #:use-module (guix build-system trivial)
a3d73f59 34 #:use-module (guix build-system gnu)
cf81a236
LC
35 #:use-module (guix profiles)
36 #:use-module (guix scripts package)
59a43334 37 #:use-module (gnu packages)
1ffa7090 38 #:use-module (gnu packages base)
05962f29 39 #:use-module (gnu packages guile)
1ffa7090 40 #:use-module (gnu packages bootstrap)
cf81a236 41 #:use-module (gnu packages xml)
05962f29 42 #:use-module (srfi srfi-1)
6b1891b0 43 #:use-module (srfi srfi-26)
9b222abe 44 #:use-module (srfi srfi-34)
dbab5150 45 #:use-module (srfi srfi-35)
6b1891b0 46 #:use-module (srfi srfi-64)
860a6f1a 47 #:use-module (rnrs io ports)
2e1bafb0 48 #:use-module (ice-9 regex)
6b1891b0 49 #:use-module (ice-9 match))
e3ce5d70
LC
50
51;; Test the high-level packaging layer.
52
53(define %store
c1bc358f 54 (open-connection-for-tests))
e3ce5d70 55
05962f29
LC
56\f
57(test-begin "packages")
58
2e1bafb0
LC
59(test-assert "printer with location"
60 (string-match "^#<package foo-0 foo.scm:42 [[:xdigit:]]+>$"
61 (with-output-to-string
62 (lambda ()
63 (write
64 (dummy-package "foo"
65 (location (make-location "foo.scm" 42 7))))))))
66
67(test-assert "printer without location"
68 (string-match "^#<package foo-0 [[:xdigit:]]+>$"
69 (with-output-to-string
70 (lambda ()
71 (write
72 (dummy-package "foo" (location #f)))))))
73
d66c7096
LC
74(test-assert "package-field-location"
75 (let ()
76 (define (goto port line column)
77 (unless (and (= (port-column port) (- column 1))
78 (= (port-line port) (- line 1)))
79 (unless (eof-object? (get-char port))
80 (goto port line column))))
81
82 (define read-at
83 (match-lambda
84 (($ <location> file line column)
85 (call-with-input-file (search-path %load-path file)
86 (lambda (port)
87 (goto port line column)
88 (read port))))))
89
ee48b283
LC
90 ;; Until Guile 2.0.6 included, source properties were added only to pairs.
91 ;; Thus, check against both VALUE and (FIELD VALUE).
92 (and (member (read-at (package-field-location %bootstrap-guile 'name))
93 (let ((name (package-name %bootstrap-guile)))
94 (list name `(name ,name))))
95 (member (read-at (package-field-location %bootstrap-guile 'version))
96 (let ((version (package-version %bootstrap-guile)))
97 (list version `(version ,version))))
f903dc05 98 (not (package-field-location %bootstrap-guile 'does-not-exist)))))
d66c7096 99
0b8749b7
LC
100;; Make sure we don't change the file name to an absolute file name.
101(test-equal "package-field-location, relative file name"
102 (location-file (package-location %bootstrap-guile))
103 (with-fluids ((%file-port-name-canonicalization 'absolute))
104 (location-file (package-field-location %bootstrap-guile 'version))))
105
a3d73f59
LC
106(test-assert "package-transitive-inputs"
107 (let* ((a (dummy-package "a"))
108 (b (dummy-package "b"
109 (propagated-inputs `(("a" ,a)))))
110 (c (dummy-package "c"
111 (inputs `(("a" ,a)))))
112 (d (dummy-package "d"
113 (propagated-inputs `(("x" "something.drv")))))
114 (e (dummy-package "e"
115 (inputs `(("b" ,b) ("c" ,c) ("d" ,d))))))
116 (and (null? (package-transitive-inputs a))
117 (equal? `(("a" ,a)) (package-transitive-inputs b))
118 (equal? `(("a" ,a)) (package-transitive-inputs c))
119 (equal? (package-propagated-inputs d)
120 (package-transitive-inputs d))
121 (equal? `(("b" ,b) ("b/a" ,a) ("c" ,c)
122 ("d" ,d) ("d/x" "something.drv"))
123 (pk 'x (package-transitive-inputs e))))))
124
7c3c0374 125(test-equal "package-transitive-supported-systems"
c37a74bd
LC
126 '(("x" "y" "z") ;a
127 ("x" "y") ;b
128 ("y") ;c
129 ("y") ;d
130 ("y")) ;e
9bf3ced0
LC
131 ;; Use TRIVIAL-BUILD-SYSTEM because it doesn't add implicit inputs and thus
132 ;; doesn't restrict the set of supported systems.
133 (let* ((a (dummy-package "a"
134 (build-system trivial-build-system)
135 (supported-systems '("x" "y" "z"))))
136 (b (dummy-package "b"
137 (build-system trivial-build-system)
138 (supported-systems '("x" "y"))
139 (inputs `(("a" ,a)))))
140 (c (dummy-package "c"
141 (build-system trivial-build-system)
142 (supported-systems '("y" "z"))
143 (inputs `(("b" ,b)))))
144 (d (dummy-package "d"
145 (build-system trivial-build-system)
146 (supported-systems '("x" "y" "z"))
147 (inputs `(("b" ,b) ("c" ,c)))))
148 (e (dummy-package "e"
149 (build-system trivial-build-system)
150 (supported-systems '("x" "y" "z"))
151 (inputs `(("d" ,d))))))
7c3c0374
LC
152 (list (package-transitive-supported-systems a)
153 (package-transitive-supported-systems b)
c37a74bd
LC
154 (package-transitive-supported-systems c)
155 (package-transitive-supported-systems d)
156 (package-transitive-supported-systems e))))
7c3c0374 157
9bf3ced0
LC
158(test-equal "package-transitive-supported-systems, implicit inputs"
159 %supported-systems
160
161 ;; Here GNU-BUILD-SYSTEM adds implicit inputs that build only on
162 ;; %SUPPORTED-SYSTEMS. Thus the others must be ignored.
163 (let ((p (dummy-package "foo"
164 (build-system gnu-build-system)
165 (supported-systems
166 `("does-not-exist" "foobar" ,@%supported-systems)))))
167 (package-transitive-supported-systems p)))
168
7357138b
LC
169(test-skip (if (not %store) 8 0))
170
171(test-assert "package-source-derivation, file"
172 (let* ((file (search-path %load-path "guix.scm"))
173 (package (package (inherit (dummy-package "p"))
174 (source file)))
175 (source (package-source-derivation %store
176 (package-source package))))
177 (and (store-path? source)
178 (valid-path? %store source)
179 (equal? (call-with-input-file source get-bytevector-all)
180 (call-with-input-file file get-bytevector-all)))))
181
182(test-assert "package-source-derivation, store path"
183 (let* ((file (add-to-store %store "guix.scm" #t "sha256"
184 (search-path %load-path "guix.scm")))
185 (package (package (inherit (dummy-package "p"))
186 (source file)))
187 (source (package-source-derivation %store
188 (package-source package))))
189 (string=? file source)))
e509d152 190
f80594cc
LC
191(test-assert "package-source-derivation, indirect store path"
192 (let* ((dir (add-to-store %store "guix-build" #t "sha256"
193 (dirname (search-path %load-path
194 "guix/build/utils.scm"))))
195 (package (package (inherit (dummy-package "p"))
196 (source (string-append dir "/utils.scm"))))
197 (source (package-source-derivation %store
198 (package-source package))))
199 (and (direct-store-path? source)
200 (string-suffix? "utils.scm" source))))
201
12d720fd 202(unless (network-reachable?) (test-skip 1))
f9cc8971
LC
203(test-equal "package-source-derivation, snippet"
204 "OK"
127ed6a9 205 (let* ((file (search-bootstrap-binary "guile-2.0.9.tar.xz"
f9cc8971
LC
206 (%current-system)))
207 (sha256 (call-with-input-file file port-sha256))
f220a838 208 (fetch (lambda* (url hash-algo hash
f9cc8971
LC
209 #:optional name #:key system)
210 (pk 'fetch url hash-algo hash name system)
f220a838 211 (interned-file url)))
f9cc8971
LC
212 (source (bootstrap-origin
213 (origin
214 (method fetch)
215 (uri file)
216 (sha256 sha256)
217 (patch-inputs
218 `(("tar" ,%bootstrap-coreutils&co)
219 ("xz" ,%bootstrap-coreutils&co)
220 ("patch" ,%bootstrap-coreutils&co)))
7db9608d 221 (patch-guile %bootstrap-guile)
f9cc8971
LC
222 (modules '((guix build utils)))
223 (imported-modules modules)
224 (snippet '(begin
225 ;; We end up in 'bin', because it's the first
226 ;; directory, alphabetically. Not a very good
227 ;; example but hey.
228 (chmod "." #o777)
229 (symlink "guile" "guile-rocks")
230 (copy-recursively "../share/guile/2.0/scripts"
cf87cc89 231 "scripts"))))))
f9cc8971
LC
232 (package (package (inherit (dummy-package "with-snippet"))
233 (source source)
234 (build-system trivial-build-system)
235 (inputs
236 `(("tar" ,(search-bootstrap-binary "tar"
237 (%current-system)))
238 ("xz" ,(search-bootstrap-binary "xz"
239 (%current-system)))))
240 (arguments
241 `(#:guile ,%bootstrap-guile
242 #:builder
243 (let ((tar (assoc-ref %build-inputs "tar"))
244 (xz (assoc-ref %build-inputs "xz"))
245 (source (assoc-ref %build-inputs "source")))
246 (and (zero? (system* tar "xvf" source
247 "--use-compress-program" xz))
248 (string=? "guile" (readlink "bin/guile-rocks"))
249 (file-exists? "bin/scripts/compile.scm")
250 (let ((out (assoc-ref %outputs "out")))
251 (call-with-output-file out
252 (lambda (p)
253 (display "OK" p))))))))))
254 (drv (package-derivation %store package))
255 (out (derivation->output-path drv)))
256 (and (build-derivations %store (list (pk 'snippet-drv drv)))
257 (call-with-input-file out get-string-all))))
258
59688fc4
LC
259(test-assert "return value"
260 (let ((drv (package-derivation %store (dummy-package "p"))))
261 (and (derivation? drv)
262 (file-exists? (derivation-file-name drv)))))
be13fbfa 263
d510ab46
LC
264(test-assert "package-output"
265 (let* ((package (dummy-package "p"))
59688fc4
LC
266 (drv (package-derivation %store package)))
267 (and (derivation? drv)
268 (string=? (derivation->output-path drv)
d510ab46
LC
269 (package-output %store package "out")))))
270
dbab5150
LC
271(test-assert "patch not found yields a run-time error"
272 (guard (c ((condition-has-type? c &message)
273 (and (string-contains (condition-message c)
274 "does-not-exist.patch")
275 (string-contains (condition-message c)
276 "not found"))))
277 (let ((p (package
278 (inherit (dummy-package "p"))
279 (source (origin
280 (method (const #f))
281 (uri "http://whatever")
282 (patches
283 (list (search-patch "does-not-exist.patch")))
284 (sha256
285 (base32
286 "0amn0bbwqvsvvsh6drfwz20ydc2czk374lzw5kksbh6bf78k4ks4")))))))
287 (package-derivation %store p)
288 #f)))
289
f304c9c2
LC
290(test-assert "reference to non-existent output"
291 ;; See <http://bugs.gnu.org/19630>.
862abf8f
LC
292 (parameterize ((%graft? #f))
293 (let* ((dep (dummy-package "dep"))
294 (p (dummy-package "p"
295 (inputs `(("dep" ,dep "non-existent"))))))
296 (guard (c ((derivation-missing-output-error? c)
297 (and (string=? (derivation-missing-output c) "non-existent")
298 (equal? (package-derivation %store dep)
299 (derivation-error-derivation c)))))
300 (package-derivation %store p)))))
f304c9c2 301
be13fbfa
LC
302(test-assert "trivial"
303 (let* ((p (package (inherit (dummy-package "trivial"))
304 (build-system trivial-build-system)
305 (source #f)
306 (arguments
14da91e2
LC
307 `(#:guile ,%bootstrap-guile
308 #:builder
be13fbfa
LC
309 (begin
310 (mkdir %output)
311 (call-with-output-file (string-append %output "/test")
312 (lambda (p)
313 (display '(hello guix) p))))))))
314 (d (package-derivation %store p)))
315 (and (build-derivations %store (list d))
59688fc4 316 (let ((p (pk 'drv d (derivation->output-path d))))
be13fbfa
LC
317 (equal? '(hello guix)
318 (call-with-input-file (string-append p "/test") read))))))
e3ce5d70 319
860a6f1a
LC
320(test-assert "trivial with local file as input"
321 (let* ((i (search-path %load-path "ice-9/boot-9.scm"))
322 (p (package (inherit (dummy-package "trivial-with-input-file"))
323 (build-system trivial-build-system)
324 (source #f)
325 (arguments
326 `(#:guile ,%bootstrap-guile
327 #:builder (copy-file (assoc-ref %build-inputs "input")
328 %output)))
329 (inputs `(("input" ,i)))))
330 (d (package-derivation %store p)))
331 (and (build-derivations %store (list d))
59688fc4 332 (let ((p (pk 'drv d (derivation->output-path d))))
860a6f1a
LC
333 (equal? (call-with-input-file p get-bytevector-all)
334 (call-with-input-file i get-bytevector-all))))))
335
03761a44
LC
336(test-assert "trivial with source"
337 (let* ((i (search-path %load-path "ice-9/boot-9.scm"))
338 (p (package (inherit (dummy-package "trivial-with-source"))
339 (build-system trivial-build-system)
340 (source i)
341 (arguments
342 `(#:guile ,%bootstrap-guile
343 #:builder (copy-file (assoc-ref %build-inputs "source")
344 %output)))))
345 (d (package-derivation %store p)))
346 (and (build-derivations %store (list d))
347 (let ((p (derivation->output-path d)))
348 (equal? (call-with-input-file p get-bytevector-all)
349 (call-with-input-file i get-bytevector-all))))))
350
592ef6c8
LC
351(test-assert "trivial with system-dependent input"
352 (let* ((p (package (inherit (dummy-package "trivial-system-dependent-input"))
353 (build-system trivial-build-system)
354 (source #f)
355 (arguments
356 `(#:guile ,%bootstrap-guile
357 #:builder
358 (let ((out (assoc-ref %outputs "out"))
359 (bash (assoc-ref %build-inputs "bash")))
360 (zero? (system* bash "-c"
361 (format #f "echo hello > ~a" out))))))
dd6b9a37
LC
362 (inputs `(("bash" ,(search-bootstrap-binary "bash"
363 (%current-system)))))))
592ef6c8
LC
364 (d (package-derivation %store p)))
365 (and (build-derivations %store (list d))
59688fc4 366 (let ((p (pk 'drv d (derivation->output-path d))))
592ef6c8
LC
367 (eq? 'hello (call-with-input-file p read))))))
368
a18eda27
LC
369(test-assert "search paths"
370 (let* ((p (make-prompt-tag "return-search-paths"))
371 (s (build-system
0d5a559f 372 (name 'raw)
a18eda27 373 (description "Raw build system with direct store access")
d3d337d2
LC
374 (lower (lambda* (name #:key source inputs system target
375 #:allow-other-keys)
0d5a559f
LC
376 (bag
377 (name name)
d3d337d2 378 (system system) (target target)
0d5a559f
LC
379 (build-inputs inputs)
380 (build
381 (lambda* (store name inputs
382 #:key outputs system search-paths)
383 search-paths)))))))
a18eda27
LC
384 (x (list (search-path-specification
385 (variable "GUILE_LOAD_PATH")
af070955 386 (files '("share/guile/site/2.0")))
a18eda27
LC
387 (search-path-specification
388 (variable "GUILE_LOAD_COMPILED_PATH")
af070955 389 (files '("share/guile/site/2.0")))))
a18eda27
LC
390 (a (package (inherit (dummy-package "guile"))
391 (build-system s)
392 (native-search-paths x)))
393 (b (package (inherit (dummy-package "guile-foo"))
394 (build-system s)
395 (inputs `(("guile" ,a)))))
396 (c (package (inherit (dummy-package "guile-bar"))
397 (build-system s)
398 (inputs `(("guile" ,a)
399 ("guile-foo" ,b))))))
400 (let-syntax ((collect (syntax-rules ()
401 ((_ body ...)
402 (call-with-prompt p
403 (lambda ()
404 body ...)
405 (lambda (k search-paths)
406 search-paths))))))
407 (and (null? (collect (package-derivation %store a)))
408 (equal? x (collect (package-derivation %store b)))
409 (equal? x (collect (package-derivation %store c)))))))
410
9c1edabd 411(test-assert "package-cross-derivation"
59688fc4
LC
412 (let ((drv (package-cross-derivation %store (dummy-package "p")
413 "mips64el-linux-gnu")))
414 (and (derivation? drv)
415 (file-exists? (derivation-file-name drv)))))
9c1edabd 416
5dce8218
LC
417(test-assert "package-cross-derivation, trivial-build-system"
418 (let ((p (package (inherit (dummy-package "p"))
419 (build-system trivial-build-system)
420 (arguments '(#:builder (exit 1))))))
59688fc4
LC
421 (let ((drv (package-cross-derivation %store p "mips64el-linux-gnu")))
422 (derivation? drv))))
5dce8218 423
9b222abe
LC
424(test-assert "package-cross-derivation, no cross builder"
425 (let* ((b (build-system (inherit trivial-build-system)
0d5a559f 426 (lower (const #f))))
9b222abe
LC
427 (p (package (inherit (dummy-package "p"))
428 (build-system b))))
429 (guard (c ((package-cross-build-system-error? c)
430 (eq? (package-error-package c) p)))
431 (package-cross-derivation %store p "mips64el-linux-gnu")
432 #f)))
433
05962f29
LC
434(test-equal "package-derivation, direct graft"
435 (package-derivation %store gnu-make)
436 (let ((p (package (inherit coreutils)
437 (replacement gnu-make))))
438 (package-derivation %store p)))
439
440(test-equal "package-cross-derivation, direct graft"
441 (package-cross-derivation %store gnu-make "mips64el-linux-gnu")
442 (let ((p (package (inherit coreutils)
443 (replacement gnu-make))))
444 (package-cross-derivation %store p "mips64el-linux-gnu")))
445
446(test-assert "package-grafts, indirect grafts"
447 (let* ((new (dummy-package "dep"
448 (arguments '(#:implicit-inputs? #f))))
449 (dep (package (inherit new) (version "0.0")))
450 (dep* (package (inherit dep) (replacement new)))
451 (dummy (dummy-package "dummy"
452 (arguments '(#:implicit-inputs? #f))
453 (inputs `(("dep" ,dep*))))))
454 (equal? (package-grafts %store dummy)
455 (list (graft
456 (origin (package-derivation %store dep))
457 (replacement (package-derivation %store new)))))))
458
459(test-assert "package-grafts, indirect grafts, cross"
460 (let* ((new (dummy-package "dep"
461 (arguments '(#:implicit-inputs? #f))))
462 (dep (package (inherit new) (version "0.0")))
463 (dep* (package (inherit dep) (replacement new)))
464 (dummy (dummy-package "dummy"
465 (arguments '(#:implicit-inputs? #f))
466 (inputs `(("dep" ,dep*)))))
467 (target "mips64el-linux-gnu"))
468 (equal? (package-grafts %store dummy #:target target)
469 (list (graft
470 (origin (package-cross-derivation %store dep target))
471 (replacement
472 (package-cross-derivation %store new target)))))))
473
474(test-assert "package-grafts, indirect grafts, propagated inputs"
475 (let* ((new (dummy-package "dep"
476 (arguments '(#:implicit-inputs? #f))))
477 (dep (package (inherit new) (version "0.0")))
478 (dep* (package (inherit dep) (replacement new)))
479 (prop (dummy-package "propagated"
480 (propagated-inputs `(("dep" ,dep*)))
481 (arguments '(#:implicit-inputs? #f))))
482 (dummy (dummy-package "dummy"
483 (arguments '(#:implicit-inputs? #f))
484 (inputs `(("prop" ,prop))))))
485 (equal? (package-grafts %store dummy)
486 (list (graft
487 (origin (package-derivation %store dep))
488 (replacement (package-derivation %store new)))))))
489
490(test-assert "package-derivation, indirect grafts"
491 (let* ((new (dummy-package "dep"
492 (arguments '(#:implicit-inputs? #f))))
493 (dep (package (inherit new) (version "0.0")))
494 (dep* (package (inherit dep) (replacement new)))
495 (dummy (dummy-package "dummy"
496 (arguments '(#:implicit-inputs? #f))
497 (inputs `(("dep" ,dep*)))))
498 (guile (package-derivation %store (canonical-package guile-2.0)
499 #:graft? #f)))
500 (equal? (package-derivation %store dummy)
501 (graft-derivation %store "dummy-0"
502 (package-derivation %store dummy #:graft? #f)
503 (package-grafts %store dummy)
504
505 ;; Use the same Guile as 'package-derivation'.
506 #:guile guile))))
507
d3d337d2
LC
508(test-equal "package->bag"
509 `("foo86-hurd" #f (,(package-source gnu-make))
510 (,(canonical-package glibc)) (,(canonical-package coreutils)))
511 (let ((bag (package->bag gnu-make "foo86-hurd")))
512 (list (bag-system bag) (bag-target bag)
513 (assoc-ref (bag-build-inputs bag) "source")
514 (assoc-ref (bag-build-inputs bag) "libc")
515 (assoc-ref (bag-build-inputs bag) "coreutils"))))
516
517(test-equal "package->bag, cross-compilation"
518 `(,(%current-system) "foo86-hurd"
519 (,(package-source gnu-make))
520 (,(canonical-package glibc)) (,(canonical-package coreutils)))
521 (let ((bag (package->bag gnu-make (%current-system) "foo86-hurd")))
522 (list (bag-system bag) (bag-target bag)
523 (assoc-ref (bag-build-inputs bag) "source")
524 (assoc-ref (bag-build-inputs bag) "libc")
525 (assoc-ref (bag-build-inputs bag) "coreutils"))))
526
50373bab
LC
527(test-assert "package->bag, propagated inputs"
528 (let* ((dep (dummy-package "dep"))
529 (prop (dummy-package "prop"
530 (propagated-inputs `(("dep" ,dep)))))
531 (dummy (dummy-package "dummy"
532 (inputs `(("prop" ,prop)))))
533 (inputs (bag-transitive-inputs (package->bag dummy #:graft? #f))))
534 (match (assoc "prop/dep" inputs)
535 (("prop/dep" package)
536 (eq? package dep)))))
537
d3d337d2 538(test-assert "bag->derivation"
05962f29
LC
539 (parameterize ((%graft? #f))
540 (let ((bag (package->bag gnu-make))
541 (drv (package-derivation %store gnu-make)))
542 (parameterize ((%current-system "foox86-hurd")) ;should have no effect
543 (equal? drv (bag->derivation %store bag))))))
d3d337d2
LC
544
545(test-assert "bag->derivation, cross-compilation"
05962f29
LC
546 (parameterize ((%graft? #f))
547 (let* ((target "mips64el-linux-gnu")
548 (bag (package->bag gnu-make (%current-system) target))
549 (drv (package-cross-derivation %store gnu-make target)))
550 (parameterize ((%current-system "foox86-hurd") ;should have no effect
551 (%current-target-system "foo64-linux-gnu"))
552 (equal? drv (bag->derivation %store bag))))))
d3d337d2 553
b69c5c2c
LC
554(when (or (not (network-reachable?)) (shebang-too-long?))
555 (test-skip 1))
9e782349
LC
556(test-assert "GNU Make, bootstrap"
557 ;; GNU Make is the first program built during bootstrap; we choose it
558 ;; here so that the test doesn't last for too long.
bdb36958 559 (let ((gnu-make (@@ (gnu packages commencement) gnu-make-boot0)))
9e782349
LC
560 (and (package? gnu-make)
561 (or (location? (package-location gnu-make))
562 (not (package-location gnu-make)))
563 (let* ((drv (package-derivation %store gnu-make))
59688fc4 564 (out (derivation->output-path drv)))
14da91e2 565 (and (build-derivations %store (list drv))
9e782349 566 (file-exists? (string-append out "/bin/make")))))))
e3ce5d70 567
ba326ce4
LC
568(test-eq "fold-packages" hello
569 (fold-packages (lambda (p r)
570 (if (string=? (package-name p) "hello")
571 p
572 r))
573 #f))
574
6b1891b0
LC
575(test-assert "find-packages-by-name"
576 (match (find-packages-by-name "hello")
577 (((? (cut eq? hello <>))) #t)
578 (wrong (pk 'find-packages-by-name wrong #f))))
579
580(test-assert "find-packages-by-name with version"
581 (match (find-packages-by-name "hello" (package-version hello))
582 (((? (cut eq? hello <>))) #t)
583 (wrong (pk 'find-packages-by-name wrong #f))))
584
cf81a236
LC
585(test-assert "--search-paths with pattern"
586 ;; Make sure 'guix package --search-paths' correctly reports environment
587 ;; variables when file patterns are used (in particular, it must follow
588 ;; symlinks when looking for 'catalog.xml'.) To do that, we rely on the
589 ;; libxml2 package specification, which contains such a definition.
590 (let* ((p1 (package
591 (name "foo") (version "0") (source #f)
592 (build-system trivial-build-system)
593 (arguments
594 `(#:guile ,%bootstrap-guile
595 #:modules ((guix build utils))
596 #:builder (begin
597 (use-modules (guix build utils))
598 (let ((out (assoc-ref %outputs "out")))
599 (mkdir-p (string-append out "/xml/bar/baz"))
600 (call-with-output-file
601 (string-append out "/xml/bar/baz/catalog.xml")
602 (lambda (port)
603 (display "xml? wat?!" port)))))))
604 (synopsis #f) (description #f)
605 (home-page #f) (license #f)))
606 (p2 (package
607 ;; Provide a fake libxml2 to avoid building the real one. This
608 ;; is OK because 'guix package' gets search path specifications
609 ;; from the same-named package found in the distro.
610 (name "libxml2") (version "0.0.0") (source #f)
611 (build-system trivial-build-system)
612 (arguments
613 `(#:guile ,%bootstrap-guile
614 #:builder (mkdir (assoc-ref %outputs "out"))))
615 (native-search-paths (package-native-search-paths libxml2))
616 (synopsis #f) (description #f)
617 (home-page #f) (license #f)))
618 (prof (run-with-store %store
619 (profile-derivation
620 (manifest (map package->manifest-entry
621 (list p1 p2)))
aa46a028 622 #:hooks '())
cf81a236
LC
623 #:guile-for-build (%guile-for-build))))
624 (build-derivations %store (list prof))
625 (string-match (format #f "^export XML_CATALOG_FILES=\"~a/xml/+bar/baz/catalog\\.xml\"\n"
626 (derivation->output-path prof))
627 (with-output-to-string
628 (lambda ()
629 (guix-package "-p" (derivation->output-path prof)
630 "--search-paths"))))))
631
e3ce5d70
LC
632(test-end "packages")
633
634\f
635(exit (= (test-runner-fail-count (test-runner-current)) 0))
636
637;;; Local Variables:
a3d73f59 638;;; eval: (put 'dummy-package 'scheme-indent-function 1)
e3ce5d70 639;;; End: