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