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