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