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