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