Commit | Line | Data |
---|---|---|
233e7676 | 1 | ;;; GNU Guix --- Functional package management for GNU |
84c5da08 | 2 | ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org> |
0db65c16 | 3 | ;;; Copyright © Jan (janneke) Nieuwenhuizen <janneke@gnu.org> |
e3ce5d70 | 4 | ;;; |
233e7676 | 5 | ;;; This file is part of GNU Guix. |
e3ce5d70 | 6 | ;;; |
233e7676 | 7 | ;;; GNU Guix is free software; you can redistribute it and/or modify it |
e3ce5d70 LC |
8 | ;;; under the terms of the GNU General Public License as published by |
9 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
10 | ;;; your option) any later version. | |
11 | ;;; | |
233e7676 | 12 | ;;; GNU Guix is distributed in the hope that it will be useful, but |
e3ce5d70 LC |
13 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | ;;; GNU General Public License for more details. | |
16 | ;;; | |
17 | ;;; You should have received a copy of the GNU General Public License | |
233e7676 | 18 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. |
e3ce5d70 | 19 | |
e3ce5d70 | 20 | (define-module (test-packages) |
c1bc358f | 21 | #:use-module (guix tests) |
e3ce5d70 | 22 | #:use-module (guix store) |
cf81a236 | 23 | #:use-module (guix monads) |
fcadd9ff | 24 | #:use-module (guix grafts) |
da675305 | 25 | #:use-module ((guix gexp) #:select (local-file local-file-file)) |
a5e2fc73 LC |
26 | #:use-module (guix utils) |
27 | #:use-module ((guix diagnostics) | |
2e1bafb0 LC |
28 | ;; Rename the 'location' binding to allow proper syntax |
29 | ;; matching when setting the 'location' field of a package. | |
30 | #:renamer (lambda (name) | |
31 | (cond ((eq? name 'location) 'make-location) | |
32 | (else name)))) | |
197c07a8 | 33 | #:use-module ((gcrypt hash) #:prefix gcrypt:) |
e3ce5d70 LC |
34 | #:use-module (guix derivations) |
35 | #:use-module (guix packages) | |
7adf9b84 | 36 | #:use-module (guix grafts) |
aa8e0515 | 37 | #:use-module (guix search-paths) |
a18eda27 | 38 | #:use-module (guix build-system) |
be13fbfa | 39 | #:use-module (guix build-system trivial) |
a3d73f59 | 40 | #:use-module (guix build-system gnu) |
2bf6f962 | 41 | #:use-module (guix build-system python) |
0db65c16 | 42 | #:use-module (guix memoization) |
cf81a236 LC |
43 | #:use-module (guix profiles) |
44 | #:use-module (guix scripts package) | |
59a43334 | 45 | #:use-module (gnu packages) |
1ffa7090 | 46 | #:use-module (gnu packages base) |
05962f29 | 47 | #:use-module (gnu packages guile) |
1ffa7090 | 48 | #:use-module (gnu packages bootstrap) |
2bf6f962 | 49 | #:use-module (gnu packages python) |
fcd75bdb | 50 | #:use-module (gnu packages version-control) |
cf81a236 | 51 | #:use-module (gnu packages xml) |
05962f29 | 52 | #:use-module (srfi srfi-1) |
6b1891b0 | 53 | #:use-module (srfi srfi-26) |
9b222abe | 54 | #:use-module (srfi srfi-34) |
dbab5150 | 55 | #:use-module (srfi srfi-35) |
6b1891b0 | 56 | #:use-module (srfi srfi-64) |
ce0be567 | 57 | #:use-module (rnrs bytevectors) |
860a6f1a | 58 | #:use-module (rnrs io ports) |
5239f3d9 | 59 | #:use-module (ice-9 vlist) |
2e1bafb0 | 60 | #:use-module (ice-9 regex) |
6b1891b0 | 61 | #:use-module (ice-9 match)) |
e3ce5d70 LC |
62 | |
63 | ;; Test the high-level packaging layer. | |
64 | ||
65 | (define %store | |
c1bc358f | 66 | (open-connection-for-tests)) |
e3ce5d70 | 67 | |
b4c42a4b LC |
68 | ;; Globally disable grafting to avoid rebuilding the world ('graft-derivation' |
69 | ;; can trigger builds early.) | |
70 | (%graft? #f) | |
71 | ||
05962f29 LC |
72 | \f |
73 | (test-begin "packages") | |
74 | ||
2e1bafb0 | 75 | (test-assert "printer with location" |
74e667d1 | 76 | (string-match "^#<package foo@0 foo.scm:42 [[:xdigit:]]+>$" |
2e1bafb0 LC |
77 | (with-output-to-string |
78 | (lambda () | |
79 | (write | |
80 | (dummy-package "foo" | |
81 | (location (make-location "foo.scm" 42 7)))))))) | |
82 | ||
83 | (test-assert "printer without location" | |
74e667d1 | 84 | (string-match "^#<package foo@0 [[:xdigit:]]+>$" |
2e1bafb0 LC |
85 | (with-output-to-string |
86 | (lambda () | |
87 | (write | |
88 | (dummy-package "foo" (location #f))))))) | |
89 | ||
6980511b LC |
90 | (test-assert "hidden-package" |
91 | (and (hidden-package? (hidden-package (dummy-package "foo"))) | |
92 | (not (hidden-package? (dummy-package "foo"))))) | |
93 | ||
01afdab8 LC |
94 | (test-assert "package-superseded" |
95 | (let* ((new (dummy-package "bar")) | |
96 | (old (deprecated-package "foo" new))) | |
97 | (and (eq? (package-superseded old) new) | |
98 | (mock ((gnu packages) find-best-packages-by-name (const (list old))) | |
99 | (specification->package "foo") | |
100 | (and (eq? new (specification->package "foo")) | |
101 | (eq? new (specification->package+output "foo"))))))) | |
102 | ||
5239f3d9 LC |
103 | (test-assert "transaction-upgrade-entry, zero upgrades" |
104 | (let* ((old (dummy-package "foo" (version "1"))) | |
465a0d65 LC |
105 | (tx (mock ((gnu packages) find-best-packages-by-name |
106 | (const '())) | |
84c5da08 LC |
107 | (transaction-upgrade-entry |
108 | #f ;no store access needed | |
5239f3d9 LC |
109 | (manifest-entry |
110 | (inherit (package->manifest-entry old)) | |
111 | (item (string-append (%store-prefix) "/" | |
112 | (make-string 32 #\e) "-foo-1"))) | |
113 | (manifest-transaction))))) | |
114 | (manifest-transaction-null? tx))) | |
115 | ||
b9c79cae LC |
116 | (test-assert "transaction-upgrade-entry, zero upgrades, equivalent package" |
117 | (let* ((old (dummy-package "foo" (version "1"))) | |
118 | (drv (package-derivation %store old)) | |
119 | (tx (mock ((gnu packages) find-best-packages-by-name | |
120 | (const (list old))) | |
121 | (transaction-upgrade-entry | |
122 | %store | |
123 | (manifest-entry | |
124 | (inherit (package->manifest-entry old)) | |
125 | (item (derivation->output-path drv))) | |
126 | (manifest-transaction))))) | |
127 | (manifest-transaction-null? tx))) | |
128 | ||
a357849f LC |
129 | (test-assert "transaction-upgrade-entry, zero upgrades, propagated inputs" |
130 | ;; Properly detect equivalent packages even when they have propagated | |
131 | ;; inputs. See <https://bugs.gnu.org/35872>. | |
132 | (let* ((dep (dummy-package "dep" (version "2"))) | |
133 | (old (dummy-package "foo" (version "1") | |
134 | (propagated-inputs `(("dep" ,dep))))) | |
135 | (drv (package-derivation %store old)) | |
136 | (tx (mock ((gnu packages) find-best-packages-by-name | |
137 | (const (list old))) | |
138 | (transaction-upgrade-entry | |
139 | %store | |
140 | (manifest-entry | |
141 | (inherit (package->manifest-entry old)) | |
142 | (item (derivation->output-path drv)) | |
143 | (dependencies | |
144 | (list (manifest-entry | |
145 | (inherit (package->manifest-entry dep)) | |
146 | (item (derivation->output-path | |
147 | (package-derivation %store dep))))))) | |
148 | (manifest-transaction))))) | |
149 | (manifest-transaction-null? tx))) | |
150 | ||
5239f3d9 LC |
151 | (test-assert "transaction-upgrade-entry, one upgrade" |
152 | (let* ((old (dummy-package "foo" (version "1"))) | |
153 | (new (dummy-package "foo" (version "2"))) | |
465a0d65 LC |
154 | (tx (mock ((gnu packages) find-best-packages-by-name |
155 | (const (list new))) | |
84c5da08 LC |
156 | (transaction-upgrade-entry |
157 | #f ;no store access needed | |
5239f3d9 LC |
158 | (manifest-entry |
159 | (inherit (package->manifest-entry old)) | |
160 | (item (string-append (%store-prefix) "/" | |
161 | (make-string 32 #\e) "-foo-1"))) | |
162 | (manifest-transaction))))) | |
163 | (and (match (manifest-transaction-install tx) | |
164 | ((($ <manifest-entry> "foo" "2" "out" item)) | |
165 | (eq? item new))) | |
166 | (null? (manifest-transaction-remove tx))))) | |
167 | ||
01afdab8 LC |
168 | (test-assert "transaction-upgrade-entry, superseded package" |
169 | (let* ((old (dummy-package "foo" (version "1"))) | |
170 | (new (dummy-package "bar" (version "2"))) | |
171 | (dep (deprecated-package "foo" new)) | |
465a0d65 LC |
172 | (tx (mock ((gnu packages) find-best-packages-by-name |
173 | (const (list dep))) | |
84c5da08 LC |
174 | (transaction-upgrade-entry |
175 | #f ;no store access needed | |
01afdab8 LC |
176 | (manifest-entry |
177 | (inherit (package->manifest-entry old)) | |
178 | (item (string-append (%store-prefix) "/" | |
179 | (make-string 32 #\e) "-foo-1"))) | |
180 | (manifest-transaction))))) | |
181 | (and (match (manifest-transaction-install tx) | |
182 | ((($ <manifest-entry> "bar" "2" "out" item)) | |
183 | (eq? item new))) | |
184 | (match (manifest-transaction-remove tx) | |
185 | (((? manifest-pattern? pattern)) | |
186 | (and (string=? (manifest-pattern-name pattern) "foo") | |
187 | (string=? (manifest-pattern-version pattern) "1") | |
188 | (string=? (manifest-pattern-output pattern) "out"))))))) | |
189 | ||
a187cc56 LC |
190 | (test-assert "transaction-upgrade-entry, grafts" |
191 | ;; Ensure that, when grafts are enabled, 'transaction-upgrade-entry' doesn't | |
192 | ;; try to build stuff. | |
193 | (with-build-handler (const 'failed!) | |
194 | (parameterize ((%graft? #t)) | |
195 | (let* ((old (dummy-package "foo" (version "1"))) | |
196 | (bar (dummy-package "bar" (version "0") | |
197 | (replacement old))) | |
198 | (new (dummy-package "foo" (version "1") | |
199 | (inputs `(("bar" ,bar))))) | |
200 | (tx (mock ((gnu packages) find-best-packages-by-name | |
201 | (const (list new))) | |
202 | (transaction-upgrade-entry | |
203 | %store | |
204 | (manifest-entry | |
205 | (inherit (package->manifest-entry old)) | |
206 | (item (string-append (%store-prefix) "/" | |
207 | (make-string 32 #\e) "-foo-1"))) | |
208 | (manifest-transaction))))) | |
209 | (and (match (manifest-transaction-install tx) | |
210 | ((($ <manifest-entry> "foo" "1" "out" item)) | |
211 | (eq? item new))) | |
212 | (null? (manifest-transaction-remove tx))))))) | |
213 | ||
d66c7096 LC |
214 | (test-assert "package-field-location" |
215 | (let () | |
216 | (define (goto port line column) | |
217 | (unless (and (= (port-column port) (- column 1)) | |
218 | (= (port-line port) (- line 1))) | |
219 | (unless (eof-object? (get-char port)) | |
220 | (goto port line column)))) | |
221 | ||
222 | (define read-at | |
223 | (match-lambda | |
224 | (($ <location> file line column) | |
225 | (call-with-input-file (search-path %load-path file) | |
226 | (lambda (port) | |
227 | (goto port line column) | |
228 | (read port)))))) | |
229 | ||
ee48b283 LC |
230 | ;; Until Guile 2.0.6 included, source properties were added only to pairs. |
231 | ;; Thus, check against both VALUE and (FIELD VALUE). | |
232 | (and (member (read-at (package-field-location %bootstrap-guile 'name)) | |
233 | (let ((name (package-name %bootstrap-guile))) | |
234 | (list name `(name ,name)))) | |
235 | (member (read-at (package-field-location %bootstrap-guile 'version)) | |
236 | (let ((version (package-version %bootstrap-guile))) | |
237 | (list version `(version ,version)))) | |
f903dc05 | 238 | (not (package-field-location %bootstrap-guile 'does-not-exist))))) |
d66c7096 | 239 | |
0b8749b7 LC |
240 | ;; Make sure we don't change the file name to an absolute file name. |
241 | (test-equal "package-field-location, relative file name" | |
242 | (location-file (package-location %bootstrap-guile)) | |
243 | (with-fluids ((%file-port-name-canonicalization 'absolute)) | |
244 | (location-file (package-field-location %bootstrap-guile 'version)))) | |
245 | ||
a3d73f59 LC |
246 | (test-assert "package-transitive-inputs" |
247 | (let* ((a (dummy-package "a")) | |
248 | (b (dummy-package "b" | |
249 | (propagated-inputs `(("a" ,a))))) | |
250 | (c (dummy-package "c" | |
251 | (inputs `(("a" ,a))))) | |
252 | (d (dummy-package "d" | |
253 | (propagated-inputs `(("x" "something.drv"))))) | |
254 | (e (dummy-package "e" | |
255 | (inputs `(("b" ,b) ("c" ,c) ("d" ,d)))))) | |
256 | (and (null? (package-transitive-inputs a)) | |
257 | (equal? `(("a" ,a)) (package-transitive-inputs b)) | |
258 | (equal? `(("a" ,a)) (package-transitive-inputs c)) | |
259 | (equal? (package-propagated-inputs d) | |
260 | (package-transitive-inputs d)) | |
161094c8 LC |
261 | (equal? `(("b" ,b) ("c" ,c) ("d" ,d) |
262 | ("a" ,a) ("x" "something.drv")) | |
a3d73f59 LC |
263 | (pk 'x (package-transitive-inputs e)))))) |
264 | ||
161094c8 LC |
265 | (test-assert "package-transitive-inputs, no duplicates" |
266 | (let* ((a (dummy-package "a")) | |
267 | (b (dummy-package "b" | |
268 | (inputs `(("a+" ,a))) | |
269 | (native-inputs `(("a*" ,a))) | |
270 | (propagated-inputs `(("a" ,a))))) | |
271 | (c (dummy-package "c" | |
272 | (propagated-inputs `(("b" ,b))))) | |
273 | (d (dummy-package "d" | |
274 | (inputs `(("a" ,a) ("c" ,c))))) | |
275 | (e (dummy-package "e" | |
276 | (inputs `(("b" ,b) ("c" ,c)))))) | |
277 | (and (null? (package-transitive-inputs a)) | |
278 | (equal? `(("a*" ,a) ("a+" ,a) ("a" ,a)) ;here duplicates are kept | |
279 | (package-transitive-inputs b)) | |
280 | (equal? `(("b" ,b) ("a" ,a)) | |
281 | (package-transitive-inputs c)) | |
282 | (equal? `(("a" ,a) ("c" ,c) ("b" ,b)) ;duplicate A removed | |
283 | (package-transitive-inputs d)) | |
284 | (equal? `(("b" ,b) ("c" ,c) ("a" ,a)) | |
285 | (package-transitive-inputs e))))) ;ditto | |
286 | ||
7c3c0374 | 287 | (test-equal "package-transitive-supported-systems" |
c37a74bd LC |
288 | '(("x" "y" "z") ;a |
289 | ("x" "y") ;b | |
290 | ("y") ;c | |
291 | ("y") ;d | |
292 | ("y")) ;e | |
9bf3ced0 LC |
293 | ;; Use TRIVIAL-BUILD-SYSTEM because it doesn't add implicit inputs and thus |
294 | ;; doesn't restrict the set of supported systems. | |
295 | (let* ((a (dummy-package "a" | |
296 | (build-system trivial-build-system) | |
297 | (supported-systems '("x" "y" "z")))) | |
298 | (b (dummy-package "b" | |
299 | (build-system trivial-build-system) | |
300 | (supported-systems '("x" "y")) | |
301 | (inputs `(("a" ,a))))) | |
302 | (c (dummy-package "c" | |
303 | (build-system trivial-build-system) | |
304 | (supported-systems '("y" "z")) | |
305 | (inputs `(("b" ,b))))) | |
306 | (d (dummy-package "d" | |
307 | (build-system trivial-build-system) | |
308 | (supported-systems '("x" "y" "z")) | |
309 | (inputs `(("b" ,b) ("c" ,c))))) | |
310 | (e (dummy-package "e" | |
311 | (build-system trivial-build-system) | |
312 | (supported-systems '("x" "y" "z")) | |
313 | (inputs `(("d" ,d)))))) | |
7c3c0374 LC |
314 | (list (package-transitive-supported-systems a) |
315 | (package-transitive-supported-systems b) | |
c37a74bd LC |
316 | (package-transitive-supported-systems c) |
317 | (package-transitive-supported-systems d) | |
318 | (package-transitive-supported-systems e)))) | |
7c3c0374 | 319 | |
3e223a22 LC |
320 | (test-assert "package-closure" |
321 | (let-syntax ((dummy-package/no-implicit | |
322 | (syntax-rules () | |
323 | ((_ name rest ...) | |
324 | (package | |
325 | (inherit (dummy-package name rest ...)) | |
326 | (build-system trivial-build-system)))))) | |
327 | (let* ((a (dummy-package/no-implicit "a")) | |
328 | (b (dummy-package/no-implicit "b" | |
329 | (propagated-inputs `(("a" ,a))))) | |
330 | (c (dummy-package/no-implicit "c" | |
331 | (inputs `(("a" ,a))))) | |
332 | (d (dummy-package/no-implicit "d" | |
333 | (native-inputs `(("b" ,b))))) | |
334 | (e (dummy-package/no-implicit "e" | |
335 | (inputs `(("c" ,c) ("d" ,d)))))) | |
336 | (lset= eq? | |
337 | (list a b c d e) | |
338 | (package-closure (list e)) | |
339 | (package-closure (list e d)) | |
340 | (package-closure (list e c b)))))) | |
341 | ||
3b4d0103 EB |
342 | (test-equal "origin-actual-file-name" |
343 | "foo-1.tar.gz" | |
344 | (let ((o (dummy-origin (uri "http://www.example.com/foo-1.tar.gz")))) | |
345 | (origin-actual-file-name o))) | |
346 | ||
347 | (test-equal "origin-actual-file-name, file-name" | |
348 | "foo-1.tar.gz" | |
349 | (let ((o (dummy-origin | |
350 | (uri "http://www.example.com/tarball") | |
351 | (file-name "foo-1.tar.gz")))) | |
352 | (origin-actual-file-name o))) | |
353 | ||
f77bcbc3 EB |
354 | (let* ((o (dummy-origin)) |
355 | (u (dummy-origin)) | |
356 | (i (dummy-origin)) | |
357 | (a (dummy-package "a")) | |
358 | (b (dummy-package "b" | |
359 | (inputs `(("a" ,a) ("i" ,i))))) | |
360 | (c (package (inherit b) (source o))) | |
361 | (d (dummy-package "d" | |
362 | (build-system trivial-build-system) | |
363 | (source u) (inputs `(("c" ,c)))))) | |
364 | (test-assert "package-direct-sources, no source" | |
365 | (null? (package-direct-sources a))) | |
366 | (test-equal "package-direct-sources, #f source" | |
367 | (list i) | |
368 | (package-direct-sources b)) | |
369 | (test-equal "package-direct-sources, not input source" | |
370 | (list u) | |
371 | (package-direct-sources d)) | |
372 | (test-assert "package-direct-sources" | |
373 | (let ((s (package-direct-sources c))) | |
374 | (and (= (length (pk 's-sources s)) 2) | |
375 | (member o s) | |
376 | (member i s)))) | |
377 | (test-assert "package-transitive-sources" | |
378 | (let ((s (package-transitive-sources d))) | |
379 | (and (= (length (pk 'd-sources s)) 3) | |
380 | (member o s) | |
381 | (member i s) | |
382 | (member u s))))) | |
383 | ||
a6d0b306 EB |
384 | (test-assert "transitive-input-references" |
385 | (let* ((a (dummy-package "a")) | |
386 | (b (dummy-package "b")) | |
387 | (c (dummy-package "c" | |
388 | (inputs `(("a" ,a))) | |
389 | (propagated-inputs `(("boo" ,b))))) | |
390 | (d (dummy-package "d" | |
391 | (inputs `(("c*" ,c))))) | |
392 | (keys (map (match-lambda | |
393 | (('assoc-ref 'l key) | |
394 | key)) | |
395 | (pk 'refs (transitive-input-references | |
396 | 'l (package-inputs d)))))) | |
397 | (and (= (length keys) 2) | |
398 | (member "c*" keys) | |
399 | (member "boo" keys)))) | |
400 | ||
9bf3ced0 LC |
401 | (test-equal "package-transitive-supported-systems, implicit inputs" |
402 | %supported-systems | |
403 | ||
0db65c16 JN |
404 | ;; Here GNU-BUILD-SYSTEM adds implicit inputs that build only on |
405 | ;; %SUPPORTED-SYSTEMS. Thus the others must be ignored. | |
406 | (let ((p (dummy-package "foo" | |
407 | (build-system gnu-build-system) | |
408 | (supported-systems | |
409 | `("does-not-exist" "foobar" ,@%supported-systems))))) | |
0db65c16 JN |
410 | (parameterize ((%current-system "armhf-linux")) ; a traditionally-bootstrapped architecture |
411 | (package-transitive-supported-systems p)))) | |
412 | ||
413 | (test-equal "package-transitive-supported-systems: reduced binary seed, implicit inputs" | |
414 | '("x86_64-linux" "i686-linux") | |
415 | ||
9bf3ced0 LC |
416 | ;; Here GNU-BUILD-SYSTEM adds implicit inputs that build only on |
417 | ;; %SUPPORTED-SYSTEMS. Thus the others must be ignored. | |
418 | (let ((p (dummy-package "foo" | |
419 | (build-system gnu-build-system) | |
420 | (supported-systems | |
421 | `("does-not-exist" "foobar" ,@%supported-systems))))) | |
0db65c16 JN |
422 | (parameterize ((%current-system "x86_64-linux")) |
423 | (package-transitive-supported-systems p)))) | |
9bf3ced0 | 424 | |
bbceb0ef | 425 | (test-assert "supported-package?" |
bc60349b LC |
426 | (let* ((d (dummy-package "dep" |
427 | (build-system trivial-build-system) | |
428 | (supported-systems '("x86_64-linux")))) | |
429 | (p (dummy-package "foo" | |
430 | (build-system gnu-build-system) | |
431 | (inputs `(("d" ,d))) | |
432 | (supported-systems '("x86_64-linux" "armhf-linux"))))) | |
433 | (and (supported-package? p "x86_64-linux") | |
434 | (not (supported-package? p "i686-linux")) | |
435 | (not (supported-package? p "armhf-linux"))))) | |
436 | ||
437 | (test-assert "supported-package? vs. system-dependent graph" | |
438 | ;; The inputs of a package can depend on (%current-system). Thus, | |
439 | ;; 'supported-package?' must make sure that it binds (%current-system) | |
440 | ;; appropriately before traversing the dependency graph. In the example | |
441 | ;; below, 'supported-package?' must thus return true for both systems. | |
442 | (let* ((p0a (dummy-package "foo-arm" | |
443 | (build-system trivial-build-system) | |
444 | (supported-systems '("armhf-linux")))) | |
445 | (p0b (dummy-package "foo-x86_64" | |
446 | (build-system trivial-build-system) | |
447 | (supported-systems '("x86_64-linux")))) | |
448 | (p (dummy-package "bar" | |
449 | (build-system trivial-build-system) | |
450 | (inputs | |
451 | (if (string=? (%current-system) "armhf-linux") | |
452 | `(("foo" ,p0a)) | |
453 | `(("foo" ,p0b))))))) | |
bbceb0ef | 454 | (and (supported-package? p "x86_64-linux") |
bc60349b | 455 | (supported-package? p "armhf-linux")))) |
bbceb0ef | 456 | |
7357138b LC |
457 | (test-skip (if (not %store) 8 0)) |
458 | ||
459 | (test-assert "package-source-derivation, file" | |
460 | (let* ((file (search-path %load-path "guix.scm")) | |
461 | (package (package (inherit (dummy-package "p")) | |
462 | (source file))) | |
463 | (source (package-source-derivation %store | |
464 | (package-source package)))) | |
465 | (and (store-path? source) | |
466 | (valid-path? %store source) | |
467 | (equal? (call-with-input-file source get-bytevector-all) | |
468 | (call-with-input-file file get-bytevector-all))))) | |
469 | ||
470 | (test-assert "package-source-derivation, store path" | |
471 | (let* ((file (add-to-store %store "guix.scm" #t "sha256" | |
472 | (search-path %load-path "guix.scm"))) | |
473 | (package (package (inherit (dummy-package "p")) | |
474 | (source file))) | |
475 | (source (package-source-derivation %store | |
476 | (package-source package)))) | |
477 | (string=? file source))) | |
e509d152 | 478 | |
f80594cc LC |
479 | (test-assert "package-source-derivation, indirect store path" |
480 | (let* ((dir (add-to-store %store "guix-build" #t "sha256" | |
481 | (dirname (search-path %load-path | |
482 | "guix/build/utils.scm")))) | |
483 | (package (package (inherit (dummy-package "p")) | |
484 | (source (string-append dir "/utils.scm")))) | |
485 | (source (package-source-derivation %store | |
486 | (package-source package)))) | |
487 | (and (direct-store-path? source) | |
488 | (string-suffix? "utils.scm" source)))) | |
489 | ||
da675305 LC |
490 | (test-assert "package-source-derivation, local-file" |
491 | (let* ((file (local-file "../guix/base32.scm")) | |
492 | (package (package (inherit (dummy-package "p")) | |
493 | (source file))) | |
494 | (source (package-source-derivation %store | |
495 | (package-source package)))) | |
496 | (and (store-path? source) | |
497 | (string-suffix? "base32.scm" source) | |
498 | (valid-path? %store source) | |
499 | (equal? (call-with-input-file source get-bytevector-all) | |
500 | (call-with-input-file | |
501 | (search-path %load-path "guix/base32.scm") | |
502 | get-bytevector-all))))) | |
503 | ||
ce0be567 LC |
504 | (test-equal "package-source-derivation, origin, sha512" |
505 | "hello" | |
506 | (let* ((bash (search-bootstrap-binary "bash" (%current-system))) | |
507 | (builder (add-text-to-store %store "my-fixed-builder.sh" | |
508 | "echo -n hello > $out" '())) | |
509 | (method (lambda* (url hash-algo hash #:optional name | |
510 | #:rest rest) | |
511 | (and (eq? hash-algo 'sha512) | |
512 | (raw-derivation name bash (list builder) | |
513 | #:sources (list builder) | |
514 | #:hash hash | |
515 | #:hash-algo hash-algo)))) | |
516 | (source (origin | |
517 | (method method) | |
518 | (uri "unused://") | |
519 | (file-name "origin-sha512") | |
520 | (hash (content-hash | |
197c07a8 LC |
521 | (gcrypt:bytevector-hash (string->utf8 "hello") |
522 | (gcrypt:lookup-hash-algorithm | |
523 | 'sha512)) | |
ce0be567 LC |
524 | sha512)))) |
525 | (drv (package-source-derivation %store source)) | |
526 | (output (derivation->output-path drv))) | |
527 | (build-derivations %store (list drv)) | |
528 | (call-with-input-file output get-string-all))) | |
529 | ||
0505eda9 LC |
530 | (test-equal "package-source-derivation, origin, sha3-512" |
531 | "hello, sha3" | |
532 | (let* ((bash (search-bootstrap-binary "bash" (%current-system))) | |
533 | (builder (add-text-to-store %store "my-fixed-builder.sh" | |
534 | "echo -n hello, sha3 > $out" '())) | |
535 | (method (lambda* (url hash-algo hash #:optional name | |
536 | #:rest rest) | |
537 | (and (eq? hash-algo 'sha3-512) | |
538 | (raw-derivation name bash (list builder) | |
539 | #:sources (list builder) | |
540 | #:hash hash | |
541 | #:hash-algo hash-algo)))) | |
542 | (source (origin | |
543 | (method method) | |
544 | (uri "unused://") | |
545 | (file-name "origin-sha3") | |
546 | (hash (content-hash | |
547 | (gcrypt:bytevector-hash (string->utf8 "hello, sha3") | |
548 | (gcrypt:lookup-hash-algorithm | |
549 | 'sha3-512)) | |
550 | sha3-512)))) | |
551 | (drv (package-source-derivation %store source)) | |
552 | (output (derivation->output-path drv))) | |
553 | (build-derivations %store (list drv)) | |
554 | (call-with-input-file output get-string-all))) | |
555 | ||
12d720fd | 556 | (unless (network-reachable?) (test-skip 1)) |
f9cc8971 LC |
557 | (test-equal "package-source-derivation, snippet" |
558 | "OK" | |
f8ec8d96 | 559 | (let* ((source (bootstrap-origin |
f9cc8971 | 560 | (origin |
f8ec8d96 | 561 | (inherit (bootstrap-guile-origin (%current-system))) |
f9cc8971 LC |
562 | (patch-inputs |
563 | `(("tar" ,%bootstrap-coreutils&co) | |
564 | ("xz" ,%bootstrap-coreutils&co) | |
565 | ("patch" ,%bootstrap-coreutils&co))) | |
7db9608d | 566 | (patch-guile %bootstrap-guile) |
f9cc8971 | 567 | (modules '((guix build utils))) |
f9cc8971 LC |
568 | (snippet '(begin |
569 | ;; We end up in 'bin', because it's the first | |
570 | ;; directory, alphabetically. Not a very good | |
571 | ;; example but hey. | |
572 | (chmod "." #o777) | |
573 | (symlink "guile" "guile-rocks") | |
574 | (copy-recursively "../share/guile/2.0/scripts" | |
d6445dff LC |
575 | "scripts") |
576 | ||
577 | ;; Make sure '.file_list' can be created. | |
578 | (chmod ".." #o777)))))) | |
f9cc8971 LC |
579 | (package (package (inherit (dummy-package "with-snippet")) |
580 | (source source) | |
581 | (build-system trivial-build-system) | |
582 | (inputs | |
583 | `(("tar" ,(search-bootstrap-binary "tar" | |
584 | (%current-system))) | |
585 | ("xz" ,(search-bootstrap-binary "xz" | |
586 | (%current-system))))) | |
587 | (arguments | |
588 | `(#:guile ,%bootstrap-guile | |
1e868858 | 589 | #:modules ((guix build utils)) |
f9cc8971 | 590 | #:builder |
1e868858 MW |
591 | (begin |
592 | (use-modules (guix build utils)) | |
593 | (let ((tar (assoc-ref %build-inputs "tar")) | |
594 | (xz (assoc-ref %build-inputs "xz")) | |
595 | (source (assoc-ref %build-inputs "source"))) | |
596 | (invoke tar "xvf" source | |
597 | "--use-compress-program" xz) | |
598 | (unless (and (string=? "guile" (readlink "bin/guile-rocks")) | |
599 | (file-exists? "bin/scripts/compile.scm")) | |
600 | (error "the snippet apparently failed")) | |
601 | (let ((out (assoc-ref %outputs "out"))) | |
602 | (call-with-output-file out | |
603 | (lambda (p) | |
604 | (display "OK" p)))) | |
605 | #t)))))) | |
f9cc8971 LC |
606 | (drv (package-derivation %store package)) |
607 | (out (derivation->output-path drv))) | |
608 | (and (build-derivations %store (list (pk 'snippet-drv drv))) | |
609 | (call-with-input-file out get-string-all)))) | |
610 | ||
59688fc4 LC |
611 | (test-assert "return value" |
612 | (let ((drv (package-derivation %store (dummy-package "p")))) | |
613 | (and (derivation? drv) | |
614 | (file-exists? (derivation-file-name drv))))) | |
be13fbfa | 615 | |
d510ab46 LC |
616 | (test-assert "package-output" |
617 | (let* ((package (dummy-package "p")) | |
59688fc4 LC |
618 | (drv (package-derivation %store package))) |
619 | (and (derivation? drv) | |
620 | (string=? (derivation->output-path drv) | |
d510ab46 LC |
621 | (package-output %store package "out"))))) |
622 | ||
d51bfe24 LC |
623 | (test-equal "patch not found yields a run-time error" |
624 | '("~a: patch not found\n" "does-not-exist.patch") | |
625 | (guard (c ((formatted-message? c) | |
626 | (cons (formatted-message-string c) | |
627 | (formatted-message-arguments c)))) | |
dbab5150 LC |
628 | (let ((p (package |
629 | (inherit (dummy-package "p")) | |
630 | (source (origin | |
631 | (method (const #f)) | |
632 | (uri "http://whatever") | |
633 | (patches | |
634 | (list (search-patch "does-not-exist.patch"))) | |
635 | (sha256 | |
636 | (base32 | |
637 | "0amn0bbwqvsvvsh6drfwz20ydc2czk374lzw5kksbh6bf78k4ks4"))))))) | |
638 | (package-derivation %store p) | |
639 | #f))) | |
640 | ||
76c48619 LC |
641 | (let ((dummy (dummy-package "foo" (inputs `(("x" ,(current-module))))))) |
642 | (test-equal "&package-input-error" | |
643 | (list dummy (current-module)) | |
644 | (guard (c ((package-input-error? c) | |
645 | (list (package-error-package c) | |
646 | (package-error-invalid-input c)))) | |
647 | (package-derivation %store dummy)))) | |
648 | ||
f304c9c2 LC |
649 | (test-assert "reference to non-existent output" |
650 | ;; See <http://bugs.gnu.org/19630>. | |
862abf8f LC |
651 | (parameterize ((%graft? #f)) |
652 | (let* ((dep (dummy-package "dep")) | |
653 | (p (dummy-package "p" | |
654 | (inputs `(("dep" ,dep "non-existent")))))) | |
655 | (guard (c ((derivation-missing-output-error? c) | |
656 | (and (string=? (derivation-missing-output c) "non-existent") | |
657 | (equal? (package-derivation %store dep) | |
658 | (derivation-error-derivation c))))) | |
659 | (package-derivation %store p))))) | |
f304c9c2 | 660 | |
be13fbfa LC |
661 | (test-assert "trivial" |
662 | (let* ((p (package (inherit (dummy-package "trivial")) | |
663 | (build-system trivial-build-system) | |
664 | (source #f) | |
665 | (arguments | |
14da91e2 LC |
666 | `(#:guile ,%bootstrap-guile |
667 | #:builder | |
be13fbfa LC |
668 | (begin |
669 | (mkdir %output) | |
670 | (call-with-output-file (string-append %output "/test") | |
671 | (lambda (p) | |
1e868858 MW |
672 | (display '(hello guix) p))) |
673 | #t))))) | |
be13fbfa LC |
674 | (d (package-derivation %store p))) |
675 | (and (build-derivations %store (list d)) | |
59688fc4 | 676 | (let ((p (pk 'drv d (derivation->output-path d)))) |
be13fbfa LC |
677 | (equal? '(hello guix) |
678 | (call-with-input-file (string-append p "/test") read)))))) | |
e3ce5d70 | 679 | |
860a6f1a LC |
680 | (test-assert "trivial with local file as input" |
681 | (let* ((i (search-path %load-path "ice-9/boot-9.scm")) | |
682 | (p (package (inherit (dummy-package "trivial-with-input-file")) | |
683 | (build-system trivial-build-system) | |
684 | (source #f) | |
685 | (arguments | |
686 | `(#:guile ,%bootstrap-guile | |
1e868858 MW |
687 | #:builder (begin |
688 | (copy-file (assoc-ref %build-inputs "input") | |
689 | %output) | |
690 | #t))) | |
860a6f1a LC |
691 | (inputs `(("input" ,i))))) |
692 | (d (package-derivation %store p))) | |
693 | (and (build-derivations %store (list d)) | |
59688fc4 | 694 | (let ((p (pk 'drv d (derivation->output-path d)))) |
860a6f1a LC |
695 | (equal? (call-with-input-file p get-bytevector-all) |
696 | (call-with-input-file i get-bytevector-all)))))) | |
697 | ||
03761a44 LC |
698 | (test-assert "trivial with source" |
699 | (let* ((i (search-path %load-path "ice-9/boot-9.scm")) | |
700 | (p (package (inherit (dummy-package "trivial-with-source")) | |
701 | (build-system trivial-build-system) | |
702 | (source i) | |
703 | (arguments | |
704 | `(#:guile ,%bootstrap-guile | |
1e868858 MW |
705 | #:builder (begin |
706 | (copy-file (assoc-ref %build-inputs "source") | |
707 | %output) | |
708 | #t))))) | |
03761a44 LC |
709 | (d (package-derivation %store p))) |
710 | (and (build-derivations %store (list d)) | |
711 | (let ((p (derivation->output-path d))) | |
712 | (equal? (call-with-input-file p get-bytevector-all) | |
713 | (call-with-input-file i get-bytevector-all)))))) | |
714 | ||
592ef6c8 LC |
715 | (test-assert "trivial with system-dependent input" |
716 | (let* ((p (package (inherit (dummy-package "trivial-system-dependent-input")) | |
717 | (build-system trivial-build-system) | |
718 | (source #f) | |
719 | (arguments | |
720 | `(#:guile ,%bootstrap-guile | |
1e868858 | 721 | #:modules ((guix build utils)) |
592ef6c8 | 722 | #:builder |
1e868858 MW |
723 | (begin |
724 | (use-modules (guix build utils)) | |
725 | (let ((out (assoc-ref %outputs "out")) | |
726 | (bash (assoc-ref %build-inputs "bash"))) | |
727 | (invoke bash "-c" | |
728 | (format #f "echo hello > ~a" out)))))) | |
dd6b9a37 LC |
729 | (inputs `(("bash" ,(search-bootstrap-binary "bash" |
730 | (%current-system))))))) | |
592ef6c8 LC |
731 | (d (package-derivation %store p))) |
732 | (and (build-derivations %store (list d)) | |
59688fc4 | 733 | (let ((p (pk 'drv d (derivation->output-path d)))) |
592ef6c8 LC |
734 | (eq? 'hello (call-with-input-file p read)))))) |
735 | ||
29760251 LC |
736 | (test-assert "trivial with #:allowed-references" |
737 | (let* ((p (package | |
738 | (inherit (dummy-package "trivial")) | |
739 | (build-system trivial-build-system) | |
740 | (arguments | |
741 | `(#:guile ,%bootstrap-guile | |
742 | #:allowed-references (,%bootstrap-guile) | |
743 | #:builder | |
744 | (begin | |
745 | (mkdir %output) | |
746 | ;; The reference to itself isn't allowed so building it | |
747 | ;; should fail. | |
1e868858 MW |
748 | (symlink %output (string-append %output "/self")) |
749 | #t))))) | |
29760251 | 750 | (d (package-derivation %store p))) |
f9e8a123 | 751 | (guard (c ((store-protocol-error? c) #t)) |
29760251 LC |
752 | (build-derivations %store (list d)) |
753 | #f))) | |
754 | ||
a18eda27 LC |
755 | (test-assert "search paths" |
756 | (let* ((p (make-prompt-tag "return-search-paths")) | |
757 | (s (build-system | |
0d5a559f | 758 | (name 'raw) |
a18eda27 | 759 | (description "Raw build system with direct store access") |
d3d337d2 LC |
760 | (lower (lambda* (name #:key source inputs system target |
761 | #:allow-other-keys) | |
0d5a559f LC |
762 | (bag |
763 | (name name) | |
d3d337d2 | 764 | (system system) (target target) |
0d5a559f LC |
765 | (build-inputs inputs) |
766 | (build | |
767 | (lambda* (store name inputs | |
768 | #:key outputs system search-paths) | |
769 | search-paths))))))) | |
a18eda27 LC |
770 | (x (list (search-path-specification |
771 | (variable "GUILE_LOAD_PATH") | |
af070955 | 772 | (files '("share/guile/site/2.0"))) |
a18eda27 LC |
773 | (search-path-specification |
774 | (variable "GUILE_LOAD_COMPILED_PATH") | |
af070955 | 775 | (files '("share/guile/site/2.0"))))) |
a18eda27 LC |
776 | (a (package (inherit (dummy-package "guile")) |
777 | (build-system s) | |
778 | (native-search-paths x))) | |
779 | (b (package (inherit (dummy-package "guile-foo")) | |
780 | (build-system s) | |
781 | (inputs `(("guile" ,a))))) | |
782 | (c (package (inherit (dummy-package "guile-bar")) | |
783 | (build-system s) | |
784 | (inputs `(("guile" ,a) | |
785 | ("guile-foo" ,b)))))) | |
786 | (let-syntax ((collect (syntax-rules () | |
787 | ((_ body ...) | |
788 | (call-with-prompt p | |
789 | (lambda () | |
790 | body ...) | |
791 | (lambda (k search-paths) | |
792 | search-paths)))))) | |
793 | (and (null? (collect (package-derivation %store a))) | |
794 | (equal? x (collect (package-derivation %store b))) | |
795 | (equal? x (collect (package-derivation %store c))))))) | |
796 | ||
aa8e0515 LC |
797 | (test-assert "package-transitive-native-search-paths" |
798 | (let* ((sp (lambda (name) | |
799 | (list (search-path-specification | |
800 | (variable name) | |
801 | (files '("foo/bar")))))) | |
802 | (p0 (dummy-package "p0" (native-search-paths (sp "PATH0")))) | |
803 | (p1 (dummy-package "p1" (native-search-paths (sp "PATH1")))) | |
804 | (p2 (dummy-package "p2" | |
805 | (native-search-paths (sp "PATH2")) | |
806 | (inputs `(("p0" ,p0))) | |
807 | (propagated-inputs `(("p1" ,p1))))) | |
808 | (p3 (dummy-package "p3" | |
809 | (native-search-paths (sp "PATH3")) | |
810 | (native-inputs `(("p0" ,p0))) | |
811 | (propagated-inputs `(("p2" ,p2)))))) | |
812 | (lset= string=? | |
813 | '("PATH1" "PATH2" "PATH3") | |
814 | (map search-path-specification-variable | |
815 | (package-transitive-native-search-paths p3))))) | |
816 | ||
9c1edabd | 817 | (test-assert "package-cross-derivation" |
59688fc4 LC |
818 | (let ((drv (package-cross-derivation %store (dummy-package "p") |
819 | "mips64el-linux-gnu"))) | |
820 | (and (derivation? drv) | |
821 | (file-exists? (derivation-file-name drv))))) | |
9c1edabd | 822 | |
5dce8218 LC |
823 | (test-assert "package-cross-derivation, trivial-build-system" |
824 | (let ((p (package (inherit (dummy-package "p")) | |
825 | (build-system trivial-build-system) | |
826 | (arguments '(#:builder (exit 1)))))) | |
59688fc4 LC |
827 | (let ((drv (package-cross-derivation %store p "mips64el-linux-gnu"))) |
828 | (derivation? drv)))) | |
5dce8218 | 829 | |
9b222abe LC |
830 | (test-assert "package-cross-derivation, no cross builder" |
831 | (let* ((b (build-system (inherit trivial-build-system) | |
0d5a559f | 832 | (lower (const #f)))) |
9b222abe LC |
833 | (p (package (inherit (dummy-package "p")) |
834 | (build-system b)))) | |
835 | (guard (c ((package-cross-build-system-error? c) | |
836 | (eq? (package-error-package c) p))) | |
837 | (package-cross-derivation %store p "mips64el-linux-gnu") | |
838 | #f))) | |
839 | ||
b4c42a4b LC |
840 | ;; XXX: The next two tests can trigger builds when the distro defines |
841 | ;; replacements on core packages, so they're disable for lack of a better | |
842 | ;; solution. | |
843 | ||
844 | ;; (test-equal "package-derivation, direct graft" | |
845 | ;; (package-derivation %store gnu-make #:graft? #f) | |
846 | ;; (let ((p (package (inherit coreutils) | |
847 | ;; (replacement gnu-make)))) | |
848 | ;; (package-derivation %store p #:graft? #t))) | |
05962f29 | 849 | |
b4c42a4b LC |
850 | ;; (test-equal "package-cross-derivation, direct graft" |
851 | ;; (package-cross-derivation %store gnu-make "mips64el-linux-gnu" | |
852 | ;; #:graft? #f) | |
853 | ;; (let ((p (package (inherit coreutils) | |
854 | ;; (replacement gnu-make)))) | |
855 | ;; (package-cross-derivation %store p "mips64el-linux-gnu" | |
856 | ;; #:graft? #t))) | |
05962f29 LC |
857 | |
858 | (test-assert "package-grafts, indirect grafts" | |
859 | (let* ((new (dummy-package "dep" | |
860 | (arguments '(#:implicit-inputs? #f)))) | |
861 | (dep (package (inherit new) (version "0.0"))) | |
862 | (dep* (package (inherit dep) (replacement new))) | |
863 | (dummy (dummy-package "dummy" | |
864 | (arguments '(#:implicit-inputs? #f)) | |
865 | (inputs `(("dep" ,dep*)))))) | |
866 | (equal? (package-grafts %store dummy) | |
867 | (list (graft | |
868 | (origin (package-derivation %store dep)) | |
869 | (replacement (package-derivation %store new))))))) | |
870 | ||
d0025d01 LC |
871 | ;; XXX: This test would require building the cross toolchain just to see if it |
872 | ;; needs grafting, which is obviously too expensive, and thus disabled. | |
873 | ;; | |
874 | ;; (test-assert "package-grafts, indirect grafts, cross" | |
875 | ;; (let* ((new (dummy-package "dep" | |
876 | ;; (arguments '(#:implicit-inputs? #f)))) | |
877 | ;; (dep (package (inherit new) (version "0.0"))) | |
878 | ;; (dep* (package (inherit dep) (replacement new))) | |
879 | ;; (dummy (dummy-package "dummy" | |
880 | ;; (arguments '(#:implicit-inputs? #f)) | |
881 | ;; (inputs `(("dep" ,dep*))))) | |
882 | ;; (target "mips64el-linux-gnu")) | |
883 | ;; ;; XXX: There might be additional grafts, for instance if the distro | |
884 | ;; ;; defines replacements for core packages like Perl. | |
885 | ;; (member (graft | |
886 | ;; (origin (package-cross-derivation %store dep target)) | |
887 | ;; (replacement | |
888 | ;; (package-cross-derivation %store new target))) | |
889 | ;; (package-grafts %store dummy #:target target)))) | |
05962f29 LC |
890 | |
891 | (test-assert "package-grafts, indirect grafts, propagated inputs" | |
892 | (let* ((new (dummy-package "dep" | |
893 | (arguments '(#:implicit-inputs? #f)))) | |
894 | (dep (package (inherit new) (version "0.0"))) | |
895 | (dep* (package (inherit dep) (replacement new))) | |
896 | (prop (dummy-package "propagated" | |
897 | (propagated-inputs `(("dep" ,dep*))) | |
898 | (arguments '(#:implicit-inputs? #f)))) | |
899 | (dummy (dummy-package "dummy" | |
900 | (arguments '(#:implicit-inputs? #f)) | |
901 | (inputs `(("prop" ,prop)))))) | |
902 | (equal? (package-grafts %store dummy) | |
903 | (list (graft | |
904 | (origin (package-derivation %store dep)) | |
905 | (replacement (package-derivation %store new))))))) | |
906 | ||
fcadd9ff LC |
907 | (test-assert "package-grafts, same replacement twice" |
908 | (let* ((new (dummy-package "dep" | |
909 | (version "1") | |
910 | (arguments '(#:implicit-inputs? #f)))) | |
911 | (dep (package (inherit new) (version "0") (replacement new))) | |
912 | (p1 (dummy-package "intermediate1" | |
913 | (arguments '(#:implicit-inputs? #f)) | |
914 | (inputs `(("dep" ,dep))))) | |
915 | (p2 (dummy-package "intermediate2" | |
916 | (arguments '(#:implicit-inputs? #f)) | |
917 | ;; Here we copy DEP to have an equivalent package that is not | |
918 | ;; 'eq?' to DEP. This is similar to what happens with | |
919 | ;; 'package-with-explicit-inputs' & co. | |
920 | (inputs `(("dep" ,(package (inherit dep))))))) | |
921 | (p3 (dummy-package "final" | |
922 | (arguments '(#:implicit-inputs? #f)) | |
923 | (inputs `(("p1" ,p1) ("p2" ,p2)))))) | |
924 | (equal? (package-grafts %store p3) | |
925 | (list (graft | |
926 | (origin (package-derivation %store | |
927 | (package (inherit dep) | |
928 | (replacement #f)))) | |
929 | (replacement (package-derivation %store new))))))) | |
930 | ||
03a70e4c LC |
931 | (test-assert "package-grafts, dependency on several outputs" |
932 | ;; Make sure we get one graft per output; see <https://bugs.gnu.org/41796>. | |
933 | (letrec* ((p0 (dummy-package "p0" | |
934 | (version "1.0") | |
935 | (replacement p0*) | |
936 | (arguments '(#:implicit-inputs? #f)) | |
937 | (outputs '("out" "lib")))) | |
938 | (p0* (package (inherit p0) (version "1.1"))) | |
939 | (p1 (dummy-package "p1" | |
940 | (arguments '(#:implicit-inputs? #f)) | |
941 | (inputs `(("p0" ,p0) | |
942 | ("p0:lib" ,p0 "lib")))))) | |
943 | (lset= equal? (pk (package-grafts %store p1)) | |
944 | (list (graft | |
945 | (origin (package-derivation %store p0)) | |
946 | (origin-output "out") | |
947 | (replacement (package-derivation %store p0*)) | |
948 | (replacement-output "out")) | |
949 | (graft | |
950 | (origin (package-derivation %store p0)) | |
951 | (origin-output "lib") | |
952 | (replacement (package-derivation %store p0*)) | |
953 | (replacement-output "lib")))))) | |
954 | ||
d0025d01 LC |
955 | (test-assert "replacement also grafted" |
956 | ;; We build a DAG as below, where dotted arrows represent replacements and | |
957 | ;; solid arrows represent dependencies: | |
958 | ;; | |
959 | ;; P1 ·············> P1R | |
960 | ;; |\__________________. | |
961 | ;; v v | |
962 | ;; P2 ·············> P2R | |
963 | ;; | | |
964 | ;; v | |
965 | ;; P3 | |
966 | ;; | |
967 | ;; We want to make sure that: | |
968 | ;; grafts(P3) = (P1,P1R) + (P2, grafted(P2R, (P1,P1R))) | |
969 | ;; where: | |
970 | ;; (A,B) is a graft to replace A by B | |
971 | ;; grafted(DRV,G) denoted DRV with graft G applied | |
972 | (let* ((p1r (dummy-package "P1" | |
973 | (build-system trivial-build-system) | |
974 | (arguments | |
975 | `(#:guile ,%bootstrap-guile | |
976 | #:builder (let ((out (assoc-ref %outputs "out"))) | |
977 | (mkdir out) | |
978 | (call-with-output-file | |
979 | (string-append out "/replacement") | |
980 | (const #t))))))) | |
981 | (p1 (package | |
982 | (inherit p1r) (name "p1") (replacement p1r) | |
983 | (arguments | |
984 | `(#:guile ,%bootstrap-guile | |
1e868858 MW |
985 | #:builder (begin |
986 | (mkdir (assoc-ref %outputs "out")) | |
987 | #t))))) | |
d0025d01 LC |
988 | (p2r (dummy-package "P2" |
989 | (build-system trivial-build-system) | |
990 | (inputs `(("p1" ,p1))) | |
991 | (arguments | |
992 | `(#:guile ,%bootstrap-guile | |
993 | #:builder (let ((out (assoc-ref %outputs "out"))) | |
994 | (mkdir out) | |
995 | (chdir out) | |
996 | (symlink (assoc-ref %build-inputs "p1") "p1") | |
997 | (call-with-output-file (string-append out "/replacement") | |
998 | (const #t))))))) | |
999 | (p2 (package | |
1000 | (inherit p2r) (name "p2") (replacement p2r) | |
1001 | (arguments | |
1002 | `(#:guile ,%bootstrap-guile | |
1003 | #:builder (let ((out (assoc-ref %outputs "out"))) | |
1004 | (mkdir out) | |
1005 | (chdir out) | |
1006 | (symlink (assoc-ref %build-inputs "p1") | |
1e868858 MW |
1007 | "p1") |
1008 | #t))))) | |
d0025d01 LC |
1009 | (p3 (dummy-package "p3" |
1010 | (build-system trivial-build-system) | |
1011 | (inputs `(("p2" ,p2))) | |
1012 | (arguments | |
1013 | `(#:guile ,%bootstrap-guile | |
1014 | #:builder (let ((out (assoc-ref %outputs "out"))) | |
1015 | (mkdir out) | |
1016 | (chdir out) | |
1017 | (symlink (assoc-ref %build-inputs "p2") | |
1e868858 MW |
1018 | "p2") |
1019 | #t)))))) | |
d0025d01 LC |
1020 | (lset= equal? |
1021 | (package-grafts %store p3) | |
1022 | (list (graft | |
1023 | (origin (package-derivation %store p1 #:graft? #f)) | |
1024 | (replacement (package-derivation %store p1r))) | |
1025 | (graft | |
1026 | (origin (package-derivation %store p2 #:graft? #f)) | |
1027 | (replacement | |
1028 | (package-derivation %store p2r #:graft? #t))))))) | |
1029 | ||
c22a1324 LC |
1030 | ;;; XXX: Nowadays 'graft-derivation' needs to build derivations beforehand to |
1031 | ;;; find out about their run-time dependencies, so this test is no longer | |
1032 | ;;; applicable since it would trigger a full rebuild. | |
1033 | ;; | |
1034 | ;; (test-assert "package-derivation, indirect grafts" | |
1035 | ;; (let* ((new (dummy-package "dep" | |
1036 | ;; (arguments '(#:implicit-inputs? #f)))) | |
1037 | ;; (dep (package (inherit new) (version "0.0"))) | |
1038 | ;; (dep* (package (inherit dep) (replacement new))) | |
1039 | ;; (dummy (dummy-package "dummy" | |
1040 | ;; (arguments '(#:implicit-inputs? #f)) | |
1041 | ;; (inputs `(("dep" ,dep*))))) | |
1042 | ;; (guile (package-derivation %store (canonical-package guile-2.0) | |
1043 | ;; #:graft? #f))) | |
1044 | ;; (equal? (package-derivation %store dummy) | |
1045 | ;; (graft-derivation %store | |
1046 | ;; (package-derivation %store dummy #:graft? #f) | |
1047 | ;; (package-grafts %store dummy) | |
1048 | ||
1049 | ;; ;; Use the same Guile as 'package-derivation'. | |
1050 | ;; #:guile guile)))) | |
05962f29 | 1051 | |
d3d337d2 LC |
1052 | (test-equal "package->bag" |
1053 | `("foo86-hurd" #f (,(package-source gnu-make)) | |
1054 | (,(canonical-package glibc)) (,(canonical-package coreutils))) | |
1055 | (let ((bag (package->bag gnu-make "foo86-hurd"))) | |
1056 | (list (bag-system bag) (bag-target bag) | |
1057 | (assoc-ref (bag-build-inputs bag) "source") | |
1058 | (assoc-ref (bag-build-inputs bag) "libc") | |
1059 | (assoc-ref (bag-build-inputs bag) "coreutils")))) | |
1060 | ||
b49caaa2 LC |
1061 | (test-assert "package->bag, sensitivity to %current-target-system" |
1062 | ;; https://bugs.gnu.org/41713 | |
1063 | (let* ((lower (lambda* (name #:key system target inputs native-inputs | |
1064 | #:allow-other-keys) | |
1065 | (and (not target) | |
1066 | (bag (name name) (system system) (target target) | |
1067 | (build-inputs native-inputs) | |
1068 | (host-inputs inputs) | |
1069 | (build (lambda* (store name inputs | |
1070 | #:key system target | |
1071 | #:allow-other-keys) | |
1072 | (build-expression->derivation | |
1073 | store "foo" '(mkdir %output)))))))) | |
1074 | (bs (build-system | |
1075 | (name 'build-system-without-cross-compilation) | |
1076 | (description "Does not support cross compilation.") | |
1077 | (lower lower))) | |
1078 | (dep (dummy-package "dep" (build-system bs))) | |
1079 | (pkg (dummy-package "example" | |
1080 | (native-inputs `(("dep" ,dep))))) | |
1081 | (do-not-build (lambda (continue store lst . _) lst))) | |
1082 | (equal? (with-build-handler do-not-build | |
1083 | (parameterize ((%current-target-system "powerpc64le-linux-gnu") | |
1084 | (%graft? #t)) | |
1085 | (package-cross-derivation %store pkg | |
1086 | (%current-target-system) | |
1087 | #:graft? #t))) | |
1088 | (with-build-handler do-not-build | |
1089 | (package-cross-derivation %store | |
1090 | (package (inherit pkg)) | |
1091 | "powerpc64le-linux-gnu" | |
1092 | #:graft? #t))))) | |
1093 | ||
d3d337d2 LC |
1094 | (test-equal "package->bag, cross-compilation" |
1095 | `(,(%current-system) "foo86-hurd" | |
1096 | (,(package-source gnu-make)) | |
1097 | (,(canonical-package glibc)) (,(canonical-package coreutils))) | |
1098 | (let ((bag (package->bag gnu-make (%current-system) "foo86-hurd"))) | |
1099 | (list (bag-system bag) (bag-target bag) | |
1100 | (assoc-ref (bag-build-inputs bag) "source") | |
1101 | (assoc-ref (bag-build-inputs bag) "libc") | |
1102 | (assoc-ref (bag-build-inputs bag) "coreutils")))) | |
1103 | ||
50373bab LC |
1104 | (test-assert "package->bag, propagated inputs" |
1105 | (let* ((dep (dummy-package "dep")) | |
1106 | (prop (dummy-package "prop" | |
1107 | (propagated-inputs `(("dep" ,dep))))) | |
1108 | (dummy (dummy-package "dummy" | |
1109 | (inputs `(("prop" ,prop))))) | |
1110 | (inputs (bag-transitive-inputs (package->bag dummy #:graft? #f)))) | |
161094c8 LC |
1111 | (match (assoc "dep" inputs) |
1112 | (("dep" package) | |
50373bab LC |
1113 | (eq? package dep))))) |
1114 | ||
efb10f17 LC |
1115 | (test-assert "package->bag, sensitivity to %current-system" |
1116 | (let* ((dep (dummy-package "dep" | |
1117 | (propagated-inputs (if (string=? (%current-system) | |
1118 | "i586-gnu") | |
1119 | `(("libxml2" ,libxml2)) | |
1120 | '())))) | |
1121 | (pkg (dummy-package "foo" | |
1122 | (native-inputs `(("dep" ,dep))))) | |
1123 | (bag (package->bag pkg (%current-system) "i586-gnu"))) | |
1124 | (equal? (parameterize ((%current-system "x86_64-linux")) | |
1125 | (bag-transitive-inputs bag)) | |
1126 | (parameterize ((%current-system "i586-gnu")) | |
1127 | (bag-transitive-inputs bag))))) | |
1128 | ||
f52fbf70 LC |
1129 | (test-assert "package->bag, sensitivity to %current-target-system" |
1130 | (let* ((dep (dummy-package "dep" | |
1131 | (propagated-inputs (if (%current-target-system) | |
1132 | `(("libxml2" ,libxml2)) | |
1133 | '())))) | |
1134 | (pkg (dummy-package "foo" | |
1135 | (native-inputs `(("dep" ,dep))))) | |
1136 | (bag (package->bag pkg (%current-system) "foo86-hurd"))) | |
1137 | (equal? (parameterize ((%current-target-system "foo64-gnu")) | |
1138 | (bag-transitive-inputs bag)) | |
1139 | (parameterize ((%current-target-system #f)) | |
1140 | (bag-transitive-inputs bag))))) | |
1141 | ||
d3d337d2 | 1142 | (test-assert "bag->derivation" |
05962f29 LC |
1143 | (parameterize ((%graft? #f)) |
1144 | (let ((bag (package->bag gnu-make)) | |
1145 | (drv (package-derivation %store gnu-make))) | |
1146 | (parameterize ((%current-system "foox86-hurd")) ;should have no effect | |
1147 | (equal? drv (bag->derivation %store bag)))))) | |
d3d337d2 LC |
1148 | |
1149 | (test-assert "bag->derivation, cross-compilation" | |
05962f29 LC |
1150 | (parameterize ((%graft? #f)) |
1151 | (let* ((target "mips64el-linux-gnu") | |
1152 | (bag (package->bag gnu-make (%current-system) target)) | |
1153 | (drv (package-cross-derivation %store gnu-make target))) | |
1154 | (parameterize ((%current-system "foox86-hurd") ;should have no effect | |
1155 | (%current-target-system "foo64-linux-gnu")) | |
1156 | (equal? drv (bag->derivation %store bag)))))) | |
d3d337d2 | 1157 | |
b69c5c2c LC |
1158 | (when (or (not (network-reachable?)) (shebang-too-long?)) |
1159 | (test-skip 1)) | |
9e782349 | 1160 | (test-assert "GNU Make, bootstrap" |
03d76577 LC |
1161 | ;; GNU-MAKE-FOR-TESTS can be built cheaply; we choose it here so that the |
1162 | ;; test doesn't last for too long. | |
1163 | (let ((gnu-make gnu-make-for-tests)) | |
9e782349 LC |
1164 | (and (package? gnu-make) |
1165 | (or (location? (package-location gnu-make)) | |
1166 | (not (package-location gnu-make))) | |
1167 | (let* ((drv (package-derivation %store gnu-make)) | |
59688fc4 | 1168 | (out (derivation->output-path drv))) |
14da91e2 | 1169 | (and (build-derivations %store (list drv)) |
9e782349 | 1170 | (file-exists? (string-append out "/bin/make"))))))) |
e3ce5d70 | 1171 | |
f37f2b83 LC |
1172 | (test-equal "package-mapping" |
1173 | 42 | |
1174 | (let* ((dep (dummy-package "chbouib" | |
1175 | (native-inputs `(("x" ,grep))))) | |
1176 | (p0 (dummy-package "example" | |
ff39361c | 1177 | (source 77) |
f37f2b83 LC |
1178 | (inputs `(("foo" ,coreutils) |
1179 | ("bar" ,grep) | |
1180 | ("baz" ,dep))))) | |
1181 | (transform (lambda (p) | |
1182 | (package (inherit p) (source 42)))) | |
1183 | (rewrite (package-mapping transform)) | |
ff39361c LC |
1184 | (p1 (rewrite p0)) |
1185 | (bag0 (package->bag p0)) | |
1186 | (bag1 (package->bag p1))) | |
f37f2b83 LC |
1187 | (and (eq? p1 (rewrite p0)) |
1188 | (eqv? 42 (package-source p1)) | |
ff39361c LC |
1189 | |
1190 | ;; Implicit inputs should be left unchanged (skip "source", "foo", | |
1191 | ;; "bar", and "baz" in this comparison). | |
1192 | (equal? (drop (bag-direct-inputs bag0) 4) | |
1193 | (drop (bag-direct-inputs bag1) 4)) | |
1194 | ||
f37f2b83 LC |
1195 | (match (package-inputs p1) |
1196 | ((("foo" dep1) ("bar" dep2) ("baz" dep3)) | |
1197 | (and (eq? dep1 (rewrite coreutils)) ;memoization | |
1198 | (eq? dep2 (rewrite grep)) | |
1199 | (eq? dep3 (rewrite dep)) | |
1200 | (eqv? 42 | |
1201 | (package-source dep1) (package-source dep2) | |
1202 | (package-source dep3)) | |
1203 | (match (package-native-inputs dep3) | |
1204 | ((("x" dep)) | |
1205 | (and (eq? dep (rewrite grep)) | |
1206 | (package-source dep)))))))))) | |
1207 | ||
ff39361c LC |
1208 | (test-equal "package-mapping, deep" |
1209 | '(42) | |
1210 | (let* ((p0 (dummy-package "example" | |
1211 | (inputs `(("foo" ,coreutils) | |
1212 | ("bar" ,grep))))) | |
1213 | (transform (lambda (p) | |
1214 | (package (inherit p) (source 42)))) | |
1215 | (rewrite (package-mapping transform #:deep? #t)) | |
1216 | (p1 (rewrite p0)) | |
1217 | (bag (package->bag p1))) | |
1218 | (and (eq? p1 (rewrite p0)) | |
1219 | (match (bag-direct-inputs bag) | |
1220 | ((("source" 42) ("foo" dep1) ("bar" dep2) rest ..1) | |
1221 | (and (eq? dep1 (rewrite coreutils)) ;memoization | |
1222 | (eq? dep2 (rewrite grep)) | |
1223 | (= 42 (package-source dep1)) | |
1224 | (= 42 (package-source dep2)) | |
1225 | ||
1226 | ;; Check that implicit inputs of P0 also got rewritten. | |
1227 | (delete-duplicates | |
1228 | (map (match-lambda | |
1229 | ((_ package . _) | |
1230 | (package-source package))) | |
1231 | rest)))))))) | |
1232 | ||
2a75b0b6 LC |
1233 | (test-assert "package-input-rewriting" |
1234 | (let* ((dep (dummy-package "chbouib" | |
1235 | (native-inputs `(("x" ,grep))))) | |
1236 | (p0 (dummy-package "example" | |
1237 | (inputs `(("foo" ,coreutils) | |
1238 | ("bar" ,grep) | |
1239 | ("baz" ,dep))))) | |
1240 | (rewrite (package-input-rewriting `((,coreutils . ,sed) | |
1241 | (,grep . ,findutils)) | |
1242 | (cut string-append "r-" <>))) | |
1243 | (p1 (rewrite p0)) | |
1244 | (p2 (rewrite p0))) | |
1245 | (and (not (eq? p1 p0)) | |
1246 | (eq? p1 p2) ;memoization | |
1247 | (string=? "r-example" (package-name p1)) | |
1248 | (match (package-inputs p1) | |
1249 | ((("foo" dep1) ("bar" dep2) ("baz" dep3)) | |
1250 | (and (eq? dep1 sed) | |
1251 | (eq? dep2 findutils) | |
1252 | (string=? (package-name dep3) "r-chbouib") | |
1253 | (eq? dep3 (rewrite dep)) ;memoization | |
1254 | (match (package-native-inputs dep3) | |
1255 | ((("x" dep)) | |
1256 | (eq? dep findutils))))))))) | |
1257 | ||
f258d886 LC |
1258 | (test-assert "package-input-rewriting/spec" |
1259 | (let* ((dep (dummy-package "chbouib" | |
1260 | (native-inputs `(("x" ,grep))))) | |
1261 | (p0 (dummy-package "example" | |
1262 | (inputs `(("foo" ,coreutils) | |
1263 | ("bar" ,grep) | |
1264 | ("baz" ,dep))))) | |
1265 | (rewrite (package-input-rewriting/spec | |
1266 | `(("coreutils" . ,(const sed)) | |
2bf6f962 LC |
1267 | ("grep" . ,(const findutils))) |
1268 | #:deep? #f)) | |
f258d886 LC |
1269 | (p1 (rewrite p0)) |
1270 | (p2 (rewrite p0))) | |
1271 | (and (not (eq? p1 p0)) | |
1272 | (eq? p1 p2) ;memoization | |
1273 | (string=? "example" (package-name p1)) | |
1274 | (match (package-inputs p1) | |
1275 | ((("foo" dep1) ("bar" dep2) ("baz" dep3)) | |
1276 | (and (string=? (package-full-name dep1) | |
1277 | (package-full-name sed)) | |
1278 | (string=? (package-full-name dep2) | |
1279 | (package-full-name findutils)) | |
1280 | (string=? (package-name dep3) "chbouib") | |
1281 | (eq? dep3 (rewrite dep)) ;memoization | |
1282 | (match (package-native-inputs dep3) | |
1283 | ((("x" dep)) | |
1284 | (string=? (package-full-name dep) | |
2bf6f962 LC |
1285 | (package-full-name findutils))))))) |
1286 | ||
1287 | ;; Make sure implicit inputs were left unchanged. | |
1288 | (equal? (drop (bag-direct-inputs (package->bag p1)) 3) | |
1289 | (drop (bag-direct-inputs (package->bag p0)) 3))))) | |
f258d886 LC |
1290 | |
1291 | (test-assert "package-input-rewriting/spec, partial match" | |
1292 | (let* ((dep (dummy-package "chbouib" | |
1293 | (version "1") | |
1294 | (native-inputs `(("x" ,grep))))) | |
1295 | (p0 (dummy-package "example" | |
1296 | (inputs `(("foo" ,coreutils) | |
1297 | ("bar" ,dep))))) | |
1298 | (rewrite (package-input-rewriting/spec | |
1299 | `(("chbouib@123" . ,(const sed)) ;not matched | |
2bf6f962 LC |
1300 | ("grep" . ,(const findutils))) |
1301 | #:deep? #f)) | |
f258d886 LC |
1302 | (p1 (rewrite p0))) |
1303 | (and (not (eq? p1 p0)) | |
1304 | (string=? "example" (package-name p1)) | |
1305 | (match (package-inputs p1) | |
1306 | ((("foo" dep1) ("bar" dep2)) | |
1307 | (and (string=? (package-full-name dep1) | |
1308 | (package-full-name coreutils)) | |
1309 | (eq? dep2 (rewrite dep)) ;memoization | |
1310 | (match (package-native-inputs dep2) | |
1311 | ((("x" dep)) | |
1312 | (string=? (package-full-name dep) | |
1313 | (package-full-name findutils)))))))))) | |
1314 | ||
2bf6f962 LC |
1315 | (test-assert "package-input-rewriting/spec, deep" |
1316 | (let* ((dep (dummy-package "chbouib")) | |
1317 | (p0 (dummy-package "example" | |
1318 | (build-system gnu-build-system) | |
1319 | (inputs `(("dep" ,dep))))) | |
1320 | (rewrite (package-input-rewriting/spec | |
1321 | `(("tar" . ,(const sed)) | |
1322 | ("gzip" . ,(const findutils))))) | |
1323 | (p1 (rewrite p0)) | |
1324 | (p2 (rewrite p0))) | |
1325 | (and (not (eq? p1 p0)) | |
1326 | (eq? p1 p2) ;memoization | |
1327 | (string=? "example" (package-name p1)) | |
1328 | (match (package-inputs p1) | |
1329 | ((("dep" dep1)) | |
1330 | (and (string=? (package-full-name dep1) | |
1331 | (package-full-name dep)) | |
1332 | (eq? dep1 (rewrite dep))))) ;memoization | |
1333 | ||
1334 | ;; Make sure implicit inputs were replaced. | |
1335 | (match (bag-direct-inputs (package->bag p1)) | |
1336 | ((("dep" dep1) ("tar" tar) ("gzip" gzip) _ ...) | |
1337 | (and (eq? dep1 (rewrite dep)) | |
1338 | (string=? (package-full-name tar) | |
1339 | (package-full-name sed)) | |
1340 | (string=? (package-full-name gzip) | |
1341 | (package-full-name findutils)))))))) | |
1342 | ||
1343 | (test-assert "package-input-rewriting/spec, no duplicates" | |
1344 | ;; Ensure that deep input rewriting does not forget implicit inputs. Doing | |
1345 | ;; so could lead to duplicates in a package's inputs: in the example below, | |
1346 | ;; P0's transitive inputs would contain one rewritten "python" and one | |
1347 | ;; original "python". These two "python" packages are thus not 'eq?' but | |
1348 | ;; they lower to the same derivation. See <https://bugs.gnu.org/42156>, | |
1349 | ;; which can be reproduced by passing #:deep? #f. | |
1350 | (let* ((dep0 (dummy-package "dep0" | |
1351 | (build-system trivial-build-system) | |
1352 | (propagated-inputs `(("python" ,python))))) | |
1353 | (p0 (dummy-package "chbouib" | |
1354 | (build-system python-build-system) | |
1355 | (arguments `(#:python ,python)) | |
1356 | (inputs `(("dep0" ,dep0))))) | |
1357 | (rewrite (package-input-rewriting/spec '() #:deep? #t)) | |
1358 | (p1 (rewrite p0)) | |
1359 | (bag1 (package->bag p1)) | |
1360 | (pythons (filter-map (match-lambda | |
1361 | (("python" python) python) | |
1362 | (_ #f)) | |
1363 | (bag-transitive-inputs bag1)))) | |
1364 | (match (delete-duplicates pythons eq?) | |
1365 | ((p) (eq? p (rewrite python)))))) | |
1366 | ||
c423ae89 LC |
1367 | (test-equal "package-patched-vulnerabilities" |
1368 | '(("CVE-2015-1234") | |
1369 | ("CVE-2016-1234" "CVE-2018-4567") | |
1370 | ()) | |
1371 | (let ((p1 (dummy-package "pi" | |
1372 | (source (dummy-origin | |
1373 | (patches (list "/a/b/pi-CVE-2015-1234.patch")))))) | |
1374 | (p2 (dummy-package "pi" | |
1375 | (source (dummy-origin | |
1376 | (patches (list | |
1377 | "/a/b/pi-CVE-2016-1234-CVE-2018-4567.patch")))))) | |
1378 | (p3 (dummy-package "pi" (source (dummy-origin))))) | |
1379 | (map package-patched-vulnerabilities | |
1380 | (list p1 p2 p3)))) | |
1381 | ||
ba326ce4 LC |
1382 | (test-eq "fold-packages" hello |
1383 | (fold-packages (lambda (p r) | |
1384 | (if (string=? (package-name p) "hello") | |
1385 | p | |
1386 | r)) | |
1387 | #f)) | |
1388 | ||
386b71d1 LC |
1389 | (test-assert "fold-packages, hidden package" |
1390 | ;; There are two public variables providing "guile@2.0" ('guile-final' in | |
b66d6d52 | 1391 | ;; commencement.scm and 'guile-2.0' in guile.scm), but only the latter |
386b71d1 LC |
1392 | ;; should show up. |
1393 | (match (fold-packages (lambda (p r) | |
1394 | (if (and (string=? (package-name p) "guile") | |
1395 | (string-prefix? "2.0" | |
1396 | (package-version p))) | |
1397 | (cons p r) | |
1398 | r)) | |
1399 | '()) | |
1400 | ((one) | |
b66d6d52 | 1401 | (eq? one guile-2.0)))) |
386b71d1 | 1402 | |
0ea939fb LC |
1403 | (test-assert "fold-available-packages with/without cache" |
1404 | (let () | |
1405 | (define no-cache | |
1406 | (fold-available-packages (lambda* (name version result #:rest rest) | |
1407 | (cons (cons* name version rest) | |
1408 | result)) | |
1409 | '())) | |
1410 | ||
1411 | (define from-cache | |
1412 | (call-with-temporary-directory | |
1413 | (lambda (cache) | |
1414 | (generate-package-cache cache) | |
1415 | (mock ((guix describe) current-profile (const cache)) | |
1416 | (mock ((gnu packages) cache-is-authoritative? (const #t)) | |
1417 | (fold-available-packages (lambda* (name version result | |
1418 | #:rest rest) | |
1419 | (cons (cons* name version rest) | |
1420 | result)) | |
1421 | '())))))) | |
1422 | ||
afc3cd84 MO |
1423 | (define (find-duplicates l) |
1424 | (match l | |
1425 | (() '()) | |
1426 | ((head . tail) | |
1427 | (if (member head tail) | |
1428 | (cons head (find-duplicates tail)) | |
1429 | (find-duplicates tail))))) | |
1430 | ||
1431 | (pk (find-duplicates from-cache)) | |
36754eee LC |
1432 | (and (equal? (delete-duplicates from-cache) from-cache) |
1433 | (lset= equal? no-cache from-cache)))) | |
0ea939fb | 1434 | |
6b1891b0 LC |
1435 | (test-assert "find-packages-by-name" |
1436 | (match (find-packages-by-name "hello") | |
1437 | (((? (cut eq? hello <>))) #t) | |
1438 | (wrong (pk 'find-packages-by-name wrong #f)))) | |
1439 | ||
1440 | (test-assert "find-packages-by-name with version" | |
1441 | (match (find-packages-by-name "hello" (package-version hello)) | |
1442 | (((? (cut eq? hello <>))) #t) | |
1443 | (wrong (pk 'find-packages-by-name wrong #f)))) | |
1444 | ||
5fbdc9a5 LC |
1445 | (test-equal "find-packages-by-name with cache" |
1446 | (find-packages-by-name "guile") | |
1447 | (call-with-temporary-directory | |
1448 | (lambda (cache) | |
1449 | (generate-package-cache cache) | |
1450 | (mock ((guix describe) current-profile (const cache)) | |
1451 | (mock ((gnu packages) cache-is-authoritative? (const #t)) | |
1452 | (find-packages-by-name "guile")))))) | |
1453 | ||
1454 | (test-equal "find-packages-by-name + version, with cache" | |
1455 | (find-packages-by-name "guile" "2") | |
1456 | (call-with-temporary-directory | |
1457 | (lambda (cache) | |
1458 | (generate-package-cache cache) | |
1459 | (mock ((guix describe) current-profile (const cache)) | |
1460 | (mock ((gnu packages) cache-is-authoritative? (const #t)) | |
1461 | (find-packages-by-name "guile" "2")))))) | |
1462 | ||
cf81a236 LC |
1463 | (test-assert "--search-paths with pattern" |
1464 | ;; Make sure 'guix package --search-paths' correctly reports environment | |
1465 | ;; variables when file patterns are used (in particular, it must follow | |
1466 | ;; symlinks when looking for 'catalog.xml'.) To do that, we rely on the | |
1467 | ;; libxml2 package specification, which contains such a definition. | |
1468 | (let* ((p1 (package | |
1469 | (name "foo") (version "0") (source #f) | |
1470 | (build-system trivial-build-system) | |
1471 | (arguments | |
1472 | `(#:guile ,%bootstrap-guile | |
1473 | #:modules ((guix build utils)) | |
1474 | #:builder (begin | |
1475 | (use-modules (guix build utils)) | |
1476 | (let ((out (assoc-ref %outputs "out"))) | |
1477 | (mkdir-p (string-append out "/xml/bar/baz")) | |
1478 | (call-with-output-file | |
1479 | (string-append out "/xml/bar/baz/catalog.xml") | |
1480 | (lambda (port) | |
1e868858 MW |
1481 | (display "xml? wat?!" port))) |
1482 | #t)))) | |
cf81a236 LC |
1483 | (synopsis #f) (description #f) |
1484 | (home-page #f) (license #f))) | |
1485 | (p2 (package | |
1486 | ;; Provide a fake libxml2 to avoid building the real one. This | |
1487 | ;; is OK because 'guix package' gets search path specifications | |
1488 | ;; from the same-named package found in the distro. | |
1489 | (name "libxml2") (version "0.0.0") (source #f) | |
1490 | (build-system trivial-build-system) | |
1491 | (arguments | |
1492 | `(#:guile ,%bootstrap-guile | |
1e868858 MW |
1493 | #:builder (begin |
1494 | (mkdir (assoc-ref %outputs "out")) | |
1495 | #t))) | |
cf81a236 LC |
1496 | (native-search-paths (package-native-search-paths libxml2)) |
1497 | (synopsis #f) (description #f) | |
1498 | (home-page #f) (license #f))) | |
1499 | (prof (run-with-store %store | |
1500 | (profile-derivation | |
1501 | (manifest (map package->manifest-entry | |
1502 | (list p1 p2))) | |
a6562c7e LC |
1503 | #:hooks '() |
1504 | #:locales? #f) | |
cf81a236 LC |
1505 | #:guile-for-build (%guile-for-build)))) |
1506 | (build-derivations %store (list prof)) | |
1507 | (string-match (format #f "^export XML_CATALOG_FILES=\"~a/xml/+bar/baz/catalog\\.xml\"\n" | |
77559f23 | 1508 | (regexp-quote (derivation->output-path prof))) |
cf81a236 LC |
1509 | (with-output-to-string |
1510 | (lambda () | |
1511 | (guix-package "-p" (derivation->output-path prof) | |
1512 | "--search-paths")))))) | |
1513 | ||
fcd75bdb LC |
1514 | (test-assert "--search-paths with single-item search path" |
1515 | ;; Make sure 'guix package --search-paths' correctly reports environment | |
1516 | ;; variables for things like 'GIT_SSL_CAINFO' that have #f as their | |
1517 | ;; separator, meaning that the first match wins. | |
1518 | (let* ((p1 (dummy-package "foo" | |
1519 | (build-system trivial-build-system) | |
1520 | (arguments | |
1521 | `(#:guile ,%bootstrap-guile | |
1522 | #:modules ((guix build utils)) | |
1523 | #:builder (begin | |
1524 | (use-modules (guix build utils)) | |
1525 | (let ((out (assoc-ref %outputs "out"))) | |
1526 | (mkdir-p (string-append out "/etc/ssl/certs")) | |
1527 | (call-with-output-file | |
1528 | (string-append | |
1529 | out "/etc/ssl/certs/ca-certificates.crt") | |
1530 | (const #t)))))))) | |
1531 | (p2 (package (inherit p1) (name "bar"))) | |
1532 | (p3 (dummy-package "git" | |
1533 | ;; Provide a fake Git to avoid building the real one. | |
1534 | (build-system trivial-build-system) | |
1535 | (arguments | |
1536 | `(#:guile ,%bootstrap-guile | |
1e868858 MW |
1537 | #:builder (begin |
1538 | (mkdir (assoc-ref %outputs "out")) | |
1539 | #t))) | |
fcd75bdb LC |
1540 | (native-search-paths (package-native-search-paths git)))) |
1541 | (prof1 (run-with-store %store | |
1542 | (profile-derivation | |
1543 | (packages->manifest (list p1 p3)) | |
1544 | #:hooks '() | |
1545 | #:locales? #f) | |
1546 | #:guile-for-build (%guile-for-build))) | |
1547 | (prof2 (run-with-store %store | |
1548 | (profile-derivation | |
1549 | (packages->manifest (list p2 p3)) | |
1550 | #:hooks '() | |
1551 | #:locales? #f) | |
1552 | #:guile-for-build (%guile-for-build)))) | |
1553 | (build-derivations %store (list prof1 prof2)) | |
1554 | (string-match (format #f "^export GIT_SSL_CAINFO=\"~a/etc/ssl/certs/ca-certificates.crt" | |
1555 | (regexp-quote (derivation->output-path prof1))) | |
1556 | (with-output-to-string | |
1557 | (lambda () | |
1558 | (guix-package "-p" (derivation->output-path prof1) | |
1559 | "-p" (derivation->output-path prof2) | |
1560 | "--search-paths")))))) | |
1561 | ||
efb107e0 LC |
1562 | (test-equal "specification->package when not found" |
1563 | 'quit | |
1564 | (catch 'quit | |
1565 | (lambda () | |
1566 | ;; This should call 'leave', producing an error message. | |
1567 | (specification->package "this-package-does-not-exist")) | |
1568 | (lambda (key . args) | |
1569 | key))) | |
1570 | ||
066eeae1 LC |
1571 | (test-equal "specification->package+output" |
1572 | `((,coreutils "out") (,coreutils "debug")) | |
1573 | (list (call-with-values (lambda () | |
1574 | (specification->package+output "coreutils")) | |
1575 | list) | |
1576 | (call-with-values (lambda () | |
1577 | (specification->package+output "coreutils:debug")) | |
1578 | list))) | |
1579 | ||
1580 | (test-equal "specification->package+output invalid output" | |
1581 | 'error | |
1582 | (catch 'quit | |
1583 | (lambda () | |
1584 | (specification->package+output "coreutils:does-not-exist")) | |
1585 | (lambda _ | |
1586 | 'error))) | |
1587 | ||
1588 | (test-equal "specification->package+output no default output" | |
1589 | `(,coreutils #f) | |
1590 | (call-with-values | |
1591 | (lambda () | |
1592 | (specification->package+output "coreutils" #f)) | |
1593 | list)) | |
1594 | ||
1595 | (test-equal "specification->package+output invalid output, no default" | |
1596 | 'error | |
1597 | (catch 'quit | |
1598 | (lambda () | |
1599 | (specification->package+output "coreutils:does-not-exist" #f)) | |
1600 | (lambda _ | |
1601 | 'error))) | |
1602 | ||
ee8099f5 LC |
1603 | (test-equal "find-package-locations" |
1604 | (map (lambda (package) | |
1605 | (cons (package-version package) | |
1606 | (package-location package))) | |
1607 | (find-packages-by-name "guile")) | |
1608 | (find-package-locations "guile")) | |
1609 | ||
1610 | (test-equal "find-package-locations with cache" | |
1611 | (map (lambda (package) | |
1612 | (cons (package-version package) | |
1613 | (package-location package))) | |
1614 | (find-packages-by-name "guile")) | |
1615 | (call-with-temporary-directory | |
1616 | (lambda (cache) | |
1617 | (generate-package-cache cache) | |
1618 | (mock ((guix describe) current-profile (const cache)) | |
1619 | (mock ((gnu packages) cache-is-authoritative? (const #t)) | |
1620 | (find-package-locations "guile")))))) | |
1621 | ||
1622 | (test-equal "specification->location" | |
1623 | (package-location (specification->package "guile@2")) | |
1624 | (specification->location "guile@2")) | |
1625 | ||
e3ce5d70 LC |
1626 | (test-end "packages") |
1627 | ||
e3ce5d70 | 1628 | ;;; Local Variables: |
a3d73f59 | 1629 | ;;; eval: (put 'dummy-package 'scheme-indent-function 1) |
3e223a22 | 1630 | ;;; eval: (put 'dummy-package/no-implicit 'scheme-indent-function 1) |
e3ce5d70 | 1631 | ;;; End: |