Commit | Line | Data |
---|---|---|
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)) | |
161094c8 LC |
121 | (equal? `(("b" ,b) ("c" ,c) ("d" ,d) |
122 | ("a" ,a) ("x" "something.drv")) | |
a3d73f59 LC |
123 | (pk 'x (package-transitive-inputs e)))))) |
124 | ||
161094c8 LC |
125 | (test-assert "package-transitive-inputs, no duplicates" |
126 | (let* ((a (dummy-package "a")) | |
127 | (b (dummy-package "b" | |
128 | (inputs `(("a+" ,a))) | |
129 | (native-inputs `(("a*" ,a))) | |
130 | (propagated-inputs `(("a" ,a))))) | |
131 | (c (dummy-package "c" | |
132 | (propagated-inputs `(("b" ,b))))) | |
133 | (d (dummy-package "d" | |
134 | (inputs `(("a" ,a) ("c" ,c))))) | |
135 | (e (dummy-package "e" | |
136 | (inputs `(("b" ,b) ("c" ,c)))))) | |
137 | (and (null? (package-transitive-inputs a)) | |
138 | (equal? `(("a*" ,a) ("a+" ,a) ("a" ,a)) ;here duplicates are kept | |
139 | (package-transitive-inputs b)) | |
140 | (equal? `(("b" ,b) ("a" ,a)) | |
141 | (package-transitive-inputs c)) | |
142 | (equal? `(("a" ,a) ("c" ,c) ("b" ,b)) ;duplicate A removed | |
143 | (package-transitive-inputs d)) | |
144 | (equal? `(("b" ,b) ("c" ,c) ("a" ,a)) | |
145 | (package-transitive-inputs e))))) ;ditto | |
146 | ||
7c3c0374 | 147 | (test-equal "package-transitive-supported-systems" |
c37a74bd LC |
148 | '(("x" "y" "z") ;a |
149 | ("x" "y") ;b | |
150 | ("y") ;c | |
151 | ("y") ;d | |
152 | ("y")) ;e | |
9bf3ced0 LC |
153 | ;; Use TRIVIAL-BUILD-SYSTEM because it doesn't add implicit inputs and thus |
154 | ;; doesn't restrict the set of supported systems. | |
155 | (let* ((a (dummy-package "a" | |
156 | (build-system trivial-build-system) | |
157 | (supported-systems '("x" "y" "z")))) | |
158 | (b (dummy-package "b" | |
159 | (build-system trivial-build-system) | |
160 | (supported-systems '("x" "y")) | |
161 | (inputs `(("a" ,a))))) | |
162 | (c (dummy-package "c" | |
163 | (build-system trivial-build-system) | |
164 | (supported-systems '("y" "z")) | |
165 | (inputs `(("b" ,b))))) | |
166 | (d (dummy-package "d" | |
167 | (build-system trivial-build-system) | |
168 | (supported-systems '("x" "y" "z")) | |
169 | (inputs `(("b" ,b) ("c" ,c))))) | |
170 | (e (dummy-package "e" | |
171 | (build-system trivial-build-system) | |
172 | (supported-systems '("x" "y" "z")) | |
173 | (inputs `(("d" ,d)))))) | |
7c3c0374 LC |
174 | (list (package-transitive-supported-systems a) |
175 | (package-transitive-supported-systems b) | |
c37a74bd LC |
176 | (package-transitive-supported-systems c) |
177 | (package-transitive-supported-systems d) | |
178 | (package-transitive-supported-systems e)))) | |
7c3c0374 | 179 | |
f77bcbc3 EB |
180 | (let* ((o (dummy-origin)) |
181 | (u (dummy-origin)) | |
182 | (i (dummy-origin)) | |
183 | (a (dummy-package "a")) | |
184 | (b (dummy-package "b" | |
185 | (inputs `(("a" ,a) ("i" ,i))))) | |
186 | (c (package (inherit b) (source o))) | |
187 | (d (dummy-package "d" | |
188 | (build-system trivial-build-system) | |
189 | (source u) (inputs `(("c" ,c)))))) | |
190 | (test-assert "package-direct-sources, no source" | |
191 | (null? (package-direct-sources a))) | |
192 | (test-equal "package-direct-sources, #f source" | |
193 | (list i) | |
194 | (package-direct-sources b)) | |
195 | (test-equal "package-direct-sources, not input source" | |
196 | (list u) | |
197 | (package-direct-sources d)) | |
198 | (test-assert "package-direct-sources" | |
199 | (let ((s (package-direct-sources c))) | |
200 | (and (= (length (pk 's-sources s)) 2) | |
201 | (member o s) | |
202 | (member i s)))) | |
203 | (test-assert "package-transitive-sources" | |
204 | (let ((s (package-transitive-sources d))) | |
205 | (and (= (length (pk 'd-sources s)) 3) | |
206 | (member o s) | |
207 | (member i s) | |
208 | (member u s))))) | |
209 | ||
9bf3ced0 LC |
210 | (test-equal "package-transitive-supported-systems, implicit inputs" |
211 | %supported-systems | |
212 | ||
213 | ;; Here GNU-BUILD-SYSTEM adds implicit inputs that build only on | |
214 | ;; %SUPPORTED-SYSTEMS. Thus the others must be ignored. | |
215 | (let ((p (dummy-package "foo" | |
216 | (build-system gnu-build-system) | |
217 | (supported-systems | |
218 | `("does-not-exist" "foobar" ,@%supported-systems))))) | |
219 | (package-transitive-supported-systems p))) | |
220 | ||
bbceb0ef LC |
221 | (test-assert "supported-package?" |
222 | (let ((p (dummy-package "foo" | |
223 | (build-system gnu-build-system) | |
224 | (supported-systems '("x86_64-linux" "does-not-exist"))))) | |
225 | (and (supported-package? p "x86_64-linux") | |
226 | (not (supported-package? p "does-not-exist")) | |
227 | (not (supported-package? p "i686-linux"))))) | |
228 | ||
7357138b LC |
229 | (test-skip (if (not %store) 8 0)) |
230 | ||
231 | (test-assert "package-source-derivation, file" | |
232 | (let* ((file (search-path %load-path "guix.scm")) | |
233 | (package (package (inherit (dummy-package "p")) | |
234 | (source file))) | |
235 | (source (package-source-derivation %store | |
236 | (package-source package)))) | |
237 | (and (store-path? source) | |
238 | (valid-path? %store source) | |
239 | (equal? (call-with-input-file source get-bytevector-all) | |
240 | (call-with-input-file file get-bytevector-all))))) | |
241 | ||
242 | (test-assert "package-source-derivation, store path" | |
243 | (let* ((file (add-to-store %store "guix.scm" #t "sha256" | |
244 | (search-path %load-path "guix.scm"))) | |
245 | (package (package (inherit (dummy-package "p")) | |
246 | (source file))) | |
247 | (source (package-source-derivation %store | |
248 | (package-source package)))) | |
249 | (string=? file source))) | |
e509d152 | 250 | |
f80594cc LC |
251 | (test-assert "package-source-derivation, indirect store path" |
252 | (let* ((dir (add-to-store %store "guix-build" #t "sha256" | |
253 | (dirname (search-path %load-path | |
254 | "guix/build/utils.scm")))) | |
255 | (package (package (inherit (dummy-package "p")) | |
256 | (source (string-append dir "/utils.scm")))) | |
257 | (source (package-source-derivation %store | |
258 | (package-source package)))) | |
259 | (and (direct-store-path? source) | |
260 | (string-suffix? "utils.scm" source)))) | |
261 | ||
12d720fd | 262 | (unless (network-reachable?) (test-skip 1)) |
f9cc8971 LC |
263 | (test-equal "package-source-derivation, snippet" |
264 | "OK" | |
5cfc17cb MW |
265 | (let* ((file (search-bootstrap-binary (match (%current-system) |
266 | ("armhf-linux" | |
267 | "guile-2.0.11.tar.xz") | |
268 | (_ | |
269 | "guile-2.0.9.tar.xz")) | |
f9cc8971 LC |
270 | (%current-system))) |
271 | (sha256 (call-with-input-file file port-sha256)) | |
f220a838 | 272 | (fetch (lambda* (url hash-algo hash |
f9cc8971 LC |
273 | #:optional name #:key system) |
274 | (pk 'fetch url hash-algo hash name system) | |
f220a838 | 275 | (interned-file url))) |
f9cc8971 LC |
276 | (source (bootstrap-origin |
277 | (origin | |
278 | (method fetch) | |
279 | (uri file) | |
280 | (sha256 sha256) | |
281 | (patch-inputs | |
282 | `(("tar" ,%bootstrap-coreutils&co) | |
283 | ("xz" ,%bootstrap-coreutils&co) | |
284 | ("patch" ,%bootstrap-coreutils&co))) | |
7db9608d | 285 | (patch-guile %bootstrap-guile) |
f9cc8971 LC |
286 | (modules '((guix build utils))) |
287 | (imported-modules modules) | |
288 | (snippet '(begin | |
289 | ;; We end up in 'bin', because it's the first | |
290 | ;; directory, alphabetically. Not a very good | |
291 | ;; example but hey. | |
292 | (chmod "." #o777) | |
293 | (symlink "guile" "guile-rocks") | |
294 | (copy-recursively "../share/guile/2.0/scripts" | |
cf87cc89 | 295 | "scripts")))))) |
f9cc8971 LC |
296 | (package (package (inherit (dummy-package "with-snippet")) |
297 | (source source) | |
298 | (build-system trivial-build-system) | |
299 | (inputs | |
300 | `(("tar" ,(search-bootstrap-binary "tar" | |
301 | (%current-system))) | |
302 | ("xz" ,(search-bootstrap-binary "xz" | |
303 | (%current-system))))) | |
304 | (arguments | |
305 | `(#:guile ,%bootstrap-guile | |
306 | #:builder | |
307 | (let ((tar (assoc-ref %build-inputs "tar")) | |
308 | (xz (assoc-ref %build-inputs "xz")) | |
309 | (source (assoc-ref %build-inputs "source"))) | |
310 | (and (zero? (system* tar "xvf" source | |
311 | "--use-compress-program" xz)) | |
312 | (string=? "guile" (readlink "bin/guile-rocks")) | |
313 | (file-exists? "bin/scripts/compile.scm") | |
314 | (let ((out (assoc-ref %outputs "out"))) | |
315 | (call-with-output-file out | |
316 | (lambda (p) | |
317 | (display "OK" p)))))))))) | |
318 | (drv (package-derivation %store package)) | |
319 | (out (derivation->output-path drv))) | |
320 | (and (build-derivations %store (list (pk 'snippet-drv drv))) | |
321 | (call-with-input-file out get-string-all)))) | |
322 | ||
59688fc4 LC |
323 | (test-assert "return value" |
324 | (let ((drv (package-derivation %store (dummy-package "p")))) | |
325 | (and (derivation? drv) | |
326 | (file-exists? (derivation-file-name drv))))) | |
be13fbfa | 327 | |
d510ab46 LC |
328 | (test-assert "package-output" |
329 | (let* ((package (dummy-package "p")) | |
59688fc4 LC |
330 | (drv (package-derivation %store package))) |
331 | (and (derivation? drv) | |
332 | (string=? (derivation->output-path drv) | |
d510ab46 LC |
333 | (package-output %store package "out"))))) |
334 | ||
dbab5150 LC |
335 | (test-assert "patch not found yields a run-time error" |
336 | (guard (c ((condition-has-type? c &message) | |
337 | (and (string-contains (condition-message c) | |
338 | "does-not-exist.patch") | |
339 | (string-contains (condition-message c) | |
340 | "not found")))) | |
341 | (let ((p (package | |
342 | (inherit (dummy-package "p")) | |
343 | (source (origin | |
344 | (method (const #f)) | |
345 | (uri "http://whatever") | |
346 | (patches | |
347 | (list (search-patch "does-not-exist.patch"))) | |
348 | (sha256 | |
349 | (base32 | |
350 | "0amn0bbwqvsvvsh6drfwz20ydc2czk374lzw5kksbh6bf78k4ks4"))))))) | |
351 | (package-derivation %store p) | |
352 | #f))) | |
353 | ||
f304c9c2 LC |
354 | (test-assert "reference to non-existent output" |
355 | ;; See <http://bugs.gnu.org/19630>. | |
862abf8f LC |
356 | (parameterize ((%graft? #f)) |
357 | (let* ((dep (dummy-package "dep")) | |
358 | (p (dummy-package "p" | |
359 | (inputs `(("dep" ,dep "non-existent")))))) | |
360 | (guard (c ((derivation-missing-output-error? c) | |
361 | (and (string=? (derivation-missing-output c) "non-existent") | |
362 | (equal? (package-derivation %store dep) | |
363 | (derivation-error-derivation c))))) | |
364 | (package-derivation %store p))))) | |
f304c9c2 | 365 | |
be13fbfa LC |
366 | (test-assert "trivial" |
367 | (let* ((p (package (inherit (dummy-package "trivial")) | |
368 | (build-system trivial-build-system) | |
369 | (source #f) | |
370 | (arguments | |
14da91e2 LC |
371 | `(#:guile ,%bootstrap-guile |
372 | #:builder | |
be13fbfa LC |
373 | (begin |
374 | (mkdir %output) | |
375 | (call-with-output-file (string-append %output "/test") | |
376 | (lambda (p) | |
377 | (display '(hello guix) p)))))))) | |
378 | (d (package-derivation %store p))) | |
379 | (and (build-derivations %store (list d)) | |
59688fc4 | 380 | (let ((p (pk 'drv d (derivation->output-path d)))) |
be13fbfa LC |
381 | (equal? '(hello guix) |
382 | (call-with-input-file (string-append p "/test") read)))))) | |
e3ce5d70 | 383 | |
860a6f1a LC |
384 | (test-assert "trivial with local file as input" |
385 | (let* ((i (search-path %load-path "ice-9/boot-9.scm")) | |
386 | (p (package (inherit (dummy-package "trivial-with-input-file")) | |
387 | (build-system trivial-build-system) | |
388 | (source #f) | |
389 | (arguments | |
390 | `(#:guile ,%bootstrap-guile | |
391 | #:builder (copy-file (assoc-ref %build-inputs "input") | |
392 | %output))) | |
393 | (inputs `(("input" ,i))))) | |
394 | (d (package-derivation %store p))) | |
395 | (and (build-derivations %store (list d)) | |
59688fc4 | 396 | (let ((p (pk 'drv d (derivation->output-path d)))) |
860a6f1a LC |
397 | (equal? (call-with-input-file p get-bytevector-all) |
398 | (call-with-input-file i get-bytevector-all)))))) | |
399 | ||
03761a44 LC |
400 | (test-assert "trivial with source" |
401 | (let* ((i (search-path %load-path "ice-9/boot-9.scm")) | |
402 | (p (package (inherit (dummy-package "trivial-with-source")) | |
403 | (build-system trivial-build-system) | |
404 | (source i) | |
405 | (arguments | |
406 | `(#:guile ,%bootstrap-guile | |
407 | #:builder (copy-file (assoc-ref %build-inputs "source") | |
408 | %output))))) | |
409 | (d (package-derivation %store p))) | |
410 | (and (build-derivations %store (list d)) | |
411 | (let ((p (derivation->output-path d))) | |
412 | (equal? (call-with-input-file p get-bytevector-all) | |
413 | (call-with-input-file i get-bytevector-all)))))) | |
414 | ||
592ef6c8 LC |
415 | (test-assert "trivial with system-dependent input" |
416 | (let* ((p (package (inherit (dummy-package "trivial-system-dependent-input")) | |
417 | (build-system trivial-build-system) | |
418 | (source #f) | |
419 | (arguments | |
420 | `(#:guile ,%bootstrap-guile | |
421 | #:builder | |
422 | (let ((out (assoc-ref %outputs "out")) | |
423 | (bash (assoc-ref %build-inputs "bash"))) | |
424 | (zero? (system* bash "-c" | |
425 | (format #f "echo hello > ~a" out)))))) | |
dd6b9a37 LC |
426 | (inputs `(("bash" ,(search-bootstrap-binary "bash" |
427 | (%current-system))))))) | |
592ef6c8 LC |
428 | (d (package-derivation %store p))) |
429 | (and (build-derivations %store (list d)) | |
59688fc4 | 430 | (let ((p (pk 'drv d (derivation->output-path d)))) |
592ef6c8 LC |
431 | (eq? 'hello (call-with-input-file p read)))))) |
432 | ||
a18eda27 LC |
433 | (test-assert "search paths" |
434 | (let* ((p (make-prompt-tag "return-search-paths")) | |
435 | (s (build-system | |
0d5a559f | 436 | (name 'raw) |
a18eda27 | 437 | (description "Raw build system with direct store access") |
d3d337d2 LC |
438 | (lower (lambda* (name #:key source inputs system target |
439 | #:allow-other-keys) | |
0d5a559f LC |
440 | (bag |
441 | (name name) | |
d3d337d2 | 442 | (system system) (target target) |
0d5a559f LC |
443 | (build-inputs inputs) |
444 | (build | |
445 | (lambda* (store name inputs | |
446 | #:key outputs system search-paths) | |
447 | search-paths))))))) | |
a18eda27 LC |
448 | (x (list (search-path-specification |
449 | (variable "GUILE_LOAD_PATH") | |
af070955 | 450 | (files '("share/guile/site/2.0"))) |
a18eda27 LC |
451 | (search-path-specification |
452 | (variable "GUILE_LOAD_COMPILED_PATH") | |
af070955 | 453 | (files '("share/guile/site/2.0"))))) |
a18eda27 LC |
454 | (a (package (inherit (dummy-package "guile")) |
455 | (build-system s) | |
456 | (native-search-paths x))) | |
457 | (b (package (inherit (dummy-package "guile-foo")) | |
458 | (build-system s) | |
459 | (inputs `(("guile" ,a))))) | |
460 | (c (package (inherit (dummy-package "guile-bar")) | |
461 | (build-system s) | |
462 | (inputs `(("guile" ,a) | |
463 | ("guile-foo" ,b)))))) | |
464 | (let-syntax ((collect (syntax-rules () | |
465 | ((_ body ...) | |
466 | (call-with-prompt p | |
467 | (lambda () | |
468 | body ...) | |
469 | (lambda (k search-paths) | |
470 | search-paths)))))) | |
471 | (and (null? (collect (package-derivation %store a))) | |
472 | (equal? x (collect (package-derivation %store b))) | |
473 | (equal? x (collect (package-derivation %store c))))))) | |
474 | ||
9c1edabd | 475 | (test-assert "package-cross-derivation" |
59688fc4 LC |
476 | (let ((drv (package-cross-derivation %store (dummy-package "p") |
477 | "mips64el-linux-gnu"))) | |
478 | (and (derivation? drv) | |
479 | (file-exists? (derivation-file-name drv))))) | |
9c1edabd | 480 | |
5dce8218 LC |
481 | (test-assert "package-cross-derivation, trivial-build-system" |
482 | (let ((p (package (inherit (dummy-package "p")) | |
483 | (build-system trivial-build-system) | |
484 | (arguments '(#:builder (exit 1)))))) | |
59688fc4 LC |
485 | (let ((drv (package-cross-derivation %store p "mips64el-linux-gnu"))) |
486 | (derivation? drv)))) | |
5dce8218 | 487 | |
9b222abe LC |
488 | (test-assert "package-cross-derivation, no cross builder" |
489 | (let* ((b (build-system (inherit trivial-build-system) | |
0d5a559f | 490 | (lower (const #f)))) |
9b222abe LC |
491 | (p (package (inherit (dummy-package "p")) |
492 | (build-system b)))) | |
493 | (guard (c ((package-cross-build-system-error? c) | |
494 | (eq? (package-error-package c) p))) | |
495 | (package-cross-derivation %store p "mips64el-linux-gnu") | |
496 | #f))) | |
497 | ||
05962f29 LC |
498 | (test-equal "package-derivation, direct graft" |
499 | (package-derivation %store gnu-make) | |
500 | (let ((p (package (inherit coreutils) | |
501 | (replacement gnu-make)))) | |
502 | (package-derivation %store p))) | |
503 | ||
504 | (test-equal "package-cross-derivation, direct graft" | |
505 | (package-cross-derivation %store gnu-make "mips64el-linux-gnu") | |
506 | (let ((p (package (inherit coreutils) | |
507 | (replacement gnu-make)))) | |
508 | (package-cross-derivation %store p "mips64el-linux-gnu"))) | |
509 | ||
510 | (test-assert "package-grafts, indirect grafts" | |
511 | (let* ((new (dummy-package "dep" | |
512 | (arguments '(#:implicit-inputs? #f)))) | |
513 | (dep (package (inherit new) (version "0.0"))) | |
514 | (dep* (package (inherit dep) (replacement new))) | |
515 | (dummy (dummy-package "dummy" | |
516 | (arguments '(#:implicit-inputs? #f)) | |
517 | (inputs `(("dep" ,dep*)))))) | |
518 | (equal? (package-grafts %store dummy) | |
519 | (list (graft | |
520 | (origin (package-derivation %store dep)) | |
521 | (replacement (package-derivation %store new))))))) | |
522 | ||
523 | (test-assert "package-grafts, indirect grafts, cross" | |
524 | (let* ((new (dummy-package "dep" | |
525 | (arguments '(#:implicit-inputs? #f)))) | |
526 | (dep (package (inherit new) (version "0.0"))) | |
527 | (dep* (package (inherit dep) (replacement new))) | |
528 | (dummy (dummy-package "dummy" | |
529 | (arguments '(#:implicit-inputs? #f)) | |
530 | (inputs `(("dep" ,dep*))))) | |
531 | (target "mips64el-linux-gnu")) | |
532 | (equal? (package-grafts %store dummy #:target target) | |
533 | (list (graft | |
534 | (origin (package-cross-derivation %store dep target)) | |
535 | (replacement | |
536 | (package-cross-derivation %store new target))))))) | |
537 | ||
538 | (test-assert "package-grafts, indirect grafts, propagated inputs" | |
539 | (let* ((new (dummy-package "dep" | |
540 | (arguments '(#:implicit-inputs? #f)))) | |
541 | (dep (package (inherit new) (version "0.0"))) | |
542 | (dep* (package (inherit dep) (replacement new))) | |
543 | (prop (dummy-package "propagated" | |
544 | (propagated-inputs `(("dep" ,dep*))) | |
545 | (arguments '(#:implicit-inputs? #f)))) | |
546 | (dummy (dummy-package "dummy" | |
547 | (arguments '(#:implicit-inputs? #f)) | |
548 | (inputs `(("prop" ,prop)))))) | |
549 | (equal? (package-grafts %store dummy) | |
550 | (list (graft | |
551 | (origin (package-derivation %store dep)) | |
552 | (replacement (package-derivation %store new))))))) | |
553 | ||
554 | (test-assert "package-derivation, indirect grafts" | |
555 | (let* ((new (dummy-package "dep" | |
556 | (arguments '(#:implicit-inputs? #f)))) | |
557 | (dep (package (inherit new) (version "0.0"))) | |
558 | (dep* (package (inherit dep) (replacement new))) | |
559 | (dummy (dummy-package "dummy" | |
560 | (arguments '(#:implicit-inputs? #f)) | |
561 | (inputs `(("dep" ,dep*))))) | |
562 | (guile (package-derivation %store (canonical-package guile-2.0) | |
563 | #:graft? #f))) | |
564 | (equal? (package-derivation %store dummy) | |
565 | (graft-derivation %store "dummy-0" | |
566 | (package-derivation %store dummy #:graft? #f) | |
567 | (package-grafts %store dummy) | |
568 | ||
569 | ;; Use the same Guile as 'package-derivation'. | |
570 | #:guile guile)))) | |
571 | ||
d3d337d2 LC |
572 | (test-equal "package->bag" |
573 | `("foo86-hurd" #f (,(package-source gnu-make)) | |
574 | (,(canonical-package glibc)) (,(canonical-package coreutils))) | |
575 | (let ((bag (package->bag gnu-make "foo86-hurd"))) | |
576 | (list (bag-system bag) (bag-target bag) | |
577 | (assoc-ref (bag-build-inputs bag) "source") | |
578 | (assoc-ref (bag-build-inputs bag) "libc") | |
579 | (assoc-ref (bag-build-inputs bag) "coreutils")))) | |
580 | ||
581 | (test-equal "package->bag, cross-compilation" | |
582 | `(,(%current-system) "foo86-hurd" | |
583 | (,(package-source gnu-make)) | |
584 | (,(canonical-package glibc)) (,(canonical-package coreutils))) | |
585 | (let ((bag (package->bag gnu-make (%current-system) "foo86-hurd"))) | |
586 | (list (bag-system bag) (bag-target bag) | |
587 | (assoc-ref (bag-build-inputs bag) "source") | |
588 | (assoc-ref (bag-build-inputs bag) "libc") | |
589 | (assoc-ref (bag-build-inputs bag) "coreutils")))) | |
590 | ||
50373bab LC |
591 | (test-assert "package->bag, propagated inputs" |
592 | (let* ((dep (dummy-package "dep")) | |
593 | (prop (dummy-package "prop" | |
594 | (propagated-inputs `(("dep" ,dep))))) | |
595 | (dummy (dummy-package "dummy" | |
596 | (inputs `(("prop" ,prop))))) | |
597 | (inputs (bag-transitive-inputs (package->bag dummy #:graft? #f)))) | |
161094c8 LC |
598 | (match (assoc "dep" inputs) |
599 | (("dep" package) | |
50373bab LC |
600 | (eq? package dep))))) |
601 | ||
d3d337d2 | 602 | (test-assert "bag->derivation" |
05962f29 LC |
603 | (parameterize ((%graft? #f)) |
604 | (let ((bag (package->bag gnu-make)) | |
605 | (drv (package-derivation %store gnu-make))) | |
606 | (parameterize ((%current-system "foox86-hurd")) ;should have no effect | |
607 | (equal? drv (bag->derivation %store bag)))))) | |
d3d337d2 LC |
608 | |
609 | (test-assert "bag->derivation, cross-compilation" | |
05962f29 LC |
610 | (parameterize ((%graft? #f)) |
611 | (let* ((target "mips64el-linux-gnu") | |
612 | (bag (package->bag gnu-make (%current-system) target)) | |
613 | (drv (package-cross-derivation %store gnu-make target))) | |
614 | (parameterize ((%current-system "foox86-hurd") ;should have no effect | |
615 | (%current-target-system "foo64-linux-gnu")) | |
616 | (equal? drv (bag->derivation %store bag)))))) | |
d3d337d2 | 617 | |
b69c5c2c LC |
618 | (when (or (not (network-reachable?)) (shebang-too-long?)) |
619 | (test-skip 1)) | |
9e782349 LC |
620 | (test-assert "GNU Make, bootstrap" |
621 | ;; GNU Make is the first program built during bootstrap; we choose it | |
622 | ;; here so that the test doesn't last for too long. | |
bdb36958 | 623 | (let ((gnu-make (@@ (gnu packages commencement) gnu-make-boot0))) |
9e782349 LC |
624 | (and (package? gnu-make) |
625 | (or (location? (package-location gnu-make)) | |
626 | (not (package-location gnu-make))) | |
627 | (let* ((drv (package-derivation %store gnu-make)) | |
59688fc4 | 628 | (out (derivation->output-path drv))) |
14da91e2 | 629 | (and (build-derivations %store (list drv)) |
9e782349 | 630 | (file-exists? (string-append out "/bin/make"))))))) |
e3ce5d70 | 631 | |
ba326ce4 LC |
632 | (test-eq "fold-packages" hello |
633 | (fold-packages (lambda (p r) | |
634 | (if (string=? (package-name p) "hello") | |
635 | p | |
636 | r)) | |
637 | #f)) | |
638 | ||
6b1891b0 LC |
639 | (test-assert "find-packages-by-name" |
640 | (match (find-packages-by-name "hello") | |
641 | (((? (cut eq? hello <>))) #t) | |
642 | (wrong (pk 'find-packages-by-name wrong #f)))) | |
643 | ||
644 | (test-assert "find-packages-by-name with version" | |
645 | (match (find-packages-by-name "hello" (package-version hello)) | |
646 | (((? (cut eq? hello <>))) #t) | |
647 | (wrong (pk 'find-packages-by-name wrong #f)))) | |
648 | ||
cf81a236 LC |
649 | (test-assert "--search-paths with pattern" |
650 | ;; Make sure 'guix package --search-paths' correctly reports environment | |
651 | ;; variables when file patterns are used (in particular, it must follow | |
652 | ;; symlinks when looking for 'catalog.xml'.) To do that, we rely on the | |
653 | ;; libxml2 package specification, which contains such a definition. | |
654 | (let* ((p1 (package | |
655 | (name "foo") (version "0") (source #f) | |
656 | (build-system trivial-build-system) | |
657 | (arguments | |
658 | `(#:guile ,%bootstrap-guile | |
659 | #:modules ((guix build utils)) | |
660 | #:builder (begin | |
661 | (use-modules (guix build utils)) | |
662 | (let ((out (assoc-ref %outputs "out"))) | |
663 | (mkdir-p (string-append out "/xml/bar/baz")) | |
664 | (call-with-output-file | |
665 | (string-append out "/xml/bar/baz/catalog.xml") | |
666 | (lambda (port) | |
667 | (display "xml? wat?!" port))))))) | |
668 | (synopsis #f) (description #f) | |
669 | (home-page #f) (license #f))) | |
670 | (p2 (package | |
671 | ;; Provide a fake libxml2 to avoid building the real one. This | |
672 | ;; is OK because 'guix package' gets search path specifications | |
673 | ;; from the same-named package found in the distro. | |
674 | (name "libxml2") (version "0.0.0") (source #f) | |
675 | (build-system trivial-build-system) | |
676 | (arguments | |
677 | `(#:guile ,%bootstrap-guile | |
678 | #:builder (mkdir (assoc-ref %outputs "out")))) | |
679 | (native-search-paths (package-native-search-paths libxml2)) | |
680 | (synopsis #f) (description #f) | |
681 | (home-page #f) (license #f))) | |
682 | (prof (run-with-store %store | |
683 | (profile-derivation | |
684 | (manifest (map package->manifest-entry | |
685 | (list p1 p2))) | |
aa46a028 | 686 | #:hooks '()) |
cf81a236 LC |
687 | #:guile-for-build (%guile-for-build)))) |
688 | (build-derivations %store (list prof)) | |
689 | (string-match (format #f "^export XML_CATALOG_FILES=\"~a/xml/+bar/baz/catalog\\.xml\"\n" | |
690 | (derivation->output-path prof)) | |
691 | (with-output-to-string | |
692 | (lambda () | |
693 | (guix-package "-p" (derivation->output-path prof) | |
694 | "--search-paths")))))) | |
695 | ||
e3ce5d70 LC |
696 | (test-end "packages") |
697 | ||
698 | \f | |
699 | (exit (= (test-runner-fail-count (test-runner-current)) 0)) | |
700 | ||
701 | ;;; Local Variables: | |
a3d73f59 | 702 | ;;; eval: (put 'dummy-package 'scheme-indent-function 1) |
e3ce5d70 | 703 | ;;; End: |