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