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