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