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