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 | ||
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 | ||
052faadd LDB |
629 | (test-equal "package-upstream-name*" |
630 | (package-upstream-name* (specification->package "guile-gcrypt")) | |
631 | "gcrypt") | |
632 | ||
cfcead2e MC |
633 | \f |
634 | ;;; | |
635 | ;;; Source derivation with snippets. | |
636 | ;;; | |
637 | ||
12d720fd | 638 | (unless (network-reachable?) (test-skip 1)) |
f9cc8971 LC |
639 | (test-equal "package-source-derivation, snippet" |
640 | "OK" | |
f8ec8d96 | 641 | (let* ((source (bootstrap-origin |
f9cc8971 | 642 | (origin |
f8ec8d96 | 643 | (inherit (bootstrap-guile-origin (%current-system))) |
f9cc8971 LC |
644 | (patch-inputs |
645 | `(("tar" ,%bootstrap-coreutils&co) | |
646 | ("xz" ,%bootstrap-coreutils&co) | |
647 | ("patch" ,%bootstrap-coreutils&co))) | |
7db9608d | 648 | (patch-guile %bootstrap-guile) |
f9cc8971 | 649 | (modules '((guix build utils))) |
f9cc8971 LC |
650 | (snippet '(begin |
651 | ;; We end up in 'bin', because it's the first | |
652 | ;; directory, alphabetically. Not a very good | |
653 | ;; example but hey. | |
654 | (chmod "." #o777) | |
655 | (symlink "guile" "guile-rocks") | |
656 | (copy-recursively "../share/guile/2.0/scripts" | |
d6445dff LC |
657 | "scripts") |
658 | ||
659 | ;; Make sure '.file_list' can be created. | |
660 | (chmod ".." #o777)))))) | |
f9cc8971 LC |
661 | (package (package (inherit (dummy-package "with-snippet")) |
662 | (source source) | |
663 | (build-system trivial-build-system) | |
664 | (inputs | |
665 | `(("tar" ,(search-bootstrap-binary "tar" | |
666 | (%current-system))) | |
667 | ("xz" ,(search-bootstrap-binary "xz" | |
668 | (%current-system))))) | |
669 | (arguments | |
670 | `(#:guile ,%bootstrap-guile | |
1e868858 | 671 | #:modules ((guix build utils)) |
f9cc8971 | 672 | #:builder |
1e868858 MW |
673 | (begin |
674 | (use-modules (guix build utils)) | |
675 | (let ((tar (assoc-ref %build-inputs "tar")) | |
676 | (xz (assoc-ref %build-inputs "xz")) | |
677 | (source (assoc-ref %build-inputs "source"))) | |
678 | (invoke tar "xvf" source | |
679 | "--use-compress-program" xz) | |
680 | (unless (and (string=? "guile" (readlink "bin/guile-rocks")) | |
681 | (file-exists? "bin/scripts/compile.scm")) | |
682 | (error "the snippet apparently failed")) | |
683 | (let ((out (assoc-ref %outputs "out"))) | |
684 | (call-with-output-file out | |
685 | (lambda (p) | |
686 | (display "OK" p)))) | |
687 | #t)))))) | |
f9cc8971 LC |
688 | (drv (package-derivation %store package)) |
689 | (out (derivation->output-path drv))) | |
690 | (and (build-derivations %store (list (pk 'snippet-drv drv))) | |
691 | (call-with-input-file out get-string-all)))) | |
692 | ||
cfcead2e MC |
693 | ;; Note: lzip is not part of bootstrap-coreutils&co, so is not included to |
694 | ;; avoid having to rebuild the world. | |
695 | (define compressors '(("gzip" . "gz") | |
696 | ("xz" . "xz") | |
697 | ("bzip2" . "bz2") | |
698 | (#f . #f))) | |
699 | ||
700 | (for-each | |
701 | (match-lambda | |
702 | ((comp . ext) | |
703 | (unless (network-reachable?) (test-skip 1)) | |
704 | (test-equal (string-append "origin->derivation, single file with snippet " | |
705 | "(compression: " (if comp comp "None") ")") | |
706 | "2 + 2 = 4" | |
707 | (let*-values | |
708 | (((name) "maths") | |
709 | ((compressed-name) (if comp | |
710 | (string-append name "." ext) | |
711 | name)) | |
712 | ((file hash) (test-file %store compressed-name "2 + 2 = 5")) | |
713 | ;; Create an origin using the above computed file and its hash. | |
714 | ((source) (origin | |
715 | (method url-fetch) | |
716 | (uri (string-append "file://" file)) | |
717 | (file-name compressed-name) | |
718 | (patch-inputs `(("tar" ,%bootstrap-coreutils&co) | |
719 | ("xz" ,%bootstrap-coreutils&co) | |
720 | ("bzip2" ,%bootstrap-coreutils&co) | |
721 | ("gzip" ,%bootstrap-coreutils&co))) | |
722 | (patch-guile %bootstrap-guile) | |
723 | (modules '((guix build utils))) | |
724 | (snippet `(substitute* ,name | |
725 | (("5") "4"))) | |
726 | (hash (content-hash hash)))) | |
727 | ;; Build origin. | |
728 | ((drv) (run-with-store %store (origin->derivation source))) | |
729 | ((out) (derivation->output-path drv))) | |
730 | ;; Decompress the resulting tar.xz and return its content. | |
731 | (and (build-derivations %store (list drv)) | |
732 | (if (tarball? out) | |
733 | (let* ((bin #~(string-append #+%bootstrap-coreutils&co | |
734 | "/bin")) | |
735 | (f (computed-file | |
736 | name | |
737 | (with-imported-modules '((guix build utils)) | |
738 | #~(begin | |
739 | (use-modules (guix build utils)) | |
740 | (setenv "PATH" #+bin) | |
741 | (invoke "tar" "xvf" #+out) | |
bc1ad696 LC |
742 | (copy-file #+name #$output))) |
743 | #:guile %bootstrap-guile)) | |
cfcead2e MC |
744 | (drv (run-with-store %store (lower-object f))) |
745 | (_ (build-derivations %store (list drv)))) | |
746 | (call-with-input-file (derivation->output-path drv) | |
747 | get-string-all)) | |
748 | (call-with-input-file out get-string-all))))))) | |
749 | compressors) | |
750 | ||
59688fc4 LC |
751 | (test-assert "return value" |
752 | (let ((drv (package-derivation %store (dummy-package "p")))) | |
753 | (and (derivation? drv) | |
754 | (file-exists? (derivation-file-name drv))))) | |
be13fbfa | 755 | |
6b466336 LC |
756 | (test-assert "package-derivation, inputs deduplicated" |
757 | (let* ((dep (dummy-package "dep")) | |
8524349f | 758 | (p0 (dummy-package "p" (inputs (list dep)))) |
6b466336 LC |
759 | (p1 (package (inherit p0) |
760 | (inputs `(("dep" ,(package (inherit dep))) | |
761 | ,@(package-inputs p0)))))) | |
762 | ;; Here P1 ends up with two non-eq? copies of DEP, under the same label. | |
763 | ;; They should be deduplicated so that P0 and P1 lead to the same | |
764 | ;; derivation rather than P1 ending up with duplicate entries in its | |
765 | ;; '%build-inputs' variable. | |
766 | (string=? (derivation-file-name (package-derivation %store p0)) | |
767 | (derivation-file-name (package-derivation %store p1))))) | |
768 | ||
98c075c2 LC |
769 | (test-assert "package-derivation, different system" |
770 | ;; Make sure the 'system' argument of 'package-derivation' is respected. | |
771 | (let* ((system (if (string=? (%current-system) "x86_64-linux") | |
772 | "aarch64-linux" | |
773 | "x86_64-linux")) | |
774 | (drv (package-derivation %store (dummy-package "p") | |
775 | system #:graft? #f))) | |
776 | (define right-system? | |
777 | (mlambdaq (drv) | |
778 | (and (string=? (derivation-system drv) system) | |
779 | (every (compose right-system? derivation-input-derivation) | |
780 | (derivation-inputs drv))))) | |
781 | ||
782 | (right-system? drv))) | |
783 | ||
d510ab46 LC |
784 | (test-assert "package-output" |
785 | (let* ((package (dummy-package "p")) | |
59688fc4 LC |
786 | (drv (package-derivation %store package))) |
787 | (and (derivation? drv) | |
788 | (string=? (derivation->output-path drv) | |
d510ab46 LC |
789 | (package-output %store package "out"))))) |
790 | ||
d51bfe24 LC |
791 | (test-equal "patch not found yields a run-time error" |
792 | '("~a: patch not found\n" "does-not-exist.patch") | |
793 | (guard (c ((formatted-message? c) | |
794 | (cons (formatted-message-string c) | |
795 | (formatted-message-arguments c)))) | |
dbab5150 LC |
796 | (let ((p (package |
797 | (inherit (dummy-package "p")) | |
798 | (source (origin | |
799 | (method (const #f)) | |
800 | (uri "http://whatever") | |
801 | (patches | |
802 | (list (search-patch "does-not-exist.patch"))) | |
803 | (sha256 | |
804 | (base32 | |
805 | "0amn0bbwqvsvvsh6drfwz20ydc2czk374lzw5kksbh6bf78k4ks4"))))))) | |
806 | (package-derivation %store p) | |
807 | #f))) | |
808 | ||
76c48619 LC |
809 | (let ((dummy (dummy-package "foo" (inputs `(("x" ,(current-module))))))) |
810 | (test-equal "&package-input-error" | |
e7477dd5 | 811 | (list dummy `("x" ,(current-module))) |
76c48619 LC |
812 | (guard (c ((package-input-error? c) |
813 | (list (package-error-package c) | |
814 | (package-error-invalid-input c)))) | |
815 | (package-derivation %store dummy)))) | |
816 | ||
f304c9c2 LC |
817 | (test-assert "reference to non-existent output" |
818 | ;; See <http://bugs.gnu.org/19630>. | |
862abf8f LC |
819 | (parameterize ((%graft? #f)) |
820 | (let* ((dep (dummy-package "dep")) | |
821 | (p (dummy-package "p" | |
8524349f | 822 | (inputs (list `(,dep "non-existent")))))) |
862abf8f LC |
823 | (guard (c ((derivation-missing-output-error? c) |
824 | (and (string=? (derivation-missing-output c) "non-existent") | |
825 | (equal? (package-derivation %store dep) | |
826 | (derivation-error-derivation c))))) | |
827 | (package-derivation %store p))))) | |
f304c9c2 | 828 | |
be13fbfa LC |
829 | (test-assert "trivial" |
830 | (let* ((p (package (inherit (dummy-package "trivial")) | |
831 | (build-system trivial-build-system) | |
832 | (source #f) | |
833 | (arguments | |
14da91e2 LC |
834 | `(#:guile ,%bootstrap-guile |
835 | #:builder | |
be13fbfa LC |
836 | (begin |
837 | (mkdir %output) | |
838 | (call-with-output-file (string-append %output "/test") | |
839 | (lambda (p) | |
1e868858 MW |
840 | (display '(hello guix) p))) |
841 | #t))))) | |
be13fbfa LC |
842 | (d (package-derivation %store p))) |
843 | (and (build-derivations %store (list d)) | |
59688fc4 | 844 | (let ((p (pk 'drv d (derivation->output-path d)))) |
be13fbfa LC |
845 | (equal? '(hello guix) |
846 | (call-with-input-file (string-append p "/test") read)))))) | |
e3ce5d70 | 847 | |
860a6f1a LC |
848 | (test-assert "trivial with local file as input" |
849 | (let* ((i (search-path %load-path "ice-9/boot-9.scm")) | |
850 | (p (package (inherit (dummy-package "trivial-with-input-file")) | |
851 | (build-system trivial-build-system) | |
852 | (source #f) | |
853 | (arguments | |
854 | `(#:guile ,%bootstrap-guile | |
1e868858 MW |
855 | #:builder (begin |
856 | (copy-file (assoc-ref %build-inputs "input") | |
857 | %output) | |
858 | #t))) | |
860a6f1a LC |
859 | (inputs `(("input" ,i))))) |
860 | (d (package-derivation %store p))) | |
861 | (and (build-derivations %store (list d)) | |
59688fc4 | 862 | (let ((p (pk 'drv d (derivation->output-path d)))) |
860a6f1a LC |
863 | (equal? (call-with-input-file p get-bytevector-all) |
864 | (call-with-input-file i get-bytevector-all)))))) | |
865 | ||
03761a44 LC |
866 | (test-assert "trivial with source" |
867 | (let* ((i (search-path %load-path "ice-9/boot-9.scm")) | |
868 | (p (package (inherit (dummy-package "trivial-with-source")) | |
869 | (build-system trivial-build-system) | |
870 | (source i) | |
871 | (arguments | |
872 | `(#:guile ,%bootstrap-guile | |
1e868858 MW |
873 | #:builder (begin |
874 | (copy-file (assoc-ref %build-inputs "source") | |
875 | %output) | |
876 | #t))))) | |
03761a44 LC |
877 | (d (package-derivation %store p))) |
878 | (and (build-derivations %store (list d)) | |
879 | (let ((p (derivation->output-path d))) | |
880 | (equal? (call-with-input-file p get-bytevector-all) | |
881 | (call-with-input-file i get-bytevector-all)))))) | |
882 | ||
592ef6c8 LC |
883 | (test-assert "trivial with system-dependent input" |
884 | (let* ((p (package (inherit (dummy-package "trivial-system-dependent-input")) | |
885 | (build-system trivial-build-system) | |
886 | (source #f) | |
887 | (arguments | |
888 | `(#:guile ,%bootstrap-guile | |
1e868858 | 889 | #:modules ((guix build utils)) |
592ef6c8 | 890 | #:builder |
1e868858 MW |
891 | (begin |
892 | (use-modules (guix build utils)) | |
893 | (let ((out (assoc-ref %outputs "out")) | |
894 | (bash (assoc-ref %build-inputs "bash"))) | |
895 | (invoke bash "-c" | |
896 | (format #f "echo hello > ~a" out)))))) | |
dd6b9a37 LC |
897 | (inputs `(("bash" ,(search-bootstrap-binary "bash" |
898 | (%current-system))))))) | |
592ef6c8 LC |
899 | (d (package-derivation %store p))) |
900 | (and (build-derivations %store (list d)) | |
59688fc4 | 901 | (let ((p (pk 'drv d (derivation->output-path d)))) |
592ef6c8 LC |
902 | (eq? 'hello (call-with-input-file p read)))))) |
903 | ||
29760251 LC |
904 | (test-assert "trivial with #:allowed-references" |
905 | (let* ((p (package | |
906 | (inherit (dummy-package "trivial")) | |
907 | (build-system trivial-build-system) | |
908 | (arguments | |
909 | `(#:guile ,%bootstrap-guile | |
910 | #:allowed-references (,%bootstrap-guile) | |
911 | #:builder | |
912 | (begin | |
913 | (mkdir %output) | |
914 | ;; The reference to itself isn't allowed so building it | |
915 | ;; should fail. | |
1e868858 MW |
916 | (symlink %output (string-append %output "/self")) |
917 | #t))))) | |
29760251 | 918 | (d (package-derivation %store p))) |
f9e8a123 | 919 | (guard (c ((store-protocol-error? c) #t)) |
29760251 LC |
920 | (build-derivations %store (list d)) |
921 | #f))) | |
922 | ||
df46bef4 LC |
923 | (test-assert "trivial with #:allowed-references + grafts" |
924 | (let* ((g (package | |
925 | (inherit %bootstrap-guile) | |
926 | (replacement (package | |
927 | (inherit %bootstrap-guile) | |
928 | (version "9.9"))))) | |
929 | (p (package | |
930 | (inherit (dummy-package "trivial")) | |
931 | (build-system trivial-build-system) | |
932 | (inputs (list g)) | |
933 | (arguments | |
934 | `(#:guile ,g | |
935 | #:allowed-references (,g) | |
936 | #:builder (mkdir %output))))) | |
937 | (d0 (package-derivation %store p #:graft? #f)) | |
938 | (d1 (parameterize ((%graft? #t)) | |
939 | (package-derivation %store p #:graft? #t)))) | |
940 | ;; D1 should be equal to D2 because there's nothing to graft. In | |
941 | ;; particular, its #:disallowed-references should be lowered in the same | |
942 | ;; way (ungrafted) whether or not #:graft? is true. | |
943 | (string=? (derivation-file-name d1) (derivation-file-name d0)))) | |
944 | ||
a18eda27 LC |
945 | (test-assert "search paths" |
946 | (let* ((p (make-prompt-tag "return-search-paths")) | |
89b0c239 | 947 | (t (make-parameter "guile-0")) |
a18eda27 | 948 | (s (build-system |
89b0c239 LC |
949 | (name 'raw) |
950 | (description "Raw build system with direct store access") | |
951 | (lower (lambda* (name #:key source inputs system target | |
952 | #:allow-other-keys) | |
953 | (bag | |
954 | (name name) | |
955 | (system system) (target target) | |
956 | (build-inputs inputs) | |
957 | (build | |
958 | (lambda* (name inputs | |
959 | #:key outputs system search-paths) | |
960 | (if (string=? name (t)) | |
961 | (abort-to-prompt p search-paths) | |
962 | (gexp->derivation name | |
963 | #~(mkdir #$output)))))))))) | |
a18eda27 LC |
964 | (x (list (search-path-specification |
965 | (variable "GUILE_LOAD_PATH") | |
af070955 | 966 | (files '("share/guile/site/2.0"))) |
a18eda27 LC |
967 | (search-path-specification |
968 | (variable "GUILE_LOAD_COMPILED_PATH") | |
af070955 | 969 | (files '("share/guile/site/2.0"))))) |
a18eda27 LC |
970 | (a (package (inherit (dummy-package "guile")) |
971 | (build-system s) | |
972 | (native-search-paths x))) | |
973 | (b (package (inherit (dummy-package "guile-foo")) | |
974 | (build-system s) | |
975 | (inputs `(("guile" ,a))))) | |
976 | (c (package (inherit (dummy-package "guile-bar")) | |
977 | (build-system s) | |
978 | (inputs `(("guile" ,a) | |
979 | ("guile-foo" ,b)))))) | |
980 | (let-syntax ((collect (syntax-rules () | |
981 | ((_ body ...) | |
982 | (call-with-prompt p | |
983 | (lambda () | |
984 | body ...) | |
985 | (lambda (k search-paths) | |
986 | search-paths)))))) | |
987 | (and (null? (collect (package-derivation %store a))) | |
89b0c239 LC |
988 | (parameterize ((t "guile-foo-0")) |
989 | (equal? x (collect (package-derivation %store b)))) | |
990 | (parameterize ((t "guile-bar-0")) | |
991 | (equal? x (collect (package-derivation %store c)))))))) | |
a18eda27 | 992 | |
aa8e0515 LC |
993 | (test-assert "package-transitive-native-search-paths" |
994 | (let* ((sp (lambda (name) | |
995 | (list (search-path-specification | |
996 | (variable name) | |
997 | (files '("foo/bar")))))) | |
998 | (p0 (dummy-package "p0" (native-search-paths (sp "PATH0")))) | |
999 | (p1 (dummy-package "p1" (native-search-paths (sp "PATH1")))) | |
1000 | (p2 (dummy-package "p2" | |
1001 | (native-search-paths (sp "PATH2")) | |
8524349f LC |
1002 | (inputs (list p0)) |
1003 | (propagated-inputs (list p1)))) | |
aa8e0515 LC |
1004 | (p3 (dummy-package "p3" |
1005 | (native-search-paths (sp "PATH3")) | |
8524349f LC |
1006 | (native-inputs (list p0)) |
1007 | (propagated-inputs (list p2))))) | |
aa8e0515 LC |
1008 | (lset= string=? |
1009 | '("PATH1" "PATH2" "PATH3") | |
1010 | (map search-path-specification-variable | |
1011 | (package-transitive-native-search-paths p3))))) | |
1012 | ||
9c1edabd | 1013 | (test-assert "package-cross-derivation" |
59688fc4 LC |
1014 | (let ((drv (package-cross-derivation %store (dummy-package "p") |
1015 | "mips64el-linux-gnu"))) | |
1016 | (and (derivation? drv) | |
1017 | (file-exists? (derivation-file-name drv))))) | |
9c1edabd | 1018 | |
5dce8218 LC |
1019 | (test-assert "package-cross-derivation, trivial-build-system" |
1020 | (let ((p (package (inherit (dummy-package "p")) | |
1021 | (build-system trivial-build-system) | |
1022 | (arguments '(#:builder (exit 1)))))) | |
59688fc4 LC |
1023 | (let ((drv (package-cross-derivation %store p "mips64el-linux-gnu"))) |
1024 | (derivation? drv)))) | |
5dce8218 | 1025 | |
9b222abe LC |
1026 | (test-assert "package-cross-derivation, no cross builder" |
1027 | (let* ((b (build-system (inherit trivial-build-system) | |
0d5a559f | 1028 | (lower (const #f)))) |
9b222abe LC |
1029 | (p (package (inherit (dummy-package "p")) |
1030 | (build-system b)))) | |
1031 | (guard (c ((package-cross-build-system-error? c) | |
1032 | (eq? (package-error-package c) p))) | |
1033 | (package-cross-derivation %store p "mips64el-linux-gnu") | |
1034 | #f))) | |
1035 | ||
b4c42a4b LC |
1036 | ;; XXX: The next two tests can trigger builds when the distro defines |
1037 | ;; replacements on core packages, so they're disable for lack of a better | |
1038 | ;; solution. | |
1039 | ||
1040 | ;; (test-equal "package-derivation, direct graft" | |
1041 | ;; (package-derivation %store gnu-make #:graft? #f) | |
1042 | ;; (let ((p (package (inherit coreutils) | |
1043 | ;; (replacement gnu-make)))) | |
1044 | ;; (package-derivation %store p #:graft? #t))) | |
05962f29 | 1045 | |
b4c42a4b LC |
1046 | ;; (test-equal "package-cross-derivation, direct graft" |
1047 | ;; (package-cross-derivation %store gnu-make "mips64el-linux-gnu" | |
1048 | ;; #:graft? #f) | |
1049 | ;; (let ((p (package (inherit coreutils) | |
1050 | ;; (replacement gnu-make)))) | |
1051 | ;; (package-cross-derivation %store p "mips64el-linux-gnu" | |
1052 | ;; #:graft? #t))) | |
05962f29 LC |
1053 | |
1054 | (test-assert "package-grafts, indirect grafts" | |
1055 | (let* ((new (dummy-package "dep" | |
1056 | (arguments '(#:implicit-inputs? #f)))) | |
1057 | (dep (package (inherit new) (version "0.0"))) | |
1058 | (dep* (package (inherit dep) (replacement new))) | |
1059 | (dummy (dummy-package "dummy" | |
1060 | (arguments '(#:implicit-inputs? #f)) | |
8524349f | 1061 | (inputs (list dep*))))) |
05962f29 LC |
1062 | (equal? (package-grafts %store dummy) |
1063 | (list (graft | |
1064 | (origin (package-derivation %store dep)) | |
1065 | (replacement (package-derivation %store new))))))) | |
1066 | ||
d0025d01 LC |
1067 | ;; XXX: This test would require building the cross toolchain just to see if it |
1068 | ;; needs grafting, which is obviously too expensive, and thus disabled. | |
1069 | ;; | |
1070 | ;; (test-assert "package-grafts, indirect grafts, cross" | |
1071 | ;; (let* ((new (dummy-package "dep" | |
1072 | ;; (arguments '(#:implicit-inputs? #f)))) | |
1073 | ;; (dep (package (inherit new) (version "0.0"))) | |
1074 | ;; (dep* (package (inherit dep) (replacement new))) | |
1075 | ;; (dummy (dummy-package "dummy" | |
1076 | ;; (arguments '(#:implicit-inputs? #f)) | |
1077 | ;; (inputs `(("dep" ,dep*))))) | |
1078 | ;; (target "mips64el-linux-gnu")) | |
1079 | ;; ;; XXX: There might be additional grafts, for instance if the distro | |
1080 | ;; ;; defines replacements for core packages like Perl. | |
1081 | ;; (member (graft | |
1082 | ;; (origin (package-cross-derivation %store dep target)) | |
1083 | ;; (replacement | |
1084 | ;; (package-cross-derivation %store new target))) | |
1085 | ;; (package-grafts %store dummy #:target target)))) | |
05962f29 LC |
1086 | |
1087 | (test-assert "package-grafts, indirect grafts, propagated inputs" | |
1088 | (let* ((new (dummy-package "dep" | |
1089 | (arguments '(#:implicit-inputs? #f)))) | |
1090 | (dep (package (inherit new) (version "0.0"))) | |
1091 | (dep* (package (inherit dep) (replacement new))) | |
1092 | (prop (dummy-package "propagated" | |
8524349f | 1093 | (propagated-inputs (list dep*)) |
05962f29 LC |
1094 | (arguments '(#:implicit-inputs? #f)))) |
1095 | (dummy (dummy-package "dummy" | |
1096 | (arguments '(#:implicit-inputs? #f)) | |
8524349f | 1097 | (inputs (list prop))))) |
05962f29 LC |
1098 | (equal? (package-grafts %store dummy) |
1099 | (list (graft | |
1100 | (origin (package-derivation %store dep)) | |
1101 | (replacement (package-derivation %store new))))))) | |
1102 | ||
fcadd9ff LC |
1103 | (test-assert "package-grafts, same replacement twice" |
1104 | (let* ((new (dummy-package "dep" | |
1105 | (version "1") | |
1106 | (arguments '(#:implicit-inputs? #f)))) | |
1107 | (dep (package (inherit new) (version "0") (replacement new))) | |
1108 | (p1 (dummy-package "intermediate1" | |
1109 | (arguments '(#:implicit-inputs? #f)) | |
8524349f | 1110 | (inputs (list dep)))) |
fcadd9ff LC |
1111 | (p2 (dummy-package "intermediate2" |
1112 | (arguments '(#:implicit-inputs? #f)) | |
1113 | ;; Here we copy DEP to have an equivalent package that is not | |
1114 | ;; 'eq?' to DEP. This is similar to what happens with | |
1115 | ;; 'package-with-explicit-inputs' & co. | |
8524349f | 1116 | (inputs (list (package (inherit dep)))))) |
fcadd9ff LC |
1117 | (p3 (dummy-package "final" |
1118 | (arguments '(#:implicit-inputs? #f)) | |
8524349f | 1119 | (inputs (list p1 p2))))) |
fcadd9ff LC |
1120 | (equal? (package-grafts %store p3) |
1121 | (list (graft | |
1122 | (origin (package-derivation %store | |
1123 | (package (inherit dep) | |
1124 | (replacement #f)))) | |
1125 | (replacement (package-derivation %store new))))))) | |
1126 | ||
03a70e4c LC |
1127 | (test-assert "package-grafts, dependency on several outputs" |
1128 | ;; Make sure we get one graft per output; see <https://bugs.gnu.org/41796>. | |
1129 | (letrec* ((p0 (dummy-package "p0" | |
1130 | (version "1.0") | |
1131 | (replacement p0*) | |
1132 | (arguments '(#:implicit-inputs? #f)) | |
1133 | (outputs '("out" "lib")))) | |
1134 | (p0* (package (inherit p0) (version "1.1"))) | |
1135 | (p1 (dummy-package "p1" | |
1136 | (arguments '(#:implicit-inputs? #f)) | |
8524349f | 1137 | (inputs (list p0 `(,p0 "lib")))))) |
03a70e4c LC |
1138 | (lset= equal? (pk (package-grafts %store p1)) |
1139 | (list (graft | |
1140 | (origin (package-derivation %store p0)) | |
1141 | (origin-output "out") | |
1142 | (replacement (package-derivation %store p0*)) | |
1143 | (replacement-output "out")) | |
1144 | (graft | |
1145 | (origin (package-derivation %store p0)) | |
1146 | (origin-output "lib") | |
1147 | (replacement (package-derivation %store p0*)) | |
1148 | (replacement-output "lib")))))) | |
1149 | ||
d0025d01 LC |
1150 | (test-assert "replacement also grafted" |
1151 | ;; We build a DAG as below, where dotted arrows represent replacements and | |
1152 | ;; solid arrows represent dependencies: | |
1153 | ;; | |
1154 | ;; P1 ·············> P1R | |
1155 | ;; |\__________________. | |
1156 | ;; v v | |
1157 | ;; P2 ·············> P2R | |
1158 | ;; | | |
1159 | ;; v | |
1160 | ;; P3 | |
1161 | ;; | |
1162 | ;; We want to make sure that: | |
1163 | ;; grafts(P3) = (P1,P1R) + (P2, grafted(P2R, (P1,P1R))) | |
1164 | ;; where: | |
1165 | ;; (A,B) is a graft to replace A by B | |
1166 | ;; grafted(DRV,G) denoted DRV with graft G applied | |
1167 | (let* ((p1r (dummy-package "P1" | |
1168 | (build-system trivial-build-system) | |
1169 | (arguments | |
1170 | `(#:guile ,%bootstrap-guile | |
1171 | #:builder (let ((out (assoc-ref %outputs "out"))) | |
1172 | (mkdir out) | |
1173 | (call-with-output-file | |
1174 | (string-append out "/replacement") | |
1175 | (const #t))))))) | |
1176 | (p1 (package | |
1177 | (inherit p1r) (name "p1") (replacement p1r) | |
1178 | (arguments | |
1179 | `(#:guile ,%bootstrap-guile | |
1e868858 MW |
1180 | #:builder (begin |
1181 | (mkdir (assoc-ref %outputs "out")) | |
1182 | #t))))) | |
d0025d01 LC |
1183 | (p2r (dummy-package "P2" |
1184 | (build-system trivial-build-system) | |
8524349f | 1185 | (inputs (list p1)) |
d0025d01 LC |
1186 | (arguments |
1187 | `(#:guile ,%bootstrap-guile | |
1188 | #:builder (let ((out (assoc-ref %outputs "out"))) | |
1189 | (mkdir out) | |
1190 | (chdir out) | |
1191 | (symlink (assoc-ref %build-inputs "p1") "p1") | |
1192 | (call-with-output-file (string-append out "/replacement") | |
1193 | (const #t))))))) | |
1194 | (p2 (package | |
1195 | (inherit p2r) (name "p2") (replacement p2r) | |
1196 | (arguments | |
1197 | `(#:guile ,%bootstrap-guile | |
1198 | #:builder (let ((out (assoc-ref %outputs "out"))) | |
1199 | (mkdir out) | |
1200 | (chdir out) | |
1201 | (symlink (assoc-ref %build-inputs "p1") | |
1e868858 MW |
1202 | "p1") |
1203 | #t))))) | |
d0025d01 LC |
1204 | (p3 (dummy-package "p3" |
1205 | (build-system trivial-build-system) | |
8524349f | 1206 | (inputs (list p2)) |
d0025d01 LC |
1207 | (arguments |
1208 | `(#:guile ,%bootstrap-guile | |
1209 | #:builder (let ((out (assoc-ref %outputs "out"))) | |
1210 | (mkdir out) | |
1211 | (chdir out) | |
1212 | (symlink (assoc-ref %build-inputs "p2") | |
1e868858 MW |
1213 | "p2") |
1214 | #t)))))) | |
d0025d01 LC |
1215 | (lset= equal? |
1216 | (package-grafts %store p3) | |
1217 | (list (graft | |
1218 | (origin (package-derivation %store p1 #:graft? #f)) | |
1219 | (replacement (package-derivation %store p1r))) | |
1220 | (graft | |
1221 | (origin (package-derivation %store p2 #:graft? #f)) | |
1222 | (replacement | |
1223 | (package-derivation %store p2r #:graft? #t))))))) | |
1224 | ||
c22a1324 LC |
1225 | ;;; XXX: Nowadays 'graft-derivation' needs to build derivations beforehand to |
1226 | ;;; find out about their run-time dependencies, so this test is no longer | |
1227 | ;;; applicable since it would trigger a full rebuild. | |
1228 | ;; | |
1229 | ;; (test-assert "package-derivation, indirect grafts" | |
1230 | ;; (let* ((new (dummy-package "dep" | |
1231 | ;; (arguments '(#:implicit-inputs? #f)))) | |
1232 | ;; (dep (package (inherit new) (version "0.0"))) | |
1233 | ;; (dep* (package (inherit dep) (replacement new))) | |
1234 | ;; (dummy (dummy-package "dummy" | |
1235 | ;; (arguments '(#:implicit-inputs? #f)) | |
1236 | ;; (inputs `(("dep" ,dep*))))) | |
1237 | ;; (guile (package-derivation %store (canonical-package guile-2.0) | |
1238 | ;; #:graft? #f))) | |
1239 | ;; (equal? (package-derivation %store dummy) | |
1240 | ;; (graft-derivation %store | |
1241 | ;; (package-derivation %store dummy #:graft? #f) | |
1242 | ;; (package-grafts %store dummy) | |
1243 | ||
1244 | ;; ;; Use the same Guile as 'package-derivation'. | |
1245 | ;; #:guile guile)))) | |
05962f29 | 1246 | |
d3d337d2 LC |
1247 | (test-equal "package->bag" |
1248 | `("foo86-hurd" #f (,(package-source gnu-make)) | |
1249 | (,(canonical-package glibc)) (,(canonical-package coreutils))) | |
1250 | (let ((bag (package->bag gnu-make "foo86-hurd"))) | |
1251 | (list (bag-system bag) (bag-target bag) | |
1252 | (assoc-ref (bag-build-inputs bag) "source") | |
1253 | (assoc-ref (bag-build-inputs bag) "libc") | |
1254 | (assoc-ref (bag-build-inputs bag) "coreutils")))) | |
1255 | ||
b49caaa2 LC |
1256 | (test-assert "package->bag, sensitivity to %current-target-system" |
1257 | ;; https://bugs.gnu.org/41713 | |
1258 | (let* ((lower (lambda* (name #:key system target inputs native-inputs | |
1259 | #:allow-other-keys) | |
1260 | (and (not target) | |
1261 | (bag (name name) (system system) (target target) | |
1262 | (build-inputs native-inputs) | |
1263 | (host-inputs inputs) | |
7d873f19 LC |
1264 | (build (lambda* (name inputs |
1265 | #:key system target | |
1266 | #:allow-other-keys) | |
1267 | (gexp->derivation "foo" | |
1268 | #~(mkdir #$output)))))))) | |
b49caaa2 LC |
1269 | (bs (build-system |
1270 | (name 'build-system-without-cross-compilation) | |
1271 | (description "Does not support cross compilation.") | |
1272 | (lower lower))) | |
1273 | (dep (dummy-package "dep" (build-system bs))) | |
1274 | (pkg (dummy-package "example" | |
8524349f | 1275 | (native-inputs (list dep)))) |
b49caaa2 LC |
1276 | (do-not-build (lambda (continue store lst . _) lst))) |
1277 | (equal? (with-build-handler do-not-build | |
1278 | (parameterize ((%current-target-system "powerpc64le-linux-gnu") | |
1279 | (%graft? #t)) | |
1280 | (package-cross-derivation %store pkg | |
1281 | (%current-target-system) | |
1282 | #:graft? #t))) | |
1283 | (with-build-handler do-not-build | |
1284 | (package-cross-derivation %store | |
1285 | (package (inherit pkg)) | |
1286 | "powerpc64le-linux-gnu" | |
1287 | #:graft? #t))))) | |
1288 | ||
d3d337d2 LC |
1289 | (test-equal "package->bag, cross-compilation" |
1290 | `(,(%current-system) "foo86-hurd" | |
1291 | (,(package-source gnu-make)) | |
1292 | (,(canonical-package glibc)) (,(canonical-package coreutils))) | |
1293 | (let ((bag (package->bag gnu-make (%current-system) "foo86-hurd"))) | |
1294 | (list (bag-system bag) (bag-target bag) | |
1295 | (assoc-ref (bag-build-inputs bag) "source") | |
1296 | (assoc-ref (bag-build-inputs bag) "libc") | |
1297 | (assoc-ref (bag-build-inputs bag) "coreutils")))) | |
1298 | ||
50373bab LC |
1299 | (test-assert "package->bag, propagated inputs" |
1300 | (let* ((dep (dummy-package "dep")) | |
1301 | (prop (dummy-package "prop" | |
8524349f | 1302 | (propagated-inputs (list dep)))) |
50373bab | 1303 | (dummy (dummy-package "dummy" |
8524349f | 1304 | (inputs (list prop)))) |
50373bab | 1305 | (inputs (bag-transitive-inputs (package->bag dummy #:graft? #f)))) |
161094c8 LC |
1306 | (match (assoc "dep" inputs) |
1307 | (("dep" package) | |
50373bab LC |
1308 | (eq? package dep))))) |
1309 | ||
efb10f17 LC |
1310 | (test-assert "package->bag, sensitivity to %current-system" |
1311 | (let* ((dep (dummy-package "dep" | |
1312 | (propagated-inputs (if (string=? (%current-system) | |
1313 | "i586-gnu") | |
1314 | `(("libxml2" ,libxml2)) | |
1315 | '())))) | |
1316 | (pkg (dummy-package "foo" | |
8524349f | 1317 | (native-inputs (list dep)))) |
efb10f17 LC |
1318 | (bag (package->bag pkg (%current-system) "i586-gnu"))) |
1319 | (equal? (parameterize ((%current-system "x86_64-linux")) | |
1320 | (bag-transitive-inputs bag)) | |
1321 | (parameterize ((%current-system "i586-gnu")) | |
1322 | (bag-transitive-inputs bag))))) | |
1323 | ||
f52fbf70 LC |
1324 | (test-assert "package->bag, sensitivity to %current-target-system" |
1325 | (let* ((dep (dummy-package "dep" | |
1326 | (propagated-inputs (if (%current-target-system) | |
1327 | `(("libxml2" ,libxml2)) | |
1328 | '())))) | |
1329 | (pkg (dummy-package "foo" | |
8524349f | 1330 | (native-inputs (list dep)))) |
f52fbf70 LC |
1331 | (bag (package->bag pkg (%current-system) "foo86-hurd"))) |
1332 | (equal? (parameterize ((%current-target-system "foo64-gnu")) | |
1333 | (bag-transitive-inputs bag)) | |
1334 | (parameterize ((%current-target-system #f)) | |
1335 | (bag-transitive-inputs bag))))) | |
1336 | ||
ba41f87e | 1337 | (test-assertm "bag->derivation" |
05962f29 LC |
1338 | (parameterize ((%graft? #f)) |
1339 | (let ((bag (package->bag gnu-make)) | |
1340 | (drv (package-derivation %store gnu-make))) | |
1341 | (parameterize ((%current-system "foox86-hurd")) ;should have no effect | |
ba41f87e LC |
1342 | (mlet %store-monad ((bag-drv (bag->derivation bag))) |
1343 | (return (equal? drv bag-drv))))))) | |
d3d337d2 LC |
1344 | |
1345 | (test-assert "bag->derivation, cross-compilation" | |
05962f29 LC |
1346 | (parameterize ((%graft? #f)) |
1347 | (let* ((target "mips64el-linux-gnu") | |
1348 | (bag (package->bag gnu-make (%current-system) target)) | |
1349 | (drv (package-cross-derivation %store gnu-make target))) | |
1350 | (parameterize ((%current-system "foox86-hurd") ;should have no effect | |
1351 | (%current-target-system "foo64-linux-gnu")) | |
ba41f87e LC |
1352 | (mlet %store-monad ((bag-drv (bag->derivation bag))) |
1353 | (return (equal? drv bag-drv))))))) | |
d3d337d2 | 1354 | |
b69c5c2c LC |
1355 | (when (or (not (network-reachable?)) (shebang-too-long?)) |
1356 | (test-skip 1)) | |
9e782349 | 1357 | (test-assert "GNU Make, bootstrap" |
03d76577 LC |
1358 | ;; GNU-MAKE-FOR-TESTS can be built cheaply; we choose it here so that the |
1359 | ;; test doesn't last for too long. | |
1360 | (let ((gnu-make gnu-make-for-tests)) | |
9e782349 LC |
1361 | (and (package? gnu-make) |
1362 | (or (location? (package-location gnu-make)) | |
1363 | (not (package-location gnu-make))) | |
1364 | (let* ((drv (package-derivation %store gnu-make)) | |
59688fc4 | 1365 | (out (derivation->output-path drv))) |
14da91e2 | 1366 | (and (build-derivations %store (list drv)) |
9e782349 | 1367 | (file-exists? (string-append out "/bin/make"))))))) |
e3ce5d70 | 1368 | |
f37f2b83 LC |
1369 | (test-equal "package-mapping" |
1370 | 42 | |
1371 | (let* ((dep (dummy-package "chbouib" | |
1372 | (native-inputs `(("x" ,grep))))) | |
1373 | (p0 (dummy-package "example" | |
ff39361c | 1374 | (source 77) |
f37f2b83 LC |
1375 | (inputs `(("foo" ,coreutils) |
1376 | ("bar" ,grep) | |
1377 | ("baz" ,dep))))) | |
1378 | (transform (lambda (p) | |
1379 | (package (inherit p) (source 42)))) | |
1380 | (rewrite (package-mapping transform)) | |
ff39361c LC |
1381 | (p1 (rewrite p0)) |
1382 | (bag0 (package->bag p0)) | |
1383 | (bag1 (package->bag p1))) | |
f37f2b83 LC |
1384 | (and (eq? p1 (rewrite p0)) |
1385 | (eqv? 42 (package-source p1)) | |
ff39361c LC |
1386 | |
1387 | ;; Implicit inputs should be left unchanged (skip "source", "foo", | |
1388 | ;; "bar", and "baz" in this comparison). | |
1389 | (equal? (drop (bag-direct-inputs bag0) 4) | |
1390 | (drop (bag-direct-inputs bag1) 4)) | |
1391 | ||
f37f2b83 LC |
1392 | (match (package-inputs p1) |
1393 | ((("foo" dep1) ("bar" dep2) ("baz" dep3)) | |
1394 | (and (eq? dep1 (rewrite coreutils)) ;memoization | |
1395 | (eq? dep2 (rewrite grep)) | |
1396 | (eq? dep3 (rewrite dep)) | |
1397 | (eqv? 42 | |
1398 | (package-source dep1) (package-source dep2) | |
1399 | (package-source dep3)) | |
1400 | (match (package-native-inputs dep3) | |
1401 | ((("x" dep)) | |
1402 | (and (eq? dep (rewrite grep)) | |
1403 | (package-source dep)))))))))) | |
1404 | ||
ff39361c LC |
1405 | (test-equal "package-mapping, deep" |
1406 | '(42) | |
1407 | (let* ((p0 (dummy-package "example" | |
1408 | (inputs `(("foo" ,coreutils) | |
1409 | ("bar" ,grep))))) | |
1410 | (transform (lambda (p) | |
1411 | (package (inherit p) (source 42)))) | |
1412 | (rewrite (package-mapping transform #:deep? #t)) | |
1413 | (p1 (rewrite p0)) | |
1414 | (bag (package->bag p1))) | |
1415 | (and (eq? p1 (rewrite p0)) | |
1416 | (match (bag-direct-inputs bag) | |
1417 | ((("source" 42) ("foo" dep1) ("bar" dep2) rest ..1) | |
1418 | (and (eq? dep1 (rewrite coreutils)) ;memoization | |
1419 | (eq? dep2 (rewrite grep)) | |
1420 | (= 42 (package-source dep1)) | |
1421 | (= 42 (package-source dep2)) | |
1422 | ||
1423 | ;; Check that implicit inputs of P0 also got rewritten. | |
1424 | (delete-duplicates | |
1425 | (map (match-lambda | |
1426 | ((_ package . _) | |
1427 | (package-source package))) | |
1428 | rest)))))))) | |
1429 | ||
2a75b0b6 LC |
1430 | (test-assert "package-input-rewriting" |
1431 | (let* ((dep (dummy-package "chbouib" | |
1432 | (native-inputs `(("x" ,grep))))) | |
1433 | (p0 (dummy-package "example" | |
1434 | (inputs `(("foo" ,coreutils) | |
1435 | ("bar" ,grep) | |
1436 | ("baz" ,dep))))) | |
1437 | (rewrite (package-input-rewriting `((,coreutils . ,sed) | |
1438 | (,grep . ,findutils)) | |
8819551c LC |
1439 | (cut string-append "r-" <>) |
1440 | #:deep? #f)) | |
2a75b0b6 LC |
1441 | (p1 (rewrite p0)) |
1442 | (p2 (rewrite p0))) | |
1443 | (and (not (eq? p1 p0)) | |
1444 | (eq? p1 p2) ;memoization | |
1445 | (string=? "r-example" (package-name p1)) | |
1446 | (match (package-inputs p1) | |
1447 | ((("foo" dep1) ("bar" dep2) ("baz" dep3)) | |
1448 | (and (eq? dep1 sed) | |
1449 | (eq? dep2 findutils) | |
1450 | (string=? (package-name dep3) "r-chbouib") | |
1451 | (eq? dep3 (rewrite dep)) ;memoization | |
1452 | (match (package-native-inputs dep3) | |
1453 | ((("x" dep)) | |
8819551c LC |
1454 | (eq? dep findutils)))))) |
1455 | ||
1456 | ;; Make sure implicit inputs were left unchanged. | |
1457 | (equal? (drop (bag-direct-inputs (package->bag p1)) 3) | |
1458 | (drop (bag-direct-inputs (package->bag p0)) 3))))) | |
1459 | ||
1460 | (test-eq "package-input-rewriting, deep" | |
1461 | (derivation-file-name (package-derivation %store sed)) | |
1462 | (let* ((p0 (dummy-package "chbouib" | |
1463 | (build-system python-build-system) | |
1464 | (arguments `(#:python ,python)))) | |
1465 | (rewrite (package-input-rewriting `((,python . ,sed)))) | |
1466 | (p1 (rewrite p0))) | |
1467 | (match (bag-direct-inputs (package->bag p1)) | |
1468 | ((("python" python) _ ...) | |
1469 | (derivation-file-name (package-derivation %store python)))))) | |
2a75b0b6 | 1470 | |
f258d886 LC |
1471 | (test-assert "package-input-rewriting/spec" |
1472 | (let* ((dep (dummy-package "chbouib" | |
1473 | (native-inputs `(("x" ,grep))))) | |
1474 | (p0 (dummy-package "example" | |
1475 | (inputs `(("foo" ,coreutils) | |
1476 | ("bar" ,grep) | |
1477 | ("baz" ,dep))))) | |
1478 | (rewrite (package-input-rewriting/spec | |
1479 | `(("coreutils" . ,(const sed)) | |
2bf6f962 LC |
1480 | ("grep" . ,(const findutils))) |
1481 | #:deep? #f)) | |
f258d886 LC |
1482 | (p1 (rewrite p0)) |
1483 | (p2 (rewrite p0))) | |
1484 | (and (not (eq? p1 p0)) | |
1485 | (eq? p1 p2) ;memoization | |
1486 | (string=? "example" (package-name p1)) | |
1487 | (match (package-inputs p1) | |
1488 | ((("foo" dep1) ("bar" dep2) ("baz" dep3)) | |
1489 | (and (string=? (package-full-name dep1) | |
1490 | (package-full-name sed)) | |
1491 | (string=? (package-full-name dep2) | |
1492 | (package-full-name findutils)) | |
1493 | (string=? (package-name dep3) "chbouib") | |
1494 | (eq? dep3 (rewrite dep)) ;memoization | |
1495 | (match (package-native-inputs dep3) | |
1496 | ((("x" dep)) | |
1497 | (string=? (package-full-name dep) | |
2bf6f962 LC |
1498 | (package-full-name findutils))))))) |
1499 | ||
1500 | ;; Make sure implicit inputs were left unchanged. | |
1501 | (equal? (drop (bag-direct-inputs (package->bag p1)) 3) | |
1502 | (drop (bag-direct-inputs (package->bag p0)) 3))))) | |
f258d886 LC |
1503 | |
1504 | (test-assert "package-input-rewriting/spec, partial match" | |
1505 | (let* ((dep (dummy-package "chbouib" | |
1506 | (version "1") | |
1507 | (native-inputs `(("x" ,grep))))) | |
1508 | (p0 (dummy-package "example" | |
1509 | (inputs `(("foo" ,coreutils) | |
1510 | ("bar" ,dep))))) | |
1511 | (rewrite (package-input-rewriting/spec | |
1512 | `(("chbouib@123" . ,(const sed)) ;not matched | |
2bf6f962 LC |
1513 | ("grep" . ,(const findutils))) |
1514 | #:deep? #f)) | |
f258d886 LC |
1515 | (p1 (rewrite p0))) |
1516 | (and (not (eq? p1 p0)) | |
1517 | (string=? "example" (package-name p1)) | |
1518 | (match (package-inputs p1) | |
1519 | ((("foo" dep1) ("bar" dep2)) | |
1520 | (and (string=? (package-full-name dep1) | |
1521 | (package-full-name coreutils)) | |
1522 | (eq? dep2 (rewrite dep)) ;memoization | |
1523 | (match (package-native-inputs dep2) | |
1524 | ((("x" dep)) | |
1525 | (string=? (package-full-name dep) | |
1526 | (package-full-name findutils)))))))))) | |
1527 | ||
2bf6f962 LC |
1528 | (test-assert "package-input-rewriting/spec, deep" |
1529 | (let* ((dep (dummy-package "chbouib")) | |
1530 | (p0 (dummy-package "example" | |
1531 | (build-system gnu-build-system) | |
1532 | (inputs `(("dep" ,dep))))) | |
1533 | (rewrite (package-input-rewriting/spec | |
1534 | `(("tar" . ,(const sed)) | |
1535 | ("gzip" . ,(const findutils))))) | |
1536 | (p1 (rewrite p0)) | |
1537 | (p2 (rewrite p0))) | |
1538 | (and (not (eq? p1 p0)) | |
1539 | (eq? p1 p2) ;memoization | |
1540 | (string=? "example" (package-name p1)) | |
1541 | (match (package-inputs p1) | |
1542 | ((("dep" dep1)) | |
1543 | (and (string=? (package-full-name dep1) | |
1544 | (package-full-name dep)) | |
1545 | (eq? dep1 (rewrite dep))))) ;memoization | |
1546 | ||
1547 | ;; Make sure implicit inputs were replaced. | |
1548 | (match (bag-direct-inputs (package->bag p1)) | |
1549 | ((("dep" dep1) ("tar" tar) ("gzip" gzip) _ ...) | |
1550 | (and (eq? dep1 (rewrite dep)) | |
1551 | (string=? (package-full-name tar) | |
1552 | (package-full-name sed)) | |
1553 | (string=? (package-full-name gzip) | |
1554 | (package-full-name findutils)))))))) | |
1555 | ||
1556 | (test-assert "package-input-rewriting/spec, no duplicates" | |
1557 | ;; Ensure that deep input rewriting does not forget implicit inputs. Doing | |
1558 | ;; so could lead to duplicates in a package's inputs: in the example below, | |
1559 | ;; P0's transitive inputs would contain one rewritten "python" and one | |
1560 | ;; original "python". These two "python" packages are thus not 'eq?' but | |
1561 | ;; they lower to the same derivation. See <https://bugs.gnu.org/42156>, | |
1562 | ;; which can be reproduced by passing #:deep? #f. | |
1563 | (let* ((dep0 (dummy-package "dep0" | |
1564 | (build-system trivial-build-system) | |
1565 | (propagated-inputs `(("python" ,python))))) | |
1566 | (p0 (dummy-package "chbouib" | |
1567 | (build-system python-build-system) | |
1568 | (arguments `(#:python ,python)) | |
1569 | (inputs `(("dep0" ,dep0))))) | |
1570 | (rewrite (package-input-rewriting/spec '() #:deep? #t)) | |
1571 | (p1 (rewrite p0)) | |
1572 | (bag1 (package->bag p1)) | |
1573 | (pythons (filter-map (match-lambda | |
1574 | (("python" python) python) | |
1575 | (_ #f)) | |
1576 | (bag-transitive-inputs bag1)))) | |
1577 | (match (delete-duplicates pythons eq?) | |
1578 | ((p) (eq? p (rewrite python)))))) | |
1579 | ||
b3fc03ee LC |
1580 | (test-equal "package-input-rewriting/spec, graft" |
1581 | (derivation-file-name (package-derivation %store sed)) | |
1582 | ||
1583 | ;; Make sure replacements are rewritten. | |
1584 | (let* ((dep0 (dummy-package "dep" | |
1585 | (version "1") | |
1586 | (build-system trivial-build-system) | |
1587 | (inputs `(("coreutils" ,coreutils))))) | |
1588 | (dep1 (dummy-package "dep" | |
1589 | (version "0") | |
1590 | (build-system trivial-build-system) | |
1591 | (replacement dep0))) | |
1592 | (p0 (dummy-package "p" | |
1593 | (build-system trivial-build-system) | |
1594 | (inputs `(("dep" ,dep1))))) | |
1595 | (rewrite (package-input-rewriting/spec | |
1596 | `(("coreutils" . ,(const sed))))) | |
1597 | (p1 (rewrite p0))) | |
1598 | (match (package-inputs p1) | |
1599 | ((("dep" dep)) | |
1600 | (match (package-inputs (package-replacement dep)) | |
1601 | ((("coreutils" coreutils)) | |
1602 | ;; COREUTILS is not 'eq?' to SED, so the most reliable way to check | |
1603 | ;; for equality is to lower to a derivation. | |
1604 | (derivation-file-name | |
1605 | (package-derivation %store coreutils)))))))) | |
1606 | ||
46135ce4 LC |
1607 | (test-assert "package-with-c-toolchain" |
1608 | (let* ((dep (dummy-package "chbouib" | |
1609 | (build-system gnu-build-system) | |
1610 | (native-inputs `(("x" ,grep))))) | |
1611 | (p0 (dummy-package "thingie" | |
1612 | (build-system gnu-build-system) | |
1613 | (inputs `(("foo" ,grep) | |
1614 | ("bar" ,dep))))) | |
1615 | (tc (dummy-package "my-toolchain")) | |
1616 | (p1 (package-with-c-toolchain p0 `(("toolchain" ,tc))))) | |
1617 | (define toolchain-packages | |
1618 | '("gcc" "binutils" "glibc" "ld-wrapper")) | |
1619 | ||
1620 | (match (bag-build-inputs (package->bag p1)) | |
1621 | ((("foo" foo) ("bar" bar) (_ (= package-name packages) . _) ...) | |
1622 | (and (not (any (cut member <> packages) toolchain-packages)) | |
1623 | (member "my-toolchain" packages) | |
1624 | (eq? foo grep) | |
1625 | (eq? bar dep)))))) | |
1626 | ||
8db4ebb0 LC |
1627 | (test-assert "package-input-rewriting/spec, identity" |
1628 | ;; Make sure that 'package-input-rewriting/spec' doesn't gratuitously | |
1629 | ;; introduce variants. In this case, the LIBFFI propagated input should not | |
1630 | ;; be duplicated when passing GOBJECT through REWRITE. | |
1631 | ;; See <https://issues.guix.gnu.org/43890>. | |
1632 | (let* ((libffi (dummy-package "libffi" | |
1633 | (build-system trivial-build-system))) | |
1634 | (glib (dummy-package "glib" | |
1635 | (build-system trivial-build-system) | |
8524349f | 1636 | (propagated-inputs (list libffi)))) |
8db4ebb0 LC |
1637 | (gobject (dummy-package "gobject-introspection" |
1638 | (build-system trivial-build-system) | |
8524349f LC |
1639 | (inputs (list glib)) |
1640 | (propagated-inputs (list libffi)))) | |
8db4ebb0 LC |
1641 | (rewrite (package-input-rewriting/spec |
1642 | `(("glib" . ,identity))))) | |
1643 | (and (= (length (package-transitive-inputs gobject)) | |
1644 | (length (package-transitive-inputs (rewrite gobject)))) | |
1645 | (string=? (derivation-file-name | |
1646 | (package-derivation %store (rewrite gobject))) | |
1647 | (derivation-file-name | |
1648 | (package-derivation %store gobject)))))) | |
1649 | ||
1650 | (test-assert "package-input-rewriting, identity" | |
1651 | ;; Similar to the test above, but with 'package-input-rewriting'. | |
1652 | ;; See <https://issues.guix.gnu.org/43890>. | |
1653 | (let* ((libffi (dummy-package "libffi" | |
1654 | (build-system trivial-build-system))) | |
1655 | (glib (dummy-package "glib" | |
1656 | (build-system trivial-build-system) | |
8524349f | 1657 | (propagated-inputs (list libffi)))) |
8db4ebb0 LC |
1658 | (gobject (dummy-package "gobject-introspection" |
1659 | (build-system trivial-build-system) | |
8524349f LC |
1660 | (inputs (list glib)) |
1661 | (propagated-inputs (list libffi)))) | |
8db4ebb0 LC |
1662 | (rewrite (package-input-rewriting `((,glib . ,glib))))) |
1663 | (and (= (length (package-transitive-inputs gobject)) | |
1664 | (length (package-transitive-inputs (rewrite gobject)))) | |
1665 | (string=? (derivation-file-name | |
1666 | (package-derivation %store (rewrite gobject))) | |
1667 | (derivation-file-name | |
1668 | (package-derivation %store gobject)))))) | |
1669 | ||
c423ae89 LC |
1670 | (test-equal "package-patched-vulnerabilities" |
1671 | '(("CVE-2015-1234") | |
1672 | ("CVE-2016-1234" "CVE-2018-4567") | |
1673 | ()) | |
1674 | (let ((p1 (dummy-package "pi" | |
1675 | (source (dummy-origin | |
1676 | (patches (list "/a/b/pi-CVE-2015-1234.patch")))))) | |
1677 | (p2 (dummy-package "pi" | |
1678 | (source (dummy-origin | |
1679 | (patches (list | |
1680 | "/a/b/pi-CVE-2016-1234-CVE-2018-4567.patch")))))) | |
1681 | (p3 (dummy-package "pi" (source (dummy-origin))))) | |
1682 | (map package-patched-vulnerabilities | |
1683 | (list p1 p2 p3)))) | |
1684 | ||
ba326ce4 LC |
1685 | (test-eq "fold-packages" hello |
1686 | (fold-packages (lambda (p r) | |
1687 | (if (string=? (package-name p) "hello") | |
1688 | p | |
1689 | r)) | |
1690 | #f)) | |
1691 | ||
386b71d1 LC |
1692 | (test-assert "fold-packages, hidden package" |
1693 | ;; There are two public variables providing "guile@2.0" ('guile-final' in | |
b66d6d52 | 1694 | ;; commencement.scm and 'guile-2.0' in guile.scm), but only the latter |
386b71d1 LC |
1695 | ;; should show up. |
1696 | (match (fold-packages (lambda (p r) | |
1697 | (if (and (string=? (package-name p) "guile") | |
1698 | (string-prefix? "2.0" | |
1699 | (package-version p))) | |
1700 | (cons p r) | |
1701 | r)) | |
1702 | '()) | |
1703 | ((one) | |
b66d6d52 | 1704 | (eq? one guile-2.0)))) |
386b71d1 | 1705 | |
0ea939fb LC |
1706 | (test-assert "fold-available-packages with/without cache" |
1707 | (let () | |
1708 | (define no-cache | |
1709 | (fold-available-packages (lambda* (name version result #:rest rest) | |
1710 | (cons (cons* name version rest) | |
1711 | result)) | |
1712 | '())) | |
1713 | ||
1714 | (define from-cache | |
1715 | (call-with-temporary-directory | |
1716 | (lambda (cache) | |
1717 | (generate-package-cache cache) | |
1718 | (mock ((guix describe) current-profile (const cache)) | |
1719 | (mock ((gnu packages) cache-is-authoritative? (const #t)) | |
1720 | (fold-available-packages (lambda* (name version result | |
1721 | #:rest rest) | |
1722 | (cons (cons* name version rest) | |
1723 | result)) | |
1724 | '())))))) | |
1725 | ||
73744725 LC |
1726 | (define (list->set* lst) |
1727 | ;; Return two values: LST represented as a set and the list of | |
1728 | ;; duplicates in LST. | |
1729 | (let loop ((lst lst) | |
1730 | (duplicates '()) | |
1731 | (seen (set))) | |
1732 | (match lst | |
1733 | (() | |
1734 | (values seen duplicates)) | |
1735 | ((head . tail) | |
1736 | (if (set-contains? seen head) | |
1737 | (loop tail (cons head duplicates) seen) | |
1738 | (loop tail duplicates (set-insert head seen))))))) | |
1739 | ||
1740 | ;; Compare FROM-CACHE and NO-CACHE but avoid 'lset=', which exhibits | |
1741 | ;; exponential behavior. | |
1742 | (let ((set1 duplicates1 (list->set* from-cache)) | |
1743 | (set2 duplicates2 (list->set* no-cache))) | |
1744 | (and (null? duplicates1) (null? duplicates2) | |
1745 | (every (cut set-contains? set1 <>) no-cache) | |
1746 | (every (cut set-contains? set2 <>) from-cache))))) | |
0ea939fb | 1747 | |
6b1891b0 LC |
1748 | (test-assert "find-packages-by-name" |
1749 | (match (find-packages-by-name "hello") | |
1750 | (((? (cut eq? hello <>))) #t) | |
1751 | (wrong (pk 'find-packages-by-name wrong #f)))) | |
1752 | ||
1753 | (test-assert "find-packages-by-name with version" | |
1754 | (match (find-packages-by-name "hello" (package-version hello)) | |
1755 | (((? (cut eq? hello <>))) #t) | |
1756 | (wrong (pk 'find-packages-by-name wrong #f)))) | |
1757 | ||
5fbdc9a5 LC |
1758 | (test-equal "find-packages-by-name with cache" |
1759 | (find-packages-by-name "guile") | |
1760 | (call-with-temporary-directory | |
1761 | (lambda (cache) | |
1762 | (generate-package-cache cache) | |
1763 | (mock ((guix describe) current-profile (const cache)) | |
1764 | (mock ((gnu packages) cache-is-authoritative? (const #t)) | |
1765 | (find-packages-by-name "guile")))))) | |
1766 | ||
1767 | (test-equal "find-packages-by-name + version, with cache" | |
1768 | (find-packages-by-name "guile" "2") | |
1769 | (call-with-temporary-directory | |
1770 | (lambda (cache) | |
1771 | (generate-package-cache cache) | |
1772 | (mock ((guix describe) current-profile (const cache)) | |
1773 | (mock ((gnu packages) cache-is-authoritative? (const #t)) | |
1774 | (find-packages-by-name "guile" "2")))))) | |
1775 | ||
cf81a236 LC |
1776 | (test-assert "--search-paths with pattern" |
1777 | ;; Make sure 'guix package --search-paths' correctly reports environment | |
1778 | ;; variables when file patterns are used (in particular, it must follow | |
1779 | ;; symlinks when looking for 'catalog.xml'.) To do that, we rely on the | |
1780 | ;; libxml2 package specification, which contains such a definition. | |
1781 | (let* ((p1 (package | |
1782 | (name "foo") (version "0") (source #f) | |
1783 | (build-system trivial-build-system) | |
1784 | (arguments | |
1785 | `(#:guile ,%bootstrap-guile | |
1786 | #:modules ((guix build utils)) | |
1787 | #:builder (begin | |
1788 | (use-modules (guix build utils)) | |
1789 | (let ((out (assoc-ref %outputs "out"))) | |
1790 | (mkdir-p (string-append out "/xml/bar/baz")) | |
1791 | (call-with-output-file | |
1792 | (string-append out "/xml/bar/baz/catalog.xml") | |
1793 | (lambda (port) | |
1e868858 MW |
1794 | (display "xml? wat?!" port))) |
1795 | #t)))) | |
cf81a236 LC |
1796 | (synopsis #f) (description #f) |
1797 | (home-page #f) (license #f))) | |
1798 | (p2 (package | |
1799 | ;; Provide a fake libxml2 to avoid building the real one. This | |
1800 | ;; is OK because 'guix package' gets search path specifications | |
1801 | ;; from the same-named package found in the distro. | |
1802 | (name "libxml2") (version "0.0.0") (source #f) | |
1803 | (build-system trivial-build-system) | |
1804 | (arguments | |
1805 | `(#:guile ,%bootstrap-guile | |
1e868858 MW |
1806 | #:builder (begin |
1807 | (mkdir (assoc-ref %outputs "out")) | |
1808 | #t))) | |
cf81a236 LC |
1809 | (native-search-paths (package-native-search-paths libxml2)) |
1810 | (synopsis #f) (description #f) | |
1811 | (home-page #f) (license #f))) | |
1812 | (prof (run-with-store %store | |
1813 | (profile-derivation | |
1814 | (manifest (map package->manifest-entry | |
1815 | (list p1 p2))) | |
a6562c7e LC |
1816 | #:hooks '() |
1817 | #:locales? #f) | |
cf81a236 LC |
1818 | #:guile-for-build (%guile-for-build)))) |
1819 | (build-derivations %store (list prof)) | |
1820 | (string-match (format #f "^export XML_CATALOG_FILES=\"~a/xml/+bar/baz/catalog\\.xml\"\n" | |
77559f23 | 1821 | (regexp-quote (derivation->output-path prof))) |
cf81a236 LC |
1822 | (with-output-to-string |
1823 | (lambda () | |
1824 | (guix-package "-p" (derivation->output-path prof) | |
1825 | "--search-paths")))))) | |
1826 | ||
fcd75bdb LC |
1827 | (test-assert "--search-paths with single-item search path" |
1828 | ;; Make sure 'guix package --search-paths' correctly reports environment | |
1829 | ;; variables for things like 'GIT_SSL_CAINFO' that have #f as their | |
1830 | ;; separator, meaning that the first match wins. | |
1831 | (let* ((p1 (dummy-package "foo" | |
1832 | (build-system trivial-build-system) | |
1833 | (arguments | |
1834 | `(#:guile ,%bootstrap-guile | |
1835 | #:modules ((guix build utils)) | |
1836 | #:builder (begin | |
1837 | (use-modules (guix build utils)) | |
1838 | (let ((out (assoc-ref %outputs "out"))) | |
1839 | (mkdir-p (string-append out "/etc/ssl/certs")) | |
1840 | (call-with-output-file | |
1841 | (string-append | |
1842 | out "/etc/ssl/certs/ca-certificates.crt") | |
1843 | (const #t)))))))) | |
1844 | (p2 (package (inherit p1) (name "bar"))) | |
1845 | (p3 (dummy-package "git" | |
1846 | ;; Provide a fake Git to avoid building the real one. | |
1847 | (build-system trivial-build-system) | |
1848 | (arguments | |
1849 | `(#:guile ,%bootstrap-guile | |
1e868858 MW |
1850 | #:builder (begin |
1851 | (mkdir (assoc-ref %outputs "out")) | |
1852 | #t))) | |
fcd75bdb LC |
1853 | (native-search-paths (package-native-search-paths git)))) |
1854 | (prof1 (run-with-store %store | |
1855 | (profile-derivation | |
1856 | (packages->manifest (list p1 p3)) | |
1857 | #:hooks '() | |
1858 | #:locales? #f) | |
1859 | #:guile-for-build (%guile-for-build))) | |
1860 | (prof2 (run-with-store %store | |
1861 | (profile-derivation | |
1862 | (packages->manifest (list p2 p3)) | |
1863 | #:hooks '() | |
1864 | #:locales? #f) | |
1865 | #:guile-for-build (%guile-for-build)))) | |
1866 | (build-derivations %store (list prof1 prof2)) | |
1867 | (string-match (format #f "^export GIT_SSL_CAINFO=\"~a/etc/ssl/certs/ca-certificates.crt" | |
1868 | (regexp-quote (derivation->output-path prof1))) | |
1869 | (with-output-to-string | |
1870 | (lambda () | |
1871 | (guix-package "-p" (derivation->output-path prof1) | |
1872 | "-p" (derivation->output-path prof2) | |
1873 | "--search-paths")))))) | |
1874 | ||
efb107e0 LC |
1875 | (test-equal "specification->package when not found" |
1876 | 'quit | |
1877 | (catch 'quit | |
1878 | (lambda () | |
1879 | ;; This should call 'leave', producing an error message. | |
1880 | (specification->package "this-package-does-not-exist")) | |
1881 | (lambda (key . args) | |
1882 | key))) | |
1883 | ||
066eeae1 LC |
1884 | (test-equal "specification->package+output" |
1885 | `((,coreutils "out") (,coreutils "debug")) | |
1886 | (list (call-with-values (lambda () | |
1887 | (specification->package+output "coreutils")) | |
1888 | list) | |
1889 | (call-with-values (lambda () | |
1890 | (specification->package+output "coreutils:debug")) | |
1891 | list))) | |
1892 | ||
1893 | (test-equal "specification->package+output invalid output" | |
1894 | 'error | |
1895 | (catch 'quit | |
1896 | (lambda () | |
1897 | (specification->package+output "coreutils:does-not-exist")) | |
1898 | (lambda _ | |
1899 | 'error))) | |
1900 | ||
1901 | (test-equal "specification->package+output no default output" | |
1902 | `(,coreutils #f) | |
1903 | (call-with-values | |
1904 | (lambda () | |
1905 | (specification->package+output "coreutils" #f)) | |
1906 | list)) | |
1907 | ||
1908 | (test-equal "specification->package+output invalid output, no default" | |
1909 | 'error | |
1910 | (catch 'quit | |
1911 | (lambda () | |
1912 | (specification->package+output "coreutils:does-not-exist" #f)) | |
1913 | (lambda _ | |
1914 | 'error))) | |
1915 | ||
ee8099f5 LC |
1916 | (test-equal "find-package-locations" |
1917 | (map (lambda (package) | |
1918 | (cons (package-version package) | |
1919 | (package-location package))) | |
1920 | (find-packages-by-name "guile")) | |
1921 | (find-package-locations "guile")) | |
1922 | ||
1923 | (test-equal "find-package-locations with cache" | |
1924 | (map (lambda (package) | |
1925 | (cons (package-version package) | |
1926 | (package-location package))) | |
1927 | (find-packages-by-name "guile")) | |
1928 | (call-with-temporary-directory | |
1929 | (lambda (cache) | |
1930 | (generate-package-cache cache) | |
1931 | (mock ((guix describe) current-profile (const cache)) | |
1932 | (mock ((gnu packages) cache-is-authoritative? (const #t)) | |
1933 | (find-package-locations "guile")))))) | |
1934 | ||
1935 | (test-equal "specification->location" | |
1936 | (package-location (specification->package "guile@2")) | |
1937 | (specification->location "guile@2")) | |
1938 | ||
f54f2aa9 LC |
1939 | (test-equal "package-unique-version-prefix, gcc@8" |
1940 | "8" | |
1941 | (let ((gcc (specification->package "gcc-toolchain@8"))) | |
1942 | (package-unique-version-prefix (package-name gcc) | |
1943 | (package-version gcc)))) | |
1944 | ||
1945 | (test-equal "package-unique-version-prefix, grep" | |
1946 | "" | |
1947 | (let ((grep (specification->package "grep"))) | |
1948 | (package-unique-version-prefix (package-name grep) | |
1949 | (package-version grep)))) | |
1950 | ||
1951 | ||
aaf9aa48 MD |
1952 | (test-eq "this-package-input, exists" |
1953 | hello | |
1954 | (package-arguments | |
1955 | (dummy-package "a" | |
1956 | (inputs `(("hello" ,hello))) | |
1957 | (arguments (this-package-input "hello"))))) | |
1958 | ||
1959 | (test-eq "this-package-input, exists in propagated-inputs" | |
1960 | hello | |
1961 | (package-arguments | |
1962 | (dummy-package "a" | |
1963 | (propagated-inputs `(("hello" ,hello))) | |
1964 | (arguments (this-package-input "hello"))))) | |
1965 | ||
1966 | (test-eq "this-package-input, does not exist" | |
1967 | #f | |
1968 | (package-arguments | |
1969 | (dummy-package "a" | |
1970 | (arguments (this-package-input "hello"))))) | |
1971 | ||
1972 | (test-eq "this-package-native-input, exists" | |
1973 | hello | |
1974 | (package-arguments | |
1975 | (dummy-package "a" | |
1976 | (native-inputs `(("hello" ,hello))) | |
1977 | (arguments (this-package-native-input "hello"))))) | |
1978 | ||
1979 | (test-eq "this-package-native-input, does not exists" | |
1980 | #f | |
1981 | (package-arguments | |
1982 | (dummy-package "a" | |
1983 | (arguments (this-package-native-input "hello"))))) | |
1984 | ||
e3801126 LC |
1985 | (test-eq "modify-inputs, replace" |
1986 | coreutils | |
1987 | ;; Replace an input; notice that the label in unchanged. | |
1988 | (let* ((p1 (dummy-package "p" | |
1989 | (inputs (list hello)))) | |
1990 | (p2 (package | |
1991 | (inherit p1) | |
1992 | (version "1") | |
1993 | (inputs (modify-inputs (package-inputs p1) | |
1994 | (replace "hello" coreutils)))))) | |
1995 | (lookup-package-input p2 "hello"))) | |
1996 | ||
1997 | (test-eq "modify-inputs, replace, change output" | |
1998 | guile-3.0 | |
1999 | ;; Replace an input and choose a different output. | |
2000 | (let* ((p1 (dummy-package "p" | |
2001 | (inputs (list `(,coreutils "debug"))))) | |
2002 | (p2 (package | |
2003 | (inherit p1) | |
2004 | (version "1") | |
2005 | (inputs (modify-inputs (package-inputs p1) | |
2006 | (replace "coreutils" `(,guile-3.0 "out"))))))) | |
2007 | (match (package-inputs p2) | |
2008 | ((("coreutils" input "out")) | |
2009 | input)))) | |
2010 | ||
00dfff84 LC |
2011 | (test-eq "modify-inputs, replace, extra output" |
2012 | guile-3.0 | |
2013 | ;; Replace an input; notice that its output is preserved. | |
2014 | ;; See <https://issues.guix.gnu.org/53915>. | |
2015 | (let* ((p1 (dummy-package "p" | |
2016 | (inputs (list `(,coreutils "debug"))))) | |
2017 | (p2 (package | |
2018 | (inherit p1) | |
2019 | (version "1") | |
2020 | (inputs (modify-inputs (package-inputs p1) | |
2021 | (replace "coreutils" guile-3.0)))))) | |
2022 | (match (package-inputs p2) | |
2023 | ((("coreutils" input "debug")) | |
2024 | input)))) | |
2025 | ||
e3ce5d70 LC |
2026 | (test-end "packages") |
2027 | ||
e3ce5d70 | 2028 | ;;; Local Variables: |
a3d73f59 | 2029 | ;;; eval: (put 'dummy-package 'scheme-indent-function 1) |
3e223a22 | 2030 | ;;; eval: (put 'dummy-package/no-implicit 'scheme-indent-function 1) |
e3ce5d70 | 2031 | ;;; End: |