Commit | Line | Data |
---|---|---|
21b679f6 | 1 | ;;; GNU Guix --- Functional package management for GNU |
d63ee94d | 2 | ;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org> |
21b679f6 LC |
3 | ;;; |
4 | ;;; This file is part of GNU Guix. | |
5 | ;;; | |
6 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | |
7 | ;;; under the terms of the GNU General Public License as published by | |
8 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
9 | ;;; your option) any later version. | |
10 | ;;; | |
11 | ;;; GNU Guix is distributed in the hope that it will be useful, but | |
12 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | ;;; GNU General Public License for more details. | |
15 | ;;; | |
16 | ;;; You should have received a copy of the GNU General Public License | |
17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | |
18 | ||
19 | (define-module (test-gexp) | |
20 | #:use-module (guix store) | |
21 | #:use-module (guix monads) | |
22 | #:use-module (guix gexp) | |
ef8de985 | 23 | #:use-module (guix grafts) |
21b679f6 | 24 | #:use-module (guix derivations) |
79c0c8cd | 25 | #:use-module (guix packages) |
838e17d8 | 26 | #:use-module (guix build-system trivial) |
c1bc358f | 27 | #:use-module (guix tests) |
4ff76a0a | 28 | #:use-module ((guix build utils) #:select (with-directory-excursion)) |
1ae16033 | 29 | #:use-module ((guix utils) #:select (call-with-temporary-directory)) |
21b679f6 LC |
30 | #:use-module (gnu packages) |
31 | #:use-module (gnu packages base) | |
32 | #:use-module (gnu packages bootstrap) | |
33 | #:use-module (srfi srfi-1) | |
c8351d9a | 34 | #:use-module (srfi srfi-34) |
21b679f6 LC |
35 | #:use-module (srfi srfi-64) |
36 | #:use-module (rnrs io ports) | |
37 | #:use-module (ice-9 match) | |
2cf0ea0d | 38 | #:use-module (ice-9 regex) |
0687fc9c LC |
39 | #:use-module (ice-9 popen) |
40 | #:use-module (ice-9 ftw)) | |
21b679f6 LC |
41 | |
42 | ;; Test the (guix gexp) module. | |
43 | ||
44 | (define %store | |
c1bc358f | 45 | (open-connection-for-tests)) |
21b679f6 | 46 | |
ef8de985 LC |
47 | ;; Globally disable grafts because they can trigger early builds. |
48 | (%graft? #f) | |
49 | ||
21b679f6 | 50 | ;; For white-box testing. |
1f976033 LC |
51 | (define (gexp-inputs x) |
52 | ((@@ (guix gexp) gexp-inputs) x)) | |
53 | (define (gexp-native-inputs x) | |
54 | ((@@ (guix gexp) gexp-native-inputs) x)) | |
55 | (define (gexp-outputs x) | |
56 | ((@@ (guix gexp) gexp-outputs) x)) | |
57 | (define (gexp->sexp . x) | |
58 | (apply (@@ (guix gexp) gexp->sexp) x)) | |
21b679f6 | 59 | |
667b2508 | 60 | (define* (gexp->sexp* exp #:optional target) |
68a61e9f | 61 | (run-with-store %store (gexp->sexp exp |
68a61e9f | 62 | #:target target) |
c1bc358f | 63 | #:guile-for-build (%guile-for-build))) |
21b679f6 | 64 | |
838e17d8 LC |
65 | (define %extension-package |
66 | ;; Example of a package to use when testing 'with-extensions'. | |
67 | (dummy-package "extension" | |
68 | (build-system trivial-build-system) | |
69 | (arguments | |
70 | `(#:guile ,%bootstrap-guile | |
71 | #:modules ((guix build utils)) | |
72 | #:builder | |
73 | (begin | |
74 | (use-modules (guix build utils)) | |
75 | (let* ((out (string-append (assoc-ref %outputs "out") | |
76 | "/share/guile/site/" | |
77 | (effective-version)))) | |
78 | (mkdir-p out) | |
79 | (call-with-output-file (string-append out "/hg2g.scm") | |
80 | (lambda (port) | |
e033700f LC |
81 | (define defmod 'define-module) ;fool Geiser |
82 | (write `(,defmod (hg2g) | |
838e17d8 LC |
83 | #:export (the-answer)) |
84 | port) | |
85 | (write '(define the-answer 42) port))))))))) | |
86 | ||
21b679f6 LC |
87 | \f |
88 | (test-begin "gexp") | |
89 | ||
90 | (test-equal "no refs" | |
91 | '(display "hello!") | |
92 | (let ((exp (gexp (display "hello!")))) | |
93 | (and (gexp? exp) | |
94 | (null? (gexp-inputs exp)) | |
95 | (gexp->sexp* exp)))) | |
96 | ||
97 | (test-equal "unquote" | |
98 | '(display `(foo ,(+ 2 3))) | |
99 | (let ((exp (gexp (display `(foo ,(+ 2 3)))))) | |
100 | (and (gexp? exp) | |
101 | (null? (gexp-inputs exp)) | |
102 | (gexp->sexp* exp)))) | |
103 | ||
104 | (test-assert "one input package" | |
105 | (let ((exp (gexp (display (ungexp coreutils))))) | |
106 | (and (gexp? exp) | |
107 | (match (gexp-inputs exp) | |
108 | (((p "out")) | |
109 | (eq? p coreutils))) | |
110 | (equal? `(display ,(derivation->output-path | |
111 | (package-derivation %store coreutils))) | |
112 | (gexp->sexp* exp))))) | |
5e2e4a51 LC |
113 | |
114 | (test-assert "one input package, dotted list" | |
115 | (let ((exp (gexp (coreutils . (ungexp coreutils))))) | |
116 | (and (gexp? exp) | |
117 | (match (gexp-inputs exp) | |
118 | (((p "out")) | |
119 | (eq? p coreutils))) | |
120 | (equal? `(coreutils . ,(derivation->output-path | |
121 | (package-derivation %store coreutils))) | |
122 | (gexp->sexp* exp))))) | |
21b679f6 | 123 | |
79c0c8cd LC |
124 | (test-assert "one input origin" |
125 | (let ((exp (gexp (display (ungexp (package-source coreutils)))))) | |
126 | (and (gexp? exp) | |
127 | (match (gexp-inputs exp) | |
128 | (((o "out")) | |
129 | (eq? o (package-source coreutils)))) | |
130 | (equal? `(display ,(derivation->output-path | |
131 | (package-source-derivation | |
132 | %store (package-source coreutils)))) | |
133 | (gexp->sexp* exp))))) | |
134 | ||
d9ae938f LC |
135 | (test-assert "one local file" |
136 | (let* ((file (search-path %load-path "guix.scm")) | |
137 | (local (local-file file)) | |
138 | (exp (gexp (display (ungexp local)))) | |
020f3e41 | 139 | (intd (add-to-store %store (basename file) #f |
d9ae938f LC |
140 | "sha256" file))) |
141 | (and (gexp? exp) | |
142 | (match (gexp-inputs exp) | |
143 | (((x "out")) | |
144 | (eq? x local))) | |
145 | (equal? `(display ,intd) (gexp->sexp* exp))))) | |
146 | ||
7833db1f LC |
147 | (test-assert "one local file, symlink" |
148 | (let ((file (search-path %load-path "guix.scm")) | |
149 | (link (tmpnam))) | |
150 | (dynamic-wind | |
151 | (const #t) | |
152 | (lambda () | |
153 | (symlink (canonicalize-path file) link) | |
154 | (let* ((local (local-file link "my-file" #:recursive? #f)) | |
155 | (exp (gexp (display (ungexp local)))) | |
156 | (intd (add-to-store %store "my-file" #f | |
157 | "sha256" file))) | |
158 | (and (gexp? exp) | |
159 | (match (gexp-inputs exp) | |
160 | (((x "out")) | |
161 | (eq? x local))) | |
162 | (equal? `(display ,intd) (gexp->sexp* exp))))) | |
163 | (lambda () | |
164 | (false-if-exception (delete-file link)))))) | |
165 | ||
4ff76a0a LC |
166 | (test-equal "local-file, relative file name" |
167 | (canonicalize-path (search-path %load-path "guix/base32.scm")) | |
168 | (let ((directory (dirname (search-path %load-path | |
169 | "guix/build-system/gnu.scm")))) | |
170 | (with-directory-excursion directory | |
171 | (let ((file (local-file "../guix/base32.scm"))) | |
172 | (local-file-absolute-file-name file))))) | |
173 | ||
99c45877 LC |
174 | (test-equal "local-file, non-literal relative file name" |
175 | (canonicalize-path (search-path %load-path "guix/base32.scm")) | |
176 | (let ((directory (dirname (search-path %load-path | |
177 | "guix/build-system/gnu.scm")))) | |
178 | (with-directory-excursion directory | |
179 | (let ((file (local-file (string-copy "../base32.scm")))) | |
180 | (local-file-absolute-file-name file))))) | |
181 | ||
0687fc9c LC |
182 | (test-assertm "local-file, #:select?" |
183 | (mlet* %store-monad ((select? -> (lambda (file stat) | |
184 | (member (basename file) | |
185 | '("guix.scm" "tests" | |
186 | "gexp.scm")))) | |
187 | (file -> (local-file ".." "directory" | |
188 | #:recursive? #t | |
189 | #:select? select?)) | |
190 | (dir (lower-object file))) | |
191 | (return (and (store-path? dir) | |
192 | (equal? (scandir dir) | |
193 | '("." ".." "guix.scm" "tests")) | |
194 | (equal? (scandir (string-append dir "/tests")) | |
195 | '("." ".." "gexp.scm")))))) | |
196 | ||
558e8b11 LC |
197 | (test-assert "one plain file" |
198 | (let* ((file (plain-file "hi" "Hello, world!")) | |
199 | (exp (gexp (display (ungexp file)))) | |
200 | (expected (add-text-to-store %store "hi" "Hello, world!"))) | |
201 | (and (gexp? exp) | |
202 | (match (gexp-inputs exp) | |
203 | (((x "out")) | |
204 | (eq? x file))) | |
205 | (equal? `(display ,expected) (gexp->sexp* exp))))) | |
206 | ||
21b679f6 LC |
207 | (test-assert "same input twice" |
208 | (let ((exp (gexp (begin | |
209 | (display (ungexp coreutils)) | |
210 | (display (ungexp coreutils)))))) | |
211 | (and (gexp? exp) | |
212 | (match (gexp-inputs exp) | |
213 | (((p "out")) | |
214 | (eq? p coreutils))) | |
215 | (let ((e `(display ,(derivation->output-path | |
216 | (package-derivation %store coreutils))))) | |
217 | (equal? `(begin ,e ,e) (gexp->sexp* exp)))))) | |
218 | ||
219 | (test-assert "two input packages, one derivation, one file" | |
220 | (let* ((drv (build-expression->derivation | |
221 | %store "foo" 'bar | |
222 | #:guile-for-build (package-derivation %store %bootstrap-guile))) | |
223 | (txt (add-text-to-store %store "foo" "Hello, world!")) | |
224 | (exp (gexp (begin | |
225 | (display (ungexp coreutils)) | |
226 | (display (ungexp %bootstrap-guile)) | |
227 | (display (ungexp drv)) | |
228 | (display (ungexp txt)))))) | |
229 | (define (match-input thing) | |
230 | (match-lambda | |
231 | ((drv-or-pkg _ ...) | |
232 | (eq? thing drv-or-pkg)))) | |
233 | ||
234 | (and (gexp? exp) | |
235 | (= 4 (length (gexp-inputs exp))) | |
236 | (every (lambda (input) | |
237 | (find (match-input input) (gexp-inputs exp))) | |
238 | (list drv coreutils %bootstrap-guile txt)) | |
239 | (let ((e0 `(display ,(derivation->output-path | |
240 | (package-derivation %store coreutils)))) | |
241 | (e1 `(display ,(derivation->output-path | |
242 | (package-derivation %store %bootstrap-guile)))) | |
243 | (e2 `(display ,(derivation->output-path drv))) | |
244 | (e3 `(display ,txt))) | |
245 | (equal? `(begin ,e0 ,e1 ,e2 ,e3) (gexp->sexp* exp)))))) | |
246 | ||
a9e5e92f LC |
247 | (test-assert "file-append" |
248 | (let* ((drv (package-derivation %store %bootstrap-guile)) | |
249 | (fa (file-append %bootstrap-guile "/bin/guile")) | |
250 | (exp #~(here we go #$fa))) | |
251 | (and (match (gexp->sexp* exp) | |
252 | (('here 'we 'go (? string? result)) | |
253 | (string=? result | |
254 | (string-append (derivation->output-path drv) | |
255 | "/bin/guile")))) | |
256 | (match (gexp-inputs exp) | |
257 | (((thing "out")) | |
258 | (eq? thing fa)))))) | |
259 | ||
260 | (test-assert "file-append, output" | |
261 | (let* ((drv (package-derivation %store glibc)) | |
262 | (fa (file-append glibc "/lib" "/debug")) | |
263 | (exp #~(foo #$fa:debug))) | |
264 | (and (match (gexp->sexp* exp) | |
265 | (('foo (? string? result)) | |
266 | (string=? result | |
267 | (string-append (derivation->output-path drv "debug") | |
268 | "/lib/debug")))) | |
269 | (match (gexp-inputs exp) | |
270 | (((thing "debug")) | |
271 | (eq? thing fa)))))) | |
272 | ||
273 | (test-assert "file-append, nested" | |
274 | (let* ((drv (package-derivation %store glibc)) | |
275 | (dir (file-append glibc "/bin")) | |
276 | (slash (file-append dir "/")) | |
277 | (file (file-append slash "getent")) | |
278 | (exp #~(foo #$file))) | |
279 | (and (match (gexp->sexp* exp) | |
280 | (('foo (? string? result)) | |
281 | (string=? result | |
282 | (string-append (derivation->output-path drv) | |
283 | "/bin/getent")))) | |
284 | (match (gexp-inputs exp) | |
285 | (((thing "out")) | |
286 | (eq? thing file)))))) | |
287 | ||
abf43d45 LC |
288 | (test-assert "file-append, raw store item" |
289 | (let* ((obj (plain-file "example.txt" "Hello!")) | |
290 | (a (file-append obj "/a")) | |
291 | (b (file-append a "/b")) | |
292 | (c (file-append b "/c")) | |
293 | (exp #~(list #$c)) | |
294 | (item (run-with-store %store (lower-object obj))) | |
295 | (lexp (run-with-store %store (lower-gexp exp)))) | |
296 | (and (equal? (lowered-gexp-sexp lexp) | |
297 | `(list ,(string-append item "/a/b/c"))) | |
298 | (equal? (lowered-gexp-sources lexp) | |
299 | (list item)) | |
300 | (null? (lowered-gexp-inputs lexp))))) | |
301 | ||
cf2ac04f LC |
302 | (test-assertm "with-parameters for %current-system" |
303 | (mlet* %store-monad ((system -> (match (%current-system) | |
304 | ("aarch64-linux" "x86_64-linux") | |
305 | (_ "aarch64-linux"))) | |
306 | (drv (package->derivation coreutils system)) | |
307 | (obj -> (with-parameters ((%current-system system)) | |
308 | coreutils)) | |
309 | (result (lower-object obj))) | |
310 | (return (string=? (derivation-file-name drv) | |
311 | (derivation-file-name result))))) | |
312 | ||
313 | (test-assertm "with-parameters for %current-target-system" | |
314 | (mlet* %store-monad ((target -> "riscv64-linux-gnu") | |
315 | (drv (package->cross-derivation coreutils target)) | |
316 | (obj -> (with-parameters | |
317 | ((%current-target-system target)) | |
318 | coreutils)) | |
319 | (result (lower-object obj))) | |
320 | (return (string=? (derivation-file-name drv) | |
321 | (derivation-file-name result))))) | |
322 | ||
323 | (test-assert "with-parameters + file-append" | |
324 | (let* ((system (match (%current-system) | |
325 | ("aarch64-linux" "x86_64-linux") | |
326 | (_ "aarch64-linux"))) | |
327 | (drv (package-derivation %store coreutils system)) | |
328 | (param (make-parameter 7)) | |
329 | (exp #~(here we go #$(with-parameters ((%current-system system) | |
330 | (param 42)) | |
331 | (if (= (param) 42) | |
332 | (file-append coreutils "/bin/touch") | |
333 | %bootstrap-guile))))) | |
334 | (match (gexp->sexp* exp) | |
335 | (('here 'we 'go (? string? result)) | |
336 | (string=? result | |
337 | (string-append (derivation->output-path drv) | |
338 | "/bin/touch")))))) | |
644cb40c LC |
339 | (test-equal "let-system" |
340 | (list `(begin ,(%current-system) #t) '(system-binding) '() | |
341 | 'low '() '()) | |
342 | (let* ((exp #~(begin | |
343 | #$(let-system system system) | |
344 | #t)) | |
345 | (low (run-with-store %store (lower-gexp exp)))) | |
346 | (list (lowered-gexp-sexp low) | |
347 | (match (gexp-inputs exp) | |
348 | (((($ (@@ (guix gexp) <system-binding>)) "out")) | |
349 | '(system-binding)) | |
350 | (x x)) | |
351 | (gexp-native-inputs exp) | |
352 | 'low | |
353 | (lowered-gexp-inputs low) | |
354 | (lowered-gexp-sources low)))) | |
355 | ||
356 | (test-equal "let-system, target" | |
357 | (list `(list ,(%current-system) #f) | |
358 | `(list ,(%current-system) "aarch64-linux-gnu")) | |
359 | (let ((exp #~(list #$@(let-system (system target) | |
360 | (list system target))))) | |
361 | (list (gexp->sexp* exp) | |
362 | (gexp->sexp* exp "aarch64-linux-gnu")))) | |
363 | ||
364 | (test-equal "let-system, ungexp-native, target" | |
365 | `(here it is: ,(%current-system) #f) | |
366 | (let ((exp #~(here it is: #+@(let-system (system target) | |
367 | (list system target))))) | |
368 | (gexp->sexp* exp "aarch64-linux-gnu"))) | |
369 | ||
370 | (test-equal "let-system, nested" | |
371 | (list `(system* ,(string-append "qemu-system-" (%current-system)) | |
372 | "-m" "256") | |
373 | '() | |
374 | '(system-binding)) | |
375 | (let ((exp #~(system* | |
376 | #+(let-system (system target) | |
377 | (file-append (@@ (gnu packages virtualization) | |
378 | qemu) | |
379 | "/bin/qemu-system-" | |
380 | system)) | |
381 | "-m" "256"))) | |
382 | (list (match (gexp->sexp* exp) | |
383 | (('system* command rest ...) | |
384 | `(system* ,(and (string-prefix? (%store-prefix) command) | |
385 | (basename command)) | |
386 | ,@rest)) | |
387 | (x x)) | |
388 | (gexp-inputs exp) | |
389 | (match (gexp-native-inputs exp) | |
390 | (((($ (@@ (guix gexp) <system-binding>)) "out")) | |
391 | '(system-binding)) | |
392 | (x x))))) | |
cf2ac04f | 393 | |
667b2508 LC |
394 | (test-assert "ungexp + ungexp-native" |
395 | (let* ((exp (gexp (list (ungexp-native %bootstrap-guile) | |
396 | (ungexp coreutils) | |
397 | (ungexp-native glibc) | |
398 | (ungexp binutils)))) | |
399 | (target "mips64el-linux") | |
400 | (guile (derivation->output-path | |
401 | (package-derivation %store %bootstrap-guile))) | |
402 | (cu (derivation->output-path | |
403 | (package-cross-derivation %store coreutils target))) | |
404 | (libc (derivation->output-path | |
405 | (package-derivation %store glibc))) | |
406 | (bu (derivation->output-path | |
407 | (package-cross-derivation %store binutils target)))) | |
408 | (and (lset= equal? | |
409 | `((,%bootstrap-guile "out") (,glibc "out")) | |
410 | (gexp-native-inputs exp)) | |
411 | (lset= equal? | |
412 | `((,coreutils "out") (,binutils "out")) | |
413 | (gexp-inputs exp)) | |
414 | (equal? `(list ,guile ,cu ,libc ,bu) | |
415 | (gexp->sexp* exp target))))) | |
416 | ||
1123759b LC |
417 | (test-equal "ungexp + ungexp-native, nested" |
418 | (list `((,%bootstrap-guile "out")) '<> `((,coreutils "out"))) | |
419 | (let* ((exp (gexp (list (ungexp-native (gexp (ungexp coreutils))) | |
420 | (ungexp %bootstrap-guile))))) | |
421 | (list (gexp-inputs exp) '<> (gexp-native-inputs exp)))) | |
422 | ||
5b14a790 LC |
423 | (test-equal "ungexp + ungexp-native, nested, special mixture" |
424 | `(() <> ((,coreutils "out"))) | |
425 | ||
426 | ;; (gexp-native-inputs exp) used to return '(), wrongfully. | |
427 | (let* ((foo (gexp (foo (ungexp-native coreutils)))) | |
428 | (exp (gexp (bar (ungexp foo))))) | |
429 | (list (gexp-inputs exp) '<> (gexp-native-inputs exp)))) | |
430 | ||
21b679f6 LC |
431 | (test-assert "input list" |
432 | (let ((exp (gexp (display | |
433 | '(ungexp (list %bootstrap-guile coreutils))))) | |
434 | (guile (derivation->output-path | |
435 | (package-derivation %store %bootstrap-guile))) | |
436 | (cu (derivation->output-path | |
437 | (package-derivation %store coreutils)))) | |
438 | (and (lset= equal? | |
439 | `((,%bootstrap-guile "out") (,coreutils "out")) | |
440 | (gexp-inputs exp)) | |
441 | (equal? `(display '(,guile ,cu)) | |
442 | (gexp->sexp* exp))))) | |
443 | ||
667b2508 LC |
444 | (test-assert "input list + ungexp-native" |
445 | (let* ((target "mips64el-linux") | |
446 | (exp (gexp (display | |
447 | (cons '(ungexp-native (list %bootstrap-guile coreutils)) | |
448 | '(ungexp (list glibc binutils)))))) | |
449 | (guile (derivation->output-path | |
450 | (package-derivation %store %bootstrap-guile))) | |
451 | (cu (derivation->output-path | |
452 | (package-derivation %store coreutils))) | |
453 | (xlibc (derivation->output-path | |
454 | (package-cross-derivation %store glibc target))) | |
455 | (xbu (derivation->output-path | |
456 | (package-cross-derivation %store binutils target)))) | |
457 | (and (lset= equal? | |
458 | `((,%bootstrap-guile "out") (,coreutils "out")) | |
459 | (gexp-native-inputs exp)) | |
460 | (lset= equal? | |
461 | `((,glibc "out") (,binutils "out")) | |
462 | (gexp-inputs exp)) | |
463 | (equal? `(display (cons '(,guile ,cu) '(,xlibc ,xbu))) | |
464 | (gexp->sexp* exp target))))) | |
465 | ||
21b679f6 | 466 | (test-assert "input list splicing" |
a482cfdc | 467 | (let* ((inputs (list (gexp-input glibc "debug") %bootstrap-guile)) |
21b679f6 LC |
468 | (outputs (list (derivation->output-path |
469 | (package-derivation %store glibc) | |
470 | "debug") | |
471 | (derivation->output-path | |
472 | (package-derivation %store %bootstrap-guile)))) | |
473 | (exp (gexp (list (ungexp-splicing (cons (+ 2 3) inputs)))))) | |
474 | (and (lset= equal? | |
475 | `((,glibc "debug") (,%bootstrap-guile "out")) | |
476 | (gexp-inputs exp)) | |
477 | (equal? (gexp->sexp* exp) | |
478 | `(list ,@(cons 5 outputs)))))) | |
479 | ||
667b2508 | 480 | (test-assert "input list splicing + ungexp-native-splicing" |
5b14a790 LC |
481 | (let* ((inputs (list (gexp-input glibc "debug" #:native? #t) |
482 | %bootstrap-guile)) | |
0dbea56b LC |
483 | (exp (gexp (list (ungexp-native-splicing (cons (+ 2 3) inputs)))))) |
484 | (and (lset= equal? | |
485 | `((,glibc "debug") (,%bootstrap-guile "out")) | |
486 | (gexp-native-inputs exp)) | |
487 | (null? (gexp-inputs exp)) | |
488 | (equal? (gexp->sexp* exp) ;native | |
489 | (gexp->sexp* exp "mips64el-linux"))))) | |
490 | ||
578dfbe0 LC |
491 | (test-assert "gexp list splicing + ungexp-splicing" |
492 | (let* ((inner (gexp (ungexp-native glibc))) | |
493 | (exp (gexp (list (ungexp-splicing (list inner)))))) | |
494 | (and (equal? `((,glibc "out")) (gexp-native-inputs exp)) | |
495 | (null? (gexp-inputs exp)) | |
496 | (equal? (gexp->sexp* exp) ;native | |
497 | (gexp->sexp* exp "mips64el-linux"))))) | |
498 | ||
4b23c466 LC |
499 | (test-equal "output list" |
500 | 2 | |
501 | (let ((exp (gexp (begin (mkdir (ungexp output)) | |
502 | (mkdir (ungexp output "bar")))))) | |
503 | (length (gexp-outputs exp)))) ;XXX: <output-ref> is private | |
504 | ||
505 | (test-assert "output list, combined gexps" | |
506 | (let* ((exp0 (gexp (mkdir (ungexp output)))) | |
507 | (exp1 (gexp (mkdir (ungexp output "foo")))) | |
508 | (exp2 (gexp (begin (display "hi!") (ungexp exp0) (ungexp exp1))))) | |
509 | (and (lset= equal? | |
510 | (append (gexp-outputs exp0) (gexp-outputs exp1)) | |
511 | (gexp-outputs exp2)) | |
512 | (= 2 (length (gexp-outputs exp2)))))) | |
513 | ||
7e75a673 LC |
514 | (test-equal "output list, combined gexps, duplicate output" |
515 | 1 | |
516 | (let* ((exp0 (gexp (mkdir (ungexp output)))) | |
517 | (exp1 (gexp (begin (mkdir (ungexp output)) (ungexp exp0)))) | |
518 | (exp2 (gexp (begin (mkdir (ungexp output)) (ungexp exp1))))) | |
519 | (length (gexp-outputs exp2)))) | |
520 | ||
f9efe568 LC |
521 | (test-assert "output list + ungexp-splicing list, combined gexps" |
522 | (let* ((exp0 (gexp (mkdir (ungexp output)))) | |
523 | (exp1 (gexp (mkdir (ungexp output "foo")))) | |
524 | (exp2 (gexp (begin (display "hi!") | |
525 | (ungexp-splicing (list exp0 exp1)))))) | |
526 | (and (lset= equal? | |
527 | (append (gexp-outputs exp0) (gexp-outputs exp1)) | |
528 | (gexp-outputs exp2)) | |
529 | (= 2 (length (gexp-outputs exp2)))))) | |
530 | ||
21b679f6 LC |
531 | (test-assertm "gexp->file" |
532 | (mlet* %store-monad ((exp -> (gexp (display (ungexp %bootstrap-guile)))) | |
533 | (guile (package-file %bootstrap-guile)) | |
534 | (sexp (gexp->sexp exp)) | |
535 | (drv (gexp->file "foo" exp)) | |
536 | (out -> (derivation->output-path drv)) | |
537 | (done (built-derivations (list drv))) | |
e74f64b9 | 538 | (refs (references* out))) |
21b679f6 LC |
539 | (return (and (equal? sexp (call-with-input-file out read)) |
540 | (equal? (list guile) refs))))) | |
541 | ||
a9e5e92f LC |
542 | (test-assertm "gexp->file + file-append" |
543 | (mlet* %store-monad ((exp -> #~#$(file-append %bootstrap-guile | |
544 | "/bin/guile")) | |
545 | (guile (package-file %bootstrap-guile)) | |
546 | (drv (gexp->file "foo" exp)) | |
547 | (out -> (derivation->output-path drv)) | |
548 | (done (built-derivations (list drv))) | |
e74f64b9 | 549 | (refs (references* out))) |
a9e5e92f LC |
550 | (return (and (equal? (string-append guile "/bin/guile") |
551 | (call-with-input-file out read)) | |
552 | (equal? (list guile) refs))))) | |
553 | ||
4fbd1a2b LC |
554 | (test-assertm "gexp->file + #:splice?" |
555 | (mlet* %store-monad ((exp -> (list | |
556 | #~(define foo 'bar) | |
557 | #~(define guile #$%bootstrap-guile))) | |
558 | (guile (package-file %bootstrap-guile)) | |
559 | (drv (gexp->file "splice" exp #:splice? #t)) | |
560 | (out -> (derivation->output-path drv)) | |
561 | (done (built-derivations (list drv))) | |
562 | (refs (references* out))) | |
563 | (pk 'splice out) | |
564 | (return (and (equal? `((define foo 'bar) | |
565 | (define guile ,guile) | |
566 | ,(call-with-input-string "" read)) | |
567 | (call-with-input-file out | |
568 | (lambda (port) | |
569 | (list (read port) (read port) (read port))))) | |
570 | (equal? (list guile) refs))))) | |
571 | ||
21b679f6 LC |
572 | (test-assertm "gexp->derivation" |
573 | (mlet* %store-monad ((file (text-file "foo" "Hello, world!")) | |
574 | (exp -> (gexp | |
575 | (begin | |
576 | (mkdir (ungexp output)) | |
577 | (chdir (ungexp output)) | |
578 | (symlink | |
579 | (string-append (ungexp %bootstrap-guile) | |
580 | "/bin/guile") | |
581 | "foo") | |
582 | (symlink (ungexp file) | |
583 | (ungexp output "2nd"))))) | |
584 | (drv (gexp->derivation "foo" exp)) | |
585 | (out -> (derivation->output-path drv)) | |
586 | (out2 -> (derivation->output-path drv "2nd")) | |
587 | (done (built-derivations (list drv))) | |
e74f64b9 LC |
588 | (refs (references* out)) |
589 | (refs2 (references* out2)) | |
21b679f6 LC |
590 | (guile (package-file %bootstrap-guile "bin/guile"))) |
591 | (return (and (string=? (readlink (string-append out "/foo")) guile) | |
592 | (string=? (readlink out2) file) | |
593 | (equal? refs (list (dirname (dirname guile)))) | |
8856f409 LC |
594 | (equal? refs2 (list file)) |
595 | (null? (derivation-properties drv)))))) | |
596 | ||
597 | (test-assertm "gexp->derivation properties" | |
598 | (mlet %store-monad ((drv (gexp->derivation "foo" | |
599 | #~(mkdir #$output) | |
600 | #:properties '((type . test))))) | |
601 | (return (equal? '((type . test)) | |
602 | (derivation-properties drv))))) | |
21b679f6 | 603 | |
ce45eb4c | 604 | (test-assertm "gexp->derivation vs. grafts" |
ef8de985 LC |
605 | (mlet* %store-monad ((graft? (set-grafting #f)) |
606 | (p0 -> (dummy-package "dummy" | |
ce45eb4c LC |
607 | (arguments |
608 | '(#:implicit-inputs? #f)))) | |
609 | (r -> (package (inherit p0) (name "DuMMY"))) | |
610 | (p1 -> (package (inherit p0) (replacement r))) | |
611 | (exp0 -> (gexp (frob (ungexp p0) (ungexp output)))) | |
612 | (exp1 -> (gexp (frob (ungexp p1) (ungexp output)))) | |
613 | (void (set-guile-for-build %bootstrap-guile)) | |
ef8de985 LC |
614 | (drv0 (gexp->derivation "t" exp0 #:graft? #t)) |
615 | (drv1 (gexp->derivation "t" exp1 #:graft? #t)) | |
616 | (drv1* (gexp->derivation "t" exp1 #:graft? #f)) | |
617 | (_ (set-grafting graft?))) | |
ce45eb4c LC |
618 | (return (and (not (string=? (derivation->output-path drv0) |
619 | (derivation->output-path drv1))) | |
620 | (string=? (derivation->output-path drv0) | |
621 | (derivation->output-path drv1*)))))) | |
622 | ||
21b679f6 LC |
623 | (test-assertm "gexp->derivation, composed gexps" |
624 | (mlet* %store-monad ((exp0 -> (gexp (begin | |
625 | (mkdir (ungexp output)) | |
626 | (chdir (ungexp output))))) | |
627 | (exp1 -> (gexp (symlink | |
628 | (string-append (ungexp %bootstrap-guile) | |
629 | "/bin/guile") | |
630 | "foo"))) | |
631 | (exp -> (gexp (begin (ungexp exp0) (ungexp exp1)))) | |
632 | (drv (gexp->derivation "foo" exp)) | |
633 | (out -> (derivation->output-path drv)) | |
634 | (done (built-derivations (list drv))) | |
635 | (guile (package-file %bootstrap-guile "bin/guile"))) | |
636 | (return (string=? (readlink (string-append out "/foo")) | |
637 | guile)))) | |
638 | ||
5d098459 LC |
639 | (test-assertm "gexp->derivation, default system" |
640 | ;; The default system should be the one at '>>=' time, not the one at | |
641 | ;; invocation time. See <http://bugs.gnu.org/18002>. | |
642 | (let ((system (%current-system)) | |
643 | (mdrv (parameterize ((%current-system "foobar64-linux")) | |
644 | (gexp->derivation "foo" | |
645 | (gexp | |
646 | (mkdir (ungexp output))))))) | |
647 | (mlet %store-monad ((drv mdrv)) | |
648 | (return (string=? system (derivation-system drv)))))) | |
649 | ||
d9ae938f LC |
650 | (test-assertm "gexp->derivation, local-file" |
651 | (mlet* %store-monad ((file -> (search-path %load-path "guix.scm")) | |
020f3e41 | 652 | (intd (interned-file file #:recursive? #f)) |
d9ae938f LC |
653 | (local -> (local-file file)) |
654 | (exp -> (gexp (begin | |
655 | (stat (ungexp local)) | |
656 | (symlink (ungexp local) | |
657 | (ungexp output))))) | |
658 | (drv (gexp->derivation "local-file" exp))) | |
659 | (mbegin %store-monad | |
660 | (built-derivations (list drv)) | |
661 | (return (string=? (readlink (derivation->output-path drv)) | |
662 | intd))))) | |
663 | ||
68a61e9f LC |
664 | (test-assertm "gexp->derivation, cross-compilation" |
665 | (mlet* %store-monad ((target -> "mips64el-linux") | |
666 | (exp -> (gexp (list (ungexp coreutils) | |
667 | (ungexp output)))) | |
668 | (xdrv (gexp->derivation "foo" exp | |
669 | #:target target)) | |
e74f64b9 | 670 | (refs (references* |
68a61e9f LC |
671 | (derivation-file-name xdrv))) |
672 | (xcu (package->cross-derivation coreutils | |
673 | target)) | |
674 | (cu (package->derivation coreutils))) | |
675 | (return (and (member (derivation-file-name xcu) refs) | |
676 | (not (member (derivation-file-name cu) refs)))))) | |
677 | ||
667b2508 LC |
678 | (test-assertm "gexp->derivation, ungexp-native" |
679 | (mlet* %store-monad ((target -> "mips64el-linux") | |
680 | (exp -> (gexp (list (ungexp-native coreutils) | |
681 | (ungexp output)))) | |
682 | (xdrv (gexp->derivation "foo" exp | |
683 | #:target target)) | |
684 | (drv (gexp->derivation "foo" exp))) | |
685 | (return (string=? (derivation-file-name drv) | |
686 | (derivation-file-name xdrv))))) | |
687 | ||
688 | (test-assertm "gexp->derivation, ungexp + ungexp-native" | |
689 | (mlet* %store-monad ((target -> "mips64el-linux") | |
690 | (exp -> (gexp (list (ungexp-native coreutils) | |
691 | (ungexp glibc) | |
692 | (ungexp output)))) | |
693 | (xdrv (gexp->derivation "foo" exp | |
694 | #:target target)) | |
e74f64b9 | 695 | (refs (references* |
667b2508 LC |
696 | (derivation-file-name xdrv))) |
697 | (xglibc (package->cross-derivation glibc target)) | |
698 | (cu (package->derivation coreutils))) | |
699 | (return (and (member (derivation-file-name cu) refs) | |
700 | (member (derivation-file-name xglibc) refs))))) | |
701 | ||
702 | (test-assertm "gexp->derivation, ungexp-native + composed gexps" | |
703 | (mlet* %store-monad ((target -> "mips64el-linux") | |
704 | (exp0 -> (gexp (list 1 2 | |
705 | (ungexp coreutils)))) | |
706 | (exp -> (gexp (list 0 (ungexp-native exp0)))) | |
707 | (xdrv (gexp->derivation "foo" exp | |
708 | #:target target)) | |
709 | (drv (gexp->derivation "foo" exp))) | |
710 | (return (string=? (derivation-file-name drv) | |
711 | (derivation-file-name xdrv))))) | |
712 | ||
6fd1a796 LC |
713 | (test-assertm "gexp->derivation, store copy" |
714 | (let ((build-one #~(call-with-output-file #$output | |
715 | (lambda (port) | |
716 | (display "This is the one." port)))) | |
717 | (build-two (lambda (one) | |
718 | #~(begin | |
719 | (mkdir #$output) | |
720 | (symlink #$one (string-append #$output "/one")) | |
721 | (call-with-output-file (string-append #$output "/two") | |
722 | (lambda (port) | |
723 | (display "This is the second one." port)))))) | |
b53833b2 LC |
724 | (build-drv #~(begin |
725 | (use-modules (guix build store-copy)) | |
6fd1a796 | 726 | |
b53833b2 LC |
727 | (mkdir #$output) |
728 | (populate-store '("graph") #$output)))) | |
6fd1a796 LC |
729 | (mlet* %store-monad ((one (gexp->derivation "one" build-one)) |
730 | (two (gexp->derivation "two" (build-two one))) | |
b53833b2 | 731 | (drv (gexp->derivation "store-copy" build-drv |
6fd1a796 | 732 | #:references-graphs |
b53833b2 | 733 | `(("graph" ,two)) |
6fd1a796 LC |
734 | #:modules |
735 | '((guix build store-copy) | |
d4e9317b LC |
736 | (guix progress) |
737 | (guix records) | |
6892f0a2 | 738 | (guix sets) |
6fd1a796 LC |
739 | (guix build utils)))) |
740 | (ok? (built-derivations (list drv))) | |
741 | (out -> (derivation->output-path drv))) | |
742 | (let ((one (derivation->output-path one)) | |
743 | (two (derivation->output-path two))) | |
744 | (return (and ok? | |
745 | (file-exists? (string-append out "/" one)) | |
746 | (file-exists? (string-append out "/" two)) | |
747 | (file-exists? (string-append out "/" two "/two")) | |
748 | (string=? (readlink (string-append out "/" two "/one")) | |
749 | one))))))) | |
750 | ||
aa72d9af LC |
751 | (test-assertm "imported-files" |
752 | (mlet* %store-monad | |
753 | ((files -> `(("x" . ,(search-path %load-path "ice-9/q.scm")) | |
754 | ("a/b/c" . ,(search-path %load-path | |
755 | "guix/derivations.scm")) | |
756 | ("p/q" . ,(search-path %load-path "guix.scm")) | |
757 | ("p/z" . ,(search-path %load-path "guix/store.scm")))) | |
8df2eca6 | 758 | (dir (imported-files files))) |
aa72d9af | 759 | (mbegin %store-monad |
8df2eca6 LC |
760 | (return |
761 | (every (match-lambda | |
762 | ((path . source) | |
763 | (equal? (call-with-input-file (string-append dir "/" path) | |
764 | get-bytevector-all) | |
765 | (call-with-input-file source | |
766 | get-bytevector-all)))) | |
767 | files))))) | |
aa72d9af | 768 | |
d938a58b LC |
769 | (test-assertm "imported-files with file-like objects" |
770 | (mlet* %store-monad ((plain -> (plain-file "foo" "bar!")) | |
771 | (q-scm -> (search-path %load-path "ice-9/q.scm")) | |
772 | (files -> `(("a/b/c" . ,q-scm) | |
773 | ("p/q" . ,plain))) | |
774 | (drv (imported-files files))) | |
e529d468 LC |
775 | (define (file=? file1 file2) |
776 | ;; Assume deduplication is in place. | |
8c7bebd6 LC |
777 | (= (stat:ino (stat file1)) |
778 | (stat:ino (stat file2)))) | |
e529d468 | 779 | |
d938a58b | 780 | (mbegin %store-monad |
8c7bebd6 | 781 | (built-derivations (list (pk 'drv drv))) |
d938a58b LC |
782 | (mlet %store-monad ((dir -> (derivation->output-path drv)) |
783 | (plain* (text-file "foo" "bar!")) | |
784 | (q-scm* (interned-file q-scm "c"))) | |
785 | (return | |
e529d468 LC |
786 | (and (file=? (string-append dir "/a/b/c") q-scm*) |
787 | (file=? (string-append dir "/p/q") plain*))))))) | |
d938a58b | 788 | |
0bb9929e LC |
789 | (test-equal "gexp-modules & ungexp" |
790 | '((bar) (foo)) | |
791 | ((@@ (guix gexp) gexp-modules) | |
792 | #~(foo #$(with-imported-modules '((foo)) #~+) | |
793 | #+(with-imported-modules '((bar)) #~-)))) | |
794 | ||
795 | (test-equal "gexp-modules & ungexp-splicing" | |
796 | '((foo) (bar)) | |
797 | ((@@ (guix gexp) gexp-modules) | |
798 | #~(foo #$@(list (with-imported-modules '((foo)) #~+) | |
799 | (with-imported-modules '((bar)) #~-))))) | |
800 | ||
932d1600 LC |
801 | (test-assert "gexp-modules deletes duplicates" ;<https://bugs.gnu.org/32966> |
802 | (let ((make-file (lambda () | |
803 | ;; Use 'eval' to make sure we get an object that's not | |
804 | ;; 'eq?' nor 'equal?' due to the closures it embeds. | |
805 | (eval '(scheme-file "bar.scm" #~(define-module (bar))) | |
806 | (current-module))))) | |
807 | (define result | |
808 | ((@@ (guix gexp) gexp-modules) | |
809 | (with-imported-modules `(((bar) => ,(make-file)) | |
810 | ((bar) => ,(make-file)) | |
811 | (foo) (foo)) | |
812 | #~+))) | |
813 | ||
814 | (match result | |
815 | (((('bar) '=> (? scheme-file?)) ('foo)) #t)))) | |
816 | ||
2363bdd7 LC |
817 | (test-equal "gexp-modules and literal Scheme object" |
818 | '() | |
819 | (gexp-modules #t)) | |
820 | ||
aa72d9af LC |
821 | (test-assertm "gexp->derivation #:modules" |
822 | (mlet* %store-monad | |
823 | ((build -> #~(begin | |
824 | (use-modules (guix build utils)) | |
825 | (mkdir-p (string-append #$output "/guile/guix/nix")) | |
826 | #t)) | |
827 | (drv (gexp->derivation "test-with-modules" build | |
828 | #:modules '((guix build utils))))) | |
829 | (mbegin %store-monad | |
830 | (built-derivations (list drv)) | |
831 | (let* ((p (derivation->output-path drv)) | |
832 | (s (stat (string-append p "/guile/guix/nix")))) | |
833 | (return (eq? (stat:type s) 'directory)))))) | |
834 | ||
0bb9929e LC |
835 | (test-assertm "gexp->derivation & with-imported-modules" |
836 | ;; Same test as above, but using 'with-imported-modules'. | |
837 | (mlet* %store-monad | |
838 | ((build -> (with-imported-modules '((guix build utils)) | |
839 | #~(begin | |
840 | (use-modules (guix build utils)) | |
841 | (mkdir-p (string-append #$output "/guile/guix/nix")) | |
842 | #t))) | |
843 | (drv (gexp->derivation "test-with-modules" build))) | |
844 | (mbegin %store-monad | |
845 | (built-derivations (list drv)) | |
846 | (let* ((p (derivation->output-path drv)) | |
847 | (s (stat (string-append p "/guile/guix/nix")))) | |
848 | (return (eq? (stat:type s) 'directory)))))) | |
849 | ||
850 | (test-assertm "gexp->derivation & nested with-imported-modules" | |
851 | (mlet* %store-monad | |
852 | ((build1 -> (with-imported-modules '((guix build utils)) | |
853 | #~(begin | |
854 | (use-modules (guix build utils)) | |
855 | (mkdir-p (string-append #$output "/guile/guix/nix")) | |
856 | #t))) | |
857 | (build2 -> (with-imported-modules '((guix build bournish)) | |
858 | #~(begin | |
859 | (use-modules (guix build bournish) | |
860 | (system base compile)) | |
861 | #+build1 | |
862 | (call-with-output-file (string-append #$output "/b") | |
863 | (lambda (port) | |
864 | (write | |
865 | (read-and-compile (open-input-string "cd /foo") | |
866 | #:from %bournish-language | |
867 | #:to 'scheme) | |
868 | port)))))) | |
869 | (drv (gexp->derivation "test-with-modules" build2))) | |
870 | (mbegin %store-monad | |
871 | (built-derivations (list drv)) | |
872 | (let* ((p (derivation->output-path drv)) | |
873 | (s (stat (string-append p "/guile/guix/nix"))) | |
874 | (b (string-append p "/b"))) | |
875 | (return (and (eq? (stat:type s) 'directory) | |
876 | (equal? '(chdir "/foo") | |
877 | (call-with-input-file b read)))))))) | |
878 | ||
d938a58b LC |
879 | (test-assertm "gexp->derivation & with-imported-module & computed module" |
880 | (mlet* %store-monad | |
4fbd1a2b | 881 | ((module -> (scheme-file "x" #~(;; splice! |
d938a58b LC |
882 | (define-module (foo bar) |
883 | #:export (the-answer)) | |
884 | ||
4fbd1a2b LC |
885 | (define the-answer 42)) |
886 | #:splice? #t)) | |
d938a58b LC |
887 | (build -> (with-imported-modules `(((foo bar) => ,module) |
888 | (guix build utils)) | |
889 | #~(begin | |
890 | (use-modules (guix build utils) | |
891 | (foo bar)) | |
892 | mkdir-p | |
893 | (call-with-output-file #$output | |
894 | (lambda (port) | |
895 | (write the-answer port)))))) | |
896 | (drv (gexp->derivation "thing" build)) | |
897 | (out -> (derivation->output-path drv))) | |
898 | (mbegin %store-monad | |
899 | (built-derivations (list drv)) | |
900 | (return (= 42 (call-with-input-file out read)))))) | |
901 | ||
838e17d8 LC |
902 | (test-equal "gexp-extensions & ungexp" |
903 | (list sed grep) | |
904 | ((@@ (guix gexp) gexp-extensions) | |
905 | #~(foo #$(with-extensions (list grep) #~+) | |
906 | #+(with-extensions (list sed) #~-)))) | |
907 | ||
908 | (test-equal "gexp-extensions & ungexp-splicing" | |
909 | (list grep sed) | |
910 | ((@@ (guix gexp) gexp-extensions) | |
911 | #~(foo #$@(list (with-extensions (list grep) #~+) | |
912 | (with-imported-modules '((foo)) | |
913 | (with-extensions (list sed) #~-)))))) | |
914 | ||
915 | (test-equal "gexp-extensions and literal Scheme object" | |
916 | '() | |
917 | ((@@ (guix gexp) gexp-extensions) #t)) | |
918 | ||
919 | (test-assertm "gexp->derivation & with-extensions" | |
920 | ;; Create a fake Guile extension and make sure it is accessible both to the | |
921 | ;; imported modules and to the derivation build script. | |
922 | (mlet* %store-monad | |
923 | ((extension -> %extension-package) | |
924 | (module -> (scheme-file "x" #~( ;; splice! | |
925 | (define-module (foo) | |
926 | #:use-module (hg2g) | |
927 | #:export (multiply)) | |
928 | ||
929 | (define (multiply x) | |
930 | (* the-answer x))) | |
931 | #:splice? #t)) | |
932 | (build -> (with-extensions (list extension) | |
933 | (with-imported-modules `((guix build utils) | |
934 | ((foo) => ,module)) | |
935 | #~(begin | |
936 | (use-modules (guix build utils) | |
937 | (hg2g) (foo)) | |
938 | (call-with-output-file #$output | |
939 | (lambda (port) | |
940 | (write (list the-answer (multiply 2)) | |
941 | port))))))) | |
942 | (drv (gexp->derivation "thingie" build | |
943 | ;; %BOOTSTRAP-GUILE is 2.0. | |
944 | #:effective-version "2.0")) | |
945 | (out -> (derivation->output-path drv))) | |
946 | (mbegin %store-monad | |
947 | (built-derivations (list drv)) | |
948 | (return (equal? '(42 84) (call-with-input-file out read)))))) | |
949 | ||
2ca41030 LC |
950 | (test-assertm "lower-gexp" |
951 | (mlet* %store-monad | |
952 | ((extension -> %extension-package) | |
953 | (extension-drv (package->derivation %extension-package)) | |
954 | (coreutils-drv (package->derivation coreutils)) | |
955 | (exp -> (with-extensions (list extension) | |
956 | (with-imported-modules `((guix build utils)) | |
957 | #~(begin | |
958 | (use-modules (guix build utils) | |
959 | (hg2g)) | |
960 | #$coreutils:debug | |
961 | mkdir-p | |
962 | the-answer)))) | |
963 | (lexp (lower-gexp exp | |
964 | #:effective-version "2.0"))) | |
965 | (define (matching-input drv output) | |
966 | (lambda (input) | |
38685774 LC |
967 | (and (eq? (derivation-input-derivation input) drv) |
968 | (equal? (derivation-input-sub-derivations input) | |
969 | (list output))))) | |
2ca41030 LC |
970 | |
971 | (mbegin %store-monad | |
972 | (return (and (find (matching-input extension-drv "out") | |
973 | (lowered-gexp-inputs (pk 'lexp lexp))) | |
974 | (find (matching-input coreutils-drv "debug") | |
975 | (lowered-gexp-inputs lexp)) | |
976 | (member (string-append | |
977 | (derivation->output-path extension-drv) | |
978 | "/share/guile/site/2.0") | |
979 | (lowered-gexp-load-path lexp)) | |
980 | (= 2 (length (lowered-gexp-load-path lexp))) | |
981 | (member (string-append | |
982 | (derivation->output-path extension-drv) | |
983 | "/lib/guile/2.0/site-ccache") | |
984 | (lowered-gexp-load-compiled-path lexp)) | |
985 | (= 2 (length (lowered-gexp-load-compiled-path lexp))) | |
b9373e26 LC |
986 | (eq? (derivation-input-derivation (lowered-gexp-guile lexp)) |
987 | (%guile-for-build))))))) | |
2ca41030 | 988 | |
d63ee94d LC |
989 | (test-assertm "lower-gexp, raw-derivation-file" |
990 | (mlet* %store-monad ((thing -> (program-file "prog" #~(display "hi!"))) | |
991 | (exp -> #~(list #$(raw-derivation-file thing))) | |
992 | (drv (lower-object thing)) | |
993 | (lexp (lower-gexp exp #:effective-version "2.0"))) | |
994 | (return (and (equal? `(list ,(derivation-file-name drv)) | |
995 | (lowered-gexp-sexp lexp)) | |
996 | (equal? (list (derivation-file-name drv)) | |
997 | (lowered-gexp-sources lexp)) | |
998 | (null? (lowered-gexp-inputs lexp)))))) | |
999 | ||
24ab804c LC |
1000 | (test-eq "lower-gexp, non-self-quoting input" |
1001 | + | |
1002 | (guard (c ((gexp-input-error? c) | |
1003 | (gexp-error-invalid-input c))) | |
1004 | (run-with-store %store | |
1005 | (lower-gexp #~(foo #$+))))) | |
1006 | ||
ab7010af MB |
1007 | (test-equal "lower-gexp, character literal" |
1008 | '(#\+) | |
1009 | (lowered-gexp-sexp | |
1010 | (run-with-store %store | |
1011 | (lower-gexp #~(#\+))))) | |
1012 | ||
b53833b2 LC |
1013 | (test-assertm "gexp->derivation #:references-graphs" |
1014 | (mlet* %store-monad | |
72cd8ec0 | 1015 | ((one (text-file "one" (random-text))) |
b53833b2 LC |
1016 | (two (gexp->derivation "two" |
1017 | #~(symlink #$one #$output:chbouib))) | |
66a35ceb | 1018 | (build -> (with-imported-modules '((guix build store-copy) |
d4e9317b LC |
1019 | (guix progress) |
1020 | (guix records) | |
6892f0a2 | 1021 | (guix sets) |
66a35ceb LC |
1022 | (guix build utils)) |
1023 | #~(begin | |
1024 | (use-modules (guix build store-copy)) | |
1025 | (with-output-to-file #$output | |
1026 | (lambda () | |
6892f0a2 LC |
1027 | (write (map store-info-item |
1028 | (call-with-input-file "guile" | |
1029 | read-reference-graph))))) | |
66a35ceb LC |
1030 | (with-output-to-file #$output:one |
1031 | (lambda () | |
6892f0a2 LC |
1032 | (write (map store-info-item |
1033 | (call-with-input-file "one" | |
1034 | read-reference-graph))))) | |
66a35ceb LC |
1035 | (with-output-to-file #$output:two |
1036 | (lambda () | |
6892f0a2 LC |
1037 | (write (map store-info-item |
1038 | (call-with-input-file "two" | |
1039 | read-reference-graph)))))))) | |
66a35ceb | 1040 | (drv (gexp->derivation "ref-graphs" build |
b53833b2 LC |
1041 | #:references-graphs `(("one" ,one) |
1042 | ("two" ,two "chbouib") | |
66a35ceb | 1043 | ("guile" ,%bootstrap-guile)))) |
b53833b2 LC |
1044 | (ok? (built-derivations (list drv))) |
1045 | (guile-drv (package->derivation %bootstrap-guile)) | |
686784d0 LC |
1046 | (bash (interned-file (search-bootstrap-binary "bash" |
1047 | (%current-system)) | |
1048 | "bash" #:recursive? #t)) | |
b53833b2 LC |
1049 | (g-one -> (derivation->output-path drv "one")) |
1050 | (g-two -> (derivation->output-path drv "two")) | |
1051 | (g-guile -> (derivation->output-path drv))) | |
1052 | (return (and ok? | |
1053 | (equal? (call-with-input-file g-one read) (list one)) | |
72cd8ec0 LC |
1054 | (lset= string=? |
1055 | (call-with-input-file g-two read) | |
1056 | (list one (derivation->output-path two "chbouib"))) | |
686784d0 LC |
1057 | |
1058 | ;; Note: %BOOTSTRAP-GUILE depends on the bootstrap Bash. | |
72cd8ec0 LC |
1059 | (lset= string=? |
1060 | (call-with-input-file g-guile read) | |
1061 | (list (derivation->output-path guile-drv) bash)))))) | |
b53833b2 | 1062 | |
c8351d9a LC |
1063 | (test-assertm "gexp->derivation #:allowed-references" |
1064 | (mlet %store-monad ((drv (gexp->derivation "allowed-refs" | |
1065 | #~(begin | |
1066 | (mkdir #$output) | |
1067 | (chdir #$output) | |
1068 | (symlink #$output "self") | |
1069 | (symlink #$%bootstrap-guile | |
1070 | "guile")) | |
1071 | #:allowed-references | |
1072 | (list "out" %bootstrap-guile)))) | |
1073 | (built-derivations (list drv)))) | |
1074 | ||
accb682c LC |
1075 | (test-assertm "gexp->derivation #:allowed-references, specific output" |
1076 | (mlet* %store-monad ((in (gexp->derivation "thing" | |
1077 | #~(begin | |
1078 | (mkdir #$output:ok) | |
1079 | (mkdir #$output:not-ok)))) | |
1080 | (drv (gexp->derivation "allowed-refs" | |
1081 | #~(begin | |
1082 | (pk #$in:not-ok) | |
1083 | (mkdir #$output) | |
1084 | (chdir #$output) | |
1085 | (symlink #$output "self") | |
1086 | (symlink #$in:ok "ok")) | |
1087 | #:allowed-references | |
1088 | (list "out" | |
1089 | (gexp-input in "ok"))))) | |
1090 | (built-derivations (list drv)))) | |
1091 | ||
c8351d9a LC |
1092 | (test-assert "gexp->derivation #:allowed-references, disallowed" |
1093 | (let ((drv (run-with-store %store | |
1094 | (gexp->derivation "allowed-refs" | |
1095 | #~(begin | |
1096 | (mkdir #$output) | |
1097 | (chdir #$output) | |
1098 | (symlink #$%bootstrap-guile "guile")) | |
1099 | #:allowed-references '())))) | |
f9e8a123 | 1100 | (guard (c ((store-protocol-error? c) #t)) |
c8351d9a LC |
1101 | (build-derivations %store (list drv)) |
1102 | #f))) | |
1103 | ||
3f4ecf32 LC |
1104 | (test-assertm "gexp->derivation #:disallowed-references, allowed" |
1105 | (mlet %store-monad ((drv (gexp->derivation "disallowed-refs" | |
1106 | #~(begin | |
1107 | (mkdir #$output) | |
1108 | (chdir #$output) | |
1109 | (symlink #$output "self") | |
1110 | (symlink #$%bootstrap-guile | |
1111 | "guile")) | |
1112 | #:disallowed-references '()))) | |
1113 | (built-derivations (list drv)))) | |
1114 | ||
1115 | ||
1116 | (test-assert "gexp->derivation #:disallowed-references" | |
1117 | (let ((drv (run-with-store %store | |
1118 | (gexp->derivation "disallowed-refs" | |
1119 | #~(begin | |
1120 | (mkdir #$output) | |
1121 | (chdir #$output) | |
1122 | (symlink #$%bootstrap-guile "guile")) | |
1123 | #:disallowed-references (list %bootstrap-guile))))) | |
f9e8a123 | 1124 | (guard (c ((store-protocol-error? c) #t)) |
3f4ecf32 LC |
1125 | (build-derivations %store (list drv)) |
1126 | #f))) | |
1127 | ||
c17b5ab4 | 1128 | (define shebang |
c1bc358f | 1129 | (string-append "#!" (derivation->output-path (%guile-for-build)) |
c17b5ab4 LC |
1130 | "/bin/guile --no-auto-compile")) |
1131 | ||
1132 | ;; If we're going to hit the silly shebang limit (128 chars on Linux-based | |
1133 | ;; systems), then skip the following test. | |
47b3124a | 1134 | (test-skip (if (> (string-length shebang) 127) 2 0)) |
c17b5ab4 | 1135 | |
21b679f6 LC |
1136 | (test-assertm "gexp->script" |
1137 | (mlet* %store-monad ((n -> (random (expt 2 50))) | |
1138 | (exp -> (gexp | |
1139 | (system* | |
1140 | (string-append (ungexp %bootstrap-guile) | |
1141 | "/bin/guile") | |
1142 | "-c" (object->string | |
1143 | '(display (expt (ungexp n) 2)))))) | |
1144 | (drv (gexp->script "guile-thing" exp | |
1145 | #:guile %bootstrap-guile)) | |
1146 | (out -> (derivation->output-path drv)) | |
1147 | (done (built-derivations (list drv)))) | |
1148 | (let* ((pipe (open-input-pipe out)) | |
1149 | (str (get-string-all pipe))) | |
1150 | (return (and (zero? (close-pipe pipe)) | |
1151 | (= (expt n 2) (string->number str))))))) | |
1152 | ||
92bcccc5 | 1153 | (test-assert "gexp->script #:module-path" |
1ae16033 LC |
1154 | (call-with-temporary-directory |
1155 | (lambda (directory) | |
1156 | (define str | |
1157 | "Fake (guix base32) module!") | |
1158 | ||
1159 | (mkdir (string-append directory "/guix")) | |
1160 | (call-with-output-file (string-append directory "/guix/base32.scm") | |
1161 | (lambda (port) | |
1162 | (write `(begin (define-module (guix base32)) | |
1163 | (define-public %fake! ,str)) | |
1164 | port))) | |
1165 | ||
92bcccc5 LF |
1166 | (run-with-store %store |
1167 | (mlet* %store-monad ((exp -> (with-imported-modules '((guix base32)) | |
1168 | (gexp (begin | |
1169 | (use-modules (guix base32)) | |
1170 | (write (list %load-path | |
1171 | %fake!)))))) | |
1172 | (drv (gexp->script "guile-thing" exp | |
1173 | #:guile %bootstrap-guile | |
1174 | #:module-path (list directory))) | |
1175 | (out -> (derivation->output-path drv)) | |
1176 | (done (built-derivations (list drv)))) | |
1177 | (let* ((pipe (open-input-pipe out)) | |
1178 | (data (read pipe))) | |
1179 | (return (and (zero? (close-pipe pipe)) | |
1180 | (match data | |
1181 | ((load-path str*) | |
1182 | (and (string=? str* str) | |
1183 | (not (member directory load-path))))))))))))) | |
1ae16033 | 1184 | |
15a01c72 LC |
1185 | (test-assertm "program-file" |
1186 | (let* ((n (random (expt 2 50))) | |
0bb9929e LC |
1187 | (exp (with-imported-modules '((guix build utils)) |
1188 | (gexp (begin | |
1189 | (use-modules (guix build utils)) | |
1190 | (display (ungexp n)))))) | |
15a01c72 | 1191 | (file (program-file "program" exp |
15a01c72 LC |
1192 | #:guile %bootstrap-guile))) |
1193 | (mlet* %store-monad ((drv (lower-object file)) | |
1194 | (out -> (derivation->output-path drv))) | |
1195 | (mbegin %store-monad | |
1196 | (built-derivations (list drv)) | |
1197 | (let* ((pipe (open-input-pipe out)) | |
1198 | (str (get-string-all pipe))) | |
1199 | (return (and (zero? (close-pipe pipe)) | |
1200 | (= n (string->number str))))))))) | |
1201 | ||
92bcccc5 | 1202 | (test-assert "program-file #:module-path" |
427ec19e LC |
1203 | (call-with-temporary-directory |
1204 | (lambda (directory) | |
1205 | (define text (random-text)) | |
1206 | ||
1207 | (call-with-output-file (string-append directory "/stupid-module.scm") | |
1208 | (lambda (port) | |
1209 | (write `(begin (define-module (stupid-module)) | |
1210 | (define-public %stupid-thing ,text)) | |
1211 | port))) | |
1212 | ||
1213 | (let* ((exp (with-imported-modules '((stupid-module)) | |
1214 | (gexp (begin | |
1215 | (use-modules (stupid-module)) | |
1216 | (display %stupid-thing))))) | |
1217 | (file (program-file "program" exp | |
1218 | #:guile %bootstrap-guile | |
1219 | #:module-path (list directory)))) | |
92bcccc5 LF |
1220 | (run-with-store %store |
1221 | (mlet* %store-monad ((drv (lower-object file)) | |
1222 | (out -> (derivation->output-path drv))) | |
1223 | (mbegin %store-monad | |
1224 | (built-derivations (list drv)) | |
1225 | (let* ((pipe (open-input-pipe out)) | |
1226 | (str (get-string-all pipe))) | |
1227 | (return (and (zero? (close-pipe pipe)) | |
1228 | (string=? text str))))))))))) | |
427ec19e | 1229 | |
838e17d8 LC |
1230 | (test-assertm "program-file & with-extensions" |
1231 | (let* ((exp (with-extensions (list %extension-package) | |
1232 | (gexp (begin | |
1233 | (use-modules (hg2g)) | |
1234 | (display the-answer))))) | |
1235 | (file (program-file "program" exp | |
1236 | #:guile %bootstrap-guile))) | |
1237 | (mlet* %store-monad ((drv (lower-object file)) | |
1238 | (out -> (derivation->output-path drv))) | |
1239 | (mbegin %store-monad | |
1240 | (built-derivations (list drv)) | |
1241 | (let* ((pipe (open-input-pipe out)) | |
1242 | (str (get-string-all pipe))) | |
1243 | (return (and (zero? (close-pipe pipe)) | |
1244 | (= 42 (string->number str))))))))) | |
1245 | ||
2e8cabb8 LC |
1246 | (test-assertm "program-file #:system" |
1247 | (let* ((exp (with-imported-modules '((guix build utils)) | |
1248 | (gexp (begin | |
1249 | (use-modules (guix build utils)) | |
1250 | (display "hi!"))))) | |
1251 | (system (if (string=? (%current-system) "x86_64-linux") | |
1252 | "armhf-linux" | |
1253 | "x86_64-linux")) | |
1254 | (file (program-file "program" exp))) | |
1255 | (mlet %store-monad ((drv (lower-object file system))) | |
1256 | (return (and (string=? (derivation-system drv) system) | |
1257 | (find (lambda (input) | |
1258 | (let ((drv (pk (derivation-input-derivation input)))) | |
1259 | (and (string=? (derivation-name drv) | |
1260 | "module-import-compiled") | |
1261 | (string=? (derivation-system drv) | |
1262 | system)))) | |
1263 | (derivation-inputs drv))))))) | |
1264 | ||
e1c153e0 LC |
1265 | (test-assertm "scheme-file" |
1266 | (let* ((text (plain-file "foo" "Hello, world!")) | |
1267 | (scheme (scheme-file "bar" #~(list "foo" #$text)))) | |
1268 | (mlet* %store-monad ((drv (lower-object scheme)) | |
1269 | (text (lower-object text)) | |
1270 | (out -> (derivation->output-path drv))) | |
1271 | (mbegin %store-monad | |
1272 | (built-derivations (list drv)) | |
e74f64b9 | 1273 | (mlet %store-monad ((refs (references* out))) |
e1c153e0 LC |
1274 | (return (and (equal? refs (list text)) |
1275 | (equal? `(list "foo" ,text) | |
1276 | (call-with-input-file out read))))))))) | |
1277 | ||
d63ee94d LC |
1278 | (test-assertm "raw-derivation-file" |
1279 | (let* ((exp #~(let ((drv #$(raw-derivation-file coreutils))) | |
1280 | (when (file-exists? drv) | |
1281 | (symlink drv #$output))))) | |
1282 | (mlet* %store-monad ((dep (lower-object coreutils)) | |
1283 | (drv (gexp->derivation "drv-ref" exp)) | |
1284 | (out -> (derivation->output-path drv))) | |
1285 | (mbegin %store-monad | |
1286 | (built-derivations (list drv)) | |
1287 | (mlet %store-monad ((refs (references* out))) | |
1288 | (return (and (member (derivation-file-name dep) | |
1289 | (derivation-sources drv)) | |
1290 | (not (member (derivation-file-name dep) | |
1291 | (map derivation-input-path | |
1292 | (derivation-inputs drv)))) | |
1293 | (equal? (readlink out) (derivation-file-name dep)) | |
1294 | (equal? refs (list (derivation-file-name dep)))))))))) | |
1295 | ||
462a3fa3 | 1296 | (test-assert "text-file*" |
e74f64b9 LC |
1297 | (run-with-store %store |
1298 | (mlet* %store-monad | |
1299 | ((drv (package->derivation %bootstrap-guile)) | |
1300 | (guile -> (derivation->output-path drv)) | |
1301 | (file (text-file "bar" "This is bar.")) | |
1302 | (text (text-file* "foo" | |
1303 | %bootstrap-guile "/bin/guile " | |
1304 | (gexp-input %bootstrap-guile "out") "/bin/guile " | |
1305 | drv "/bin/guile " | |
1306 | file)) | |
1307 | (done (built-derivations (list text))) | |
1308 | (out -> (derivation->output-path text)) | |
1309 | (refs (references* out))) | |
1310 | ;; Make sure we get the right references and the right content. | |
1311 | (return (and (lset= string=? refs (list guile file)) | |
1312 | (equal? (call-with-input-file out get-string-all) | |
1313 | (string-append guile "/bin/guile " | |
1314 | guile "/bin/guile " | |
1315 | guile "/bin/guile " | |
1316 | file))))) | |
1317 | #:guile-for-build (package-derivation %store %bootstrap-guile))) | |
462a3fa3 | 1318 | |
b751cde3 LC |
1319 | (test-assertm "mixed-text-file" |
1320 | (mlet* %store-monad ((file -> (mixed-text-file "mixed" | |
1321 | "export PATH=" | |
1322 | %bootstrap-guile "/bin")) | |
1323 | (drv (lower-object file)) | |
1324 | (out -> (derivation->output-path drv)) | |
1325 | (guile-drv (package->derivation %bootstrap-guile)) | |
1326 | (guile -> (derivation->output-path guile-drv))) | |
1327 | (mbegin %store-monad | |
1328 | (built-derivations (list drv)) | |
e74f64b9 | 1329 | (mlet %store-monad ((refs (references* out))) |
b751cde3 LC |
1330 | (return (and (string=? (string-append "export PATH=" guile "/bin") |
1331 | (call-with-input-file out get-string-all)) | |
1332 | (equal? refs (list guile)))))))) | |
1333 | ||
5dec93bb LC |
1334 | (test-assertm "file-union" |
1335 | (mlet* %store-monad ((union -> (file-union "union" | |
1336 | `(("a" ,(plain-file "a" "1")) | |
1337 | ("b/c/d" ,(plain-file "d" "2")) | |
1338 | ("e" ,(plain-file "e" "3"))))) | |
1339 | (drv (lower-object union)) | |
1340 | (out -> (derivation->output-path drv))) | |
1341 | (define (contents=? file str) | |
1342 | (string=? (call-with-input-file (string-append out "/" file) | |
1343 | get-string-all) | |
1344 | str)) | |
1345 | ||
1346 | (mbegin %store-monad | |
1347 | (built-derivations (list drv)) | |
1348 | (return (and (contents=? "a" "1") | |
1349 | (contents=? "b/c/d" "2") | |
1350 | (contents=? "e" "3")))))) | |
1351 | ||
a8afb9ae LC |
1352 | (test-assert "gexp->derivation vs. %current-target-system" |
1353 | (let ((mval (gexp->derivation "foo" | |
1354 | #~(begin | |
1355 | (mkdir #$output) | |
1356 | (foo #+gnu-make)) | |
1357 | #:target #f))) | |
1358 | ;; The value of %CURRENT-TARGET-SYSTEM at bind-time should have no | |
1359 | ;; influence. | |
1360 | (parameterize ((%current-target-system "fooooo")) | |
1361 | (derivation? (run-with-store %store mval))))) | |
1362 | ||
c2b84676 LC |
1363 | (test-assertm "lower-object" |
1364 | (mlet %store-monad ((drv1 (lower-object %bootstrap-guile)) | |
1365 | (drv2 (lower-object (package-source coreutils))) | |
1366 | (item (lower-object (plain-file "foo" "Hello!")))) | |
1367 | (return (and (derivation? drv1) (derivation? drv2) | |
1368 | (store-path? item))))) | |
1369 | ||
91937029 LC |
1370 | (test-assertm "lower-object, computed-file" |
1371 | (let* ((text (plain-file "foo" "Hello!")) | |
1372 | (exp #~(begin | |
1373 | (mkdir #$output) | |
1374 | (symlink #$%bootstrap-guile | |
1375 | (string-append #$output "/guile")) | |
1376 | (symlink #$text (string-append #$output "/text")))) | |
1377 | (computed (computed-file "computed" exp))) | |
1378 | (mlet* %store-monad ((text (lower-object text)) | |
1379 | (guile-drv (lower-object %bootstrap-guile)) | |
1380 | (comp-drv (lower-object computed)) | |
1381 | (comp -> (derivation->output-path comp-drv))) | |
1382 | (mbegin %store-monad | |
1383 | (built-derivations (list comp-drv)) | |
1384 | (return (and (string=? (readlink (string-append comp "/guile")) | |
1385 | (derivation->output-path guile-drv)) | |
1386 | (string=? (readlink (string-append comp "/text")) | |
1387 | text))))))) | |
1388 | ||
9ec154f5 LC |
1389 | (test-equal "lower-object, computed-file, #:system" |
1390 | '("mips64el-linux") | |
1391 | (run-with-store %store | |
1392 | (let* ((exp #~(symlink #$coreutils #$output)) | |
1393 | (computed (computed-file "computed" exp | |
1394 | #:guile %bootstrap-guile))) | |
1395 | ;; Make sure that the SYSTEM argument to 'lower-object' is honored. | |
1396 | (mlet* %store-monad ((drv (lower-object computed "mips64el-linux")) | |
1397 | (refs (references* (derivation-file-name drv)))) | |
1398 | (return (delete-duplicates | |
1399 | (filter-map (lambda (file) | |
1400 | (and (string-suffix? ".drv" file) | |
1401 | (let ((drv (read-derivation-from-file | |
1402 | file))) | |
1403 | (derivation-system drv)))) | |
1404 | (cons (derivation-file-name drv) | |
1405 | refs)))))))) | |
1406 | ||
3e43166f LC |
1407 | (test-assert "lower-object & gexp-input-error?" |
1408 | (guard (c ((gexp-input-error? c) | |
1409 | (gexp-error-invalid-input c))) | |
1410 | (run-with-store %store | |
1411 | (lower-object (current-module)) | |
1412 | #:guile-for-build (%guile-for-build)))) | |
1413 | ||
2cf0ea0d LC |
1414 | (test-assert "printer" |
1415 | (string-match "^#<gexp \\(string-append .*#<package coreutils.*\ | |
1416 | \"/bin/uname\"\\) [[:xdigit:]]+>$" | |
1417 | (with-output-to-string | |
1418 | (lambda () | |
1419 | (write | |
1420 | (gexp (string-append (ungexp coreutils) | |
1421 | "/bin/uname"))))))) | |
1422 | ||
1423 | (test-assert "printer vs. ungexp-splicing" | |
1424 | (string-match "^#<gexp .* [[:xdigit:]]+>$" | |
1425 | (with-output-to-string | |
1426 | (lambda () | |
1427 | ;; #~(begin #$@#~()) | |
1428 | (write | |
1429 | (gexp (begin (ungexp-splicing (gexp ()))))))))) | |
1430 | ||
21b679f6 LC |
1431 | (test-equal "sugar" |
1432 | '(gexp (foo (ungexp bar) (ungexp baz "out") | |
1433 | (ungexp (chbouib 42)) | |
667b2508 LC |
1434 | (ungexp-splicing (list x y z)) |
1435 | (ungexp-native foo) (ungexp-native foo "out") | |
1436 | (ungexp-native (chbouib 42)) | |
1437 | (ungexp-native-splicing (list x y z)))) | |
1438 | '#~(foo #$bar #$baz:out #$(chbouib 42) #$@(list x y z) | |
1439 | #+foo #+foo:out #+(chbouib 42) #+@(list x y z))) | |
21b679f6 | 1440 | |
9a2f99f4 MO |
1441 | (test-assertm "gexp->file, cross-compilation" |
1442 | (mlet* %store-monad ((target -> "aarch64-linux-gnu") | |
1443 | (exp -> (gexp (list (ungexp coreutils)))) | |
1444 | (xdrv (gexp->file "foo" exp #:target target)) | |
1445 | (refs (references* | |
1446 | (derivation-file-name xdrv))) | |
1447 | (xcu (package->cross-derivation coreutils | |
1448 | target)) | |
1449 | (cu (package->derivation coreutils))) | |
1450 | (return (and (member (derivation-file-name xcu) refs) | |
1451 | (not (member (derivation-file-name cu) refs)))))) | |
1452 | ||
1453 | (test-assertm "gexp->file, cross-compilation with default target" | |
1454 | (mlet* %store-monad ((target -> "aarch64-linux-gnu") | |
1455 | (_ (set-current-target target)) | |
1456 | (exp -> (gexp (list (ungexp coreutils)))) | |
1457 | (xdrv (gexp->file "foo" exp)) | |
1458 | (refs (references* | |
1459 | (derivation-file-name xdrv))) | |
1460 | (xcu (package->cross-derivation coreutils | |
1461 | target)) | |
1462 | (cu (package->derivation coreutils))) | |
1463 | (return (and (member (derivation-file-name xcu) refs) | |
1464 | (not (member (derivation-file-name cu) refs)))))) | |
1465 | ||
1466 | (test-assertm "gexp->script, cross-compilation" | |
1467 | (mlet* %store-monad ((target -> "aarch64-linux-gnu") | |
1468 | (exp -> (gexp (list (ungexp coreutils)))) | |
1469 | (xdrv (gexp->script "foo" exp #:target target)) | |
1470 | (refs (references* | |
1471 | (derivation-file-name xdrv))) | |
1472 | (xcu (package->cross-derivation coreutils | |
1473 | target)) | |
1474 | (cu (package->derivation coreutils))) | |
1475 | (return (and (member (derivation-file-name xcu) refs) | |
1476 | (not (member (derivation-file-name cu) refs)))))) | |
1477 | ||
1478 | (test-assertm "gexp->script, cross-compilation with default target" | |
1479 | (mlet* %store-monad ((target -> "aarch64-linux-gnu") | |
1480 | (_ (set-current-target target)) | |
1481 | (exp -> (gexp (list (ungexp coreutils)))) | |
1482 | (xdrv (gexp->script "foo" exp)) | |
1483 | (refs (references* | |
1484 | (derivation-file-name xdrv))) | |
1485 | (xcu (package->cross-derivation coreutils | |
1486 | target)) | |
1487 | (cu (package->derivation coreutils))) | |
1488 | (return (and (member (derivation-file-name xcu) refs) | |
1489 | (not (member (derivation-file-name cu) refs)))))) | |
1490 | ||
21b679f6 LC |
1491 | (test-end "gexp") |
1492 | ||
21b679f6 LC |
1493 | ;; Local Variables: |
1494 | ;; eval: (put 'test-assertm 'scheme-indent-function 1) | |
1495 | ;; End: |