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