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