Commit | Line | Data |
---|---|---|
a2078770 | 1 | ;;; GNU Guix --- Functional package management for GNU |
ef674a24 | 2 | ;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org> |
343745c8 | 3 | ;;; Copyright © 2014 Alex Kost <alezost@gmail.com> |
a2078770 LC |
4 | ;;; |
5 | ;;; This file is part of GNU Guix. | |
6 | ;;; | |
7 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | |
8 | ;;; under the terms of the GNU General Public License as published by | |
9 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
10 | ;;; your option) any later version. | |
11 | ;;; | |
12 | ;;; GNU Guix is distributed in the hope that it will be useful, but | |
13 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | ;;; GNU General Public License for more details. | |
16 | ;;; | |
17 | ;;; You should have received a copy of the GNU General Public License | |
18 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | |
19 | ||
20 | (define-module (test-profiles) | |
c1bc358f | 21 | #:use-module (guix tests) |
a2078770 | 22 | #:use-module (guix profiles) |
2225d56a | 23 | #:use-module (guix gexp) |
462f5cca LC |
24 | #:use-module (guix store) |
25 | #:use-module (guix monads) | |
ef8de985 | 26 | #:use-module (guix grafts) |
462f5cca LC |
27 | #:use-module (guix packages) |
28 | #:use-module (guix derivations) | |
a0dac7a0 | 29 | #:use-module (guix build-system trivial) |
462f5cca | 30 | #:use-module (gnu packages bootstrap) |
e39d1461 | 31 | #:use-module ((gnu packages base) #:prefix packages:) |
dedb17ad | 32 | #:use-module ((gnu packages guile) #:prefix packages:) |
a2078770 | 33 | #:use-module (ice-9 match) |
ef8993e2 | 34 | #:use-module (ice-9 regex) |
d664f1b4 LC |
35 | #:use-module (ice-9 popen) |
36 | #:use-module (rnrs io ports) | |
ccda8f7d | 37 | #:use-module (srfi srfi-1) |
79601521 | 38 | #:use-module (srfi srfi-11) |
a654dc4b | 39 | #:use-module (srfi srfi-34) |
a2078770 LC |
40 | #:use-module (srfi srfi-64)) |
41 | ||
343745c8 | 42 | ;; Test the (guix profiles) module. |
a2078770 | 43 | |
462f5cca | 44 | (define %store |
c1bc358f | 45 | (open-connection-for-tests)) |
a2078770 | 46 | |
ef8de985 LC |
47 | ;; Globally disable grafts because they can trigger early builds. |
48 | (%graft? #f) | |
49 | ||
a2078770 LC |
50 | ;; Example manifest entries. |
51 | ||
f7554030 AK |
52 | (define guile-1.8.8 |
53 | (manifest-entry | |
54 | (name "guile") | |
55 | (version "1.8.8") | |
56 | (item "/gnu/store/...") | |
57 | (output "out"))) | |
58 | ||
a2078770 LC |
59 | (define guile-2.0.9 |
60 | (manifest-entry | |
61 | (name "guile") | |
62 | (version "2.0.9") | |
a54c94a4 | 63 | (item "/gnu/store/...") |
a2078770 LC |
64 | (output "out"))) |
65 | ||
66 | (define guile-2.0.9:debug | |
67 | (manifest-entry (inherit guile-2.0.9) | |
68 | (output "debug"))) | |
69 | ||
79601521 LC |
70 | (define glibc |
71 | (manifest-entry | |
72 | (name "glibc") | |
73 | (version "2.19") | |
74 | (item "/gnu/store/...") | |
75 | (output "out"))) | |
76 | ||
a2078770 LC |
77 | \f |
78 | (test-begin "profiles") | |
79 | ||
80 | (test-assert "manifest-installed?" | |
81 | (let ((m (manifest (list guile-2.0.9 guile-2.0.9:debug)))) | |
82 | (and (manifest-installed? m (manifest-pattern (name "guile"))) | |
83 | (manifest-installed? m (manifest-pattern | |
84 | (name "guile") (output "debug"))) | |
85 | (manifest-installed? m (manifest-pattern | |
86 | (name "guile") (output "out") | |
87 | (version "2.0.9"))) | |
88 | (not (manifest-installed? | |
89 | m (manifest-pattern (name "guile") (version "1.8.8")))) | |
90 | (not (manifest-installed? | |
91 | m (manifest-pattern (name "guile") (output "foobar"))))))) | |
92 | ||
93 | (test-assert "manifest-matching-entries" | |
94 | (let* ((e (list guile-2.0.9 guile-2.0.9:debug)) | |
95 | (m (manifest e))) | |
487cbb01 | 96 | (and (equal? e |
a2078770 LC |
97 | (manifest-matching-entries m |
98 | (list (manifest-pattern | |
99 | (name "guile") | |
100 | (output #f))))) | |
101 | (equal? (list guile-2.0.9) | |
102 | (manifest-matching-entries m | |
103 | (list (manifest-pattern | |
104 | (name "guile") | |
105 | (version "2.0.9")))))))) | |
106 | ||
487cbb01 LC |
107 | (test-assert "manifest-matching-entries, no match" |
108 | (let ((m (manifest (list guile-2.0.9))) | |
109 | (p (manifest-pattern (name "python")))) | |
110 | (guard (c ((unmatched-pattern-error? c) | |
111 | (and (eq? p (unmatched-pattern-error-pattern c)) | |
112 | (eq? m (unmatched-pattern-error-manifest c))))) | |
113 | (manifest-matching-entries m (list p)) | |
114 | #f))) | |
115 | ||
ce30a0eb LC |
116 | (test-equal "concatenate-manifests" |
117 | (manifest (list guile-2.0.9 glibc)) | |
118 | (concatenate-manifests (list (manifest (list guile-2.0.9)) | |
119 | (manifest (list glibc))))) | |
120 | ||
a2078770 LC |
121 | (test-assert "manifest-remove" |
122 | (let* ((m0 (manifest (list guile-2.0.9 guile-2.0.9:debug))) | |
123 | (m1 (manifest-remove m0 | |
124 | (list (manifest-pattern (name "guile"))))) | |
125 | (m2 (manifest-remove m1 | |
126 | (list (manifest-pattern (name "guile"))))) ; same | |
127 | (m3 (manifest-remove m2 | |
128 | (list (manifest-pattern | |
129 | (name "guile") (output "debug"))))) | |
130 | (m4 (manifest-remove m3 | |
131 | (list (manifest-pattern (name "guile")))))) | |
132 | (match (manifest-entries m2) | |
133 | ((($ <manifest-entry> "guile" "2.0.9" "debug")) | |
134 | (and (equal? m1 m2) | |
135 | (null? (manifest-entries m3)) | |
136 | (null? (manifest-entries m4))))))) | |
137 | ||
f7554030 AK |
138 | (test-assert "manifest-add" |
139 | (let* ((m0 (manifest '())) | |
140 | (m1 (manifest-add m0 (list guile-1.8.8))) | |
141 | (m2 (manifest-add m1 (list guile-2.0.9))) | |
142 | (m3 (manifest-add m2 (list guile-2.0.9:debug))) | |
143 | (m4 (manifest-add m3 (list guile-2.0.9:debug)))) | |
144 | (and (match (manifest-entries m1) | |
145 | ((($ <manifest-entry> "guile" "1.8.8" "out")) #t) | |
146 | (_ #f)) | |
147 | (match (manifest-entries m2) | |
148 | ((($ <manifest-entry> "guile" "2.0.9" "out")) #t) | |
149 | (_ #f)) | |
150 | (equal? m3 m4)))) | |
151 | ||
435603a1 LC |
152 | (test-equal "manifest-add removes duplicates" ;<https://bugs.gnu.org/30569> |
153 | (list guile-2.0.9) | |
154 | (manifest-entries (manifest-add (manifest '()) | |
155 | (list guile-2.0.9 guile-2.0.9)))) | |
156 | ||
343745c8 AK |
157 | (test-assert "manifest-perform-transaction" |
158 | (let* ((m0 (manifest (list guile-2.0.9 guile-2.0.9:debug))) | |
159 | (t1 (manifest-transaction | |
160 | (install (list guile-1.8.8)) | |
161 | (remove (list (manifest-pattern (name "guile") | |
162 | (output "debug")))))) | |
163 | (t2 (manifest-transaction | |
164 | (remove (list (manifest-pattern (name "guile") | |
165 | (version "2.0.9") | |
166 | (output #f)))))) | |
167 | (m1 (manifest-perform-transaction m0 t1)) | |
168 | (m2 (manifest-perform-transaction m1 t2)) | |
169 | (m3 (manifest-perform-transaction m0 t2))) | |
170 | (and (match (manifest-entries m1) | |
171 | ((($ <manifest-entry> "guile" "1.8.8" "out")) #t) | |
172 | (_ #f)) | |
173 | (equal? m1 m2) | |
174 | (null? (manifest-entries m3))))) | |
175 | ||
79601521 LC |
176 | (test-assert "manifest-transaction-effects" |
177 | (let* ((m0 (manifest (list guile-1.8.8))) | |
178 | (t (manifest-transaction | |
487cbb01 | 179 | (install (list guile-2.0.9 glibc))))) |
46b23e1a | 180 | (let-values (((remove install upgrade downgrade) |
79601521 | 181 | (manifest-transaction-effects m0 t))) |
46b23e1a | 182 | (and (null? remove) (null? downgrade) |
79601521 | 183 | (equal? (list glibc) install) |
ef8993e2 LC |
184 | (equal? (list (cons guile-1.8.8 guile-2.0.9)) upgrade))))) |
185 | ||
f5d952c5 LP |
186 | (test-assert "manifest-transaction-effects no double install or upgrades" |
187 | (let* ((m0 (manifest (list guile-1.8.8))) | |
188 | (t (manifest-transaction | |
189 | (install (list guile-2.0.9 glibc glibc))))) | |
190 | (let-values (((remove install upgrade downgrade) | |
191 | (manifest-transaction-effects m0 t))) | |
192 | (and (null? remove) (null? downgrade) | |
193 | (equal? (list glibc) install) | |
194 | (equal? (list (cons guile-1.8.8 guile-2.0.9)) upgrade))))) | |
195 | ||
46b23e1a LC |
196 | (test-assert "manifest-transaction-effects and downgrades" |
197 | (let* ((m0 (manifest (list guile-2.0.9))) | |
198 | (t (manifest-transaction (install (list guile-1.8.8))))) | |
199 | (let-values (((remove install upgrade downgrade) | |
200 | (manifest-transaction-effects m0 t))) | |
201 | (and (null? remove) (null? install) (null? upgrade) | |
202 | (equal? (list (cons guile-2.0.9 guile-1.8.8)) downgrade))))) | |
203 | ||
f5d952c5 LP |
204 | (test-assert "manifest-transaction-effects no double downgrade" |
205 | (let* ((m0 (manifest (list guile-2.0.9))) | |
206 | (t (manifest-transaction (install (list guile-1.8.8 guile-1.8.8))))) | |
207 | (let-values (((remove install upgrade downgrade) | |
208 | (manifest-transaction-effects m0 t))) | |
209 | (and (null? remove) (null? install) (null? upgrade) | |
210 | (equal? (list (cons guile-2.0.9 guile-1.8.8)) downgrade))))) | |
211 | ||
3bea13bb LC |
212 | (test-assert "manifest-transaction-effects and pseudo-upgrades" |
213 | (let* ((m0 (manifest (list guile-2.0.9))) | |
214 | (t (manifest-transaction (install (list guile-2.0.9))))) | |
215 | (let-values (((remove install upgrade downgrade) | |
216 | (manifest-transaction-effects m0 t))) | |
217 | (and (null? remove) (null? install) (null? downgrade) | |
218 | (equal? (list (cons guile-2.0.9 guile-2.0.9)) upgrade))))) | |
219 | ||
c8c25704 LC |
220 | (test-assert "manifest-transaction-null?" |
221 | (manifest-transaction-null? (manifest-transaction))) | |
222 | ||
6d382339 LC |
223 | (test-assert "manifest-transaction-removal-candidate?" |
224 | (let ((m (manifest (list guile-2.0.9))) | |
225 | (t (manifest-transaction | |
226 | (remove (list (manifest-pattern (name "guile"))))))) | |
227 | (and (manifest-transaction-removal-candidate? guile-2.0.9 t) | |
228 | (not (manifest-transaction-removal-candidate? glibc t))))) | |
229 | ||
f5d952c5 LP |
230 | (test-assert "manifest-transaction-effects no double removal" |
231 | (let* ((m0 (manifest (list guile-2.0.9))) | |
232 | (t (manifest-transaction | |
233 | (remove (list (manifest-pattern (name "guile"))))))) | |
234 | (let-values (((remove install upgrade downgrade) | |
235 | (manifest-transaction-effects m0 t))) | |
236 | (and (= 1 (length remove)) | |
237 | (manifest-transaction-removal-candidate? guile-2.0.9 t) | |
238 | (null? install) (null? downgrade) (null? upgrade))))) | |
239 | ||
ebf5ad46 LC |
240 | (test-assertm "profile-derivation" |
241 | (mlet* %store-monad | |
242 | ((entry -> (package->manifest-entry %bootstrap-guile)) | |
243 | (guile (package->derivation %bootstrap-guile)) | |
244 | (drv (profile-derivation (manifest (list entry)) | |
a6562c7e LC |
245 | #:hooks '() |
246 | #:locales? #f)) | |
ebf5ad46 LC |
247 | (profile -> (derivation->output-path drv)) |
248 | (bindir -> (string-append profile "/bin")) | |
249 | (_ (built-derivations (list drv)))) | |
250 | (return (and (file-exists? (string-append bindir "/guile")) | |
251 | (string=? (dirname (readlink bindir)) | |
252 | (derivation->output-path guile)))))) | |
462f5cca | 253 | |
ef674a24 LC |
254 | (test-assertm "<profile>" |
255 | (mlet* %store-monad | |
256 | ((entry -> (package->manifest-entry %bootstrap-guile)) | |
257 | (profile -> (profile (hooks '()) (locales? #f) | |
258 | (content (manifest (list entry))))) | |
259 | (drv (lower-object profile)) | |
260 | (profile -> (derivation->output-path drv)) | |
261 | (bindir -> (string-append profile "/bin")) | |
262 | (_ (built-derivations (list drv)))) | |
263 | (return (file-exists? (string-append bindir "/guile"))))) | |
264 | ||
e00ade3f LC |
265 | (test-assertm "profile-derivation relative symlinks, one entry" |
266 | (mlet* %store-monad | |
267 | ((entry -> (package->manifest-entry %bootstrap-guile)) | |
268 | (guile (package->derivation %bootstrap-guile)) | |
269 | (drv (profile-derivation (manifest (list entry)) | |
270 | #:relative-symlinks? #t | |
271 | #:hooks '() | |
272 | #:locales? #f)) | |
273 | (profile -> (derivation->output-path drv)) | |
274 | (bindir -> (string-append profile "/bin")) | |
275 | (_ (built-derivations (list drv)))) | |
276 | (return (and (file-exists? (string-append bindir "/guile")) | |
277 | (string=? (readlink bindir) | |
278 | (string-append "../" | |
279 | (basename | |
280 | (derivation->output-path guile)) | |
281 | "/bin")))))) | |
282 | ||
283 | (unless (network-reachable?) (test-skip 1)) | |
284 | (test-assertm "profile-derivation relative symlinks, two entries" | |
285 | (mlet* %store-monad | |
03d76577 LC |
286 | ((manifest -> (packages->manifest |
287 | (list %bootstrap-guile gnu-make-for-tests))) | |
e00ade3f | 288 | (guile (package->derivation %bootstrap-guile)) |
03d76577 | 289 | (make (package->derivation gnu-make-for-tests)) |
e00ade3f LC |
290 | (drv (profile-derivation manifest |
291 | #:relative-symlinks? #t | |
292 | #:hooks '() | |
293 | #:locales? #f)) | |
294 | (profile -> (derivation->output-path drv)) | |
295 | (bindir -> (string-append profile "/bin")) | |
296 | (_ (built-derivations (list drv)))) | |
297 | (return (and (file-exists? (string-append bindir "/guile")) | |
298 | (file-exists? (string-append bindir "/make")) | |
299 | (string=? (readlink (string-append bindir "/guile")) | |
300 | (string-append "../../" | |
301 | (basename | |
302 | (derivation->output-path guile)) | |
303 | "/bin/guile")) | |
304 | (string=? (readlink (string-append bindir "/make")) | |
305 | (string-append "../../" | |
306 | (basename | |
307 | (derivation->output-path make)) | |
308 | "/bin/make")))))) | |
309 | ||
e39d1461 LC |
310 | (test-assertm "profile-derivation, inputs" |
311 | (mlet* %store-monad | |
312 | ((entry -> (package->manifest-entry packages:glibc "debug")) | |
313 | (drv (profile-derivation (manifest (list entry)) | |
a6562c7e LC |
314 | #:hooks '() |
315 | #:locales? #f))) | |
e39d1461 LC |
316 | (return (derivation-inputs drv)))) |
317 | ||
176febe3 LC |
318 | (test-assertm "profile-derivation, cross-compilation" |
319 | (mlet* %store-monad | |
320 | ((manifest -> (packages->manifest (list packages:sed packages:grep))) | |
321 | (target -> "arm-linux-gnueabihf") | |
322 | (grep (package->cross-derivation packages:grep target)) | |
323 | (sed (package->cross-derivation packages:sed target)) | |
324 | (locales (package->derivation packages:glibc-utf8-locales)) | |
325 | (drv (profile-derivation manifest | |
326 | #:hooks '() | |
327 | #:locales? #t | |
328 | #:target target))) | |
ede121de CM |
329 | (define (find-input package) |
330 | (let ((name (string-append (package-full-name package "-") ".drv"))) | |
176febe3 LC |
331 | (any (lambda (input) |
332 | (let ((input (derivation-input-path input))) | |
333 | (and (string-suffix? name input) input))) | |
334 | (derivation-inputs drv)))) | |
335 | ||
336 | ;; The inputs for grep and sed should be cross-build derivations, but that | |
337 | ;; for the glibc-utf8-locales should be a native build. | |
338 | (return (and (string=? (derivation-system drv) (%current-system)) | |
ede121de | 339 | (string=? (find-input packages:grep) |
176febe3 | 340 | (derivation-file-name grep)) |
ede121de | 341 | (string=? (find-input packages:sed) |
176febe3 | 342 | (derivation-file-name sed)) |
ede121de | 343 | (string=? (find-input packages:glibc-utf8-locales) |
176febe3 LC |
344 | (derivation-file-name locales)))))) |
345 | ||
9e90fc77 LC |
346 | (test-assert "package->manifest-entry defaults to \"out\"" |
347 | (let ((outputs (package-outputs packages:glibc))) | |
348 | (equal? (manifest-entry-output | |
349 | (package->manifest-entry (package | |
350 | (inherit packages:glibc) | |
351 | (outputs (reverse outputs))))) | |
352 | (manifest-entry-output | |
353 | (package->manifest-entry packages:glibc)) | |
354 | "out"))) | |
355 | ||
dedb17ad LC |
356 | (test-assertm "profile-manifest, search-paths" |
357 | (mlet* %store-monad | |
358 | ((guile -> (package | |
359 | (inherit %bootstrap-guile) | |
360 | (native-search-paths | |
361 | (package-native-search-paths packages:guile-2.0)))) | |
362 | (entry -> (package->manifest-entry guile)) | |
363 | (drv (profile-derivation (manifest (list entry)) | |
a6562c7e LC |
364 | #:hooks '() |
365 | #:locales? #f)) | |
dedb17ad LC |
366 | (profile -> (derivation->output-path drv))) |
367 | (mbegin %store-monad | |
368 | (built-derivations (list drv)) | |
369 | ||
370 | ;; Read the manifest back and make sure search paths are preserved. | |
371 | (let ((manifest (profile-manifest profile))) | |
372 | (match (manifest-entries manifest) | |
373 | ((result) | |
374 | (return (equal? (manifest-entry-search-paths result) | |
375 | (manifest-entry-search-paths entry) | |
376 | (package-native-search-paths | |
377 | packages:guile-2.0))))))))) | |
d664f1b4 | 378 | |
ccda8f7d LC |
379 | (test-assert "package->manifest-entry, search paths" |
380 | ;; See <http://bugs.gnu.org/22073>. | |
2d17a904 | 381 | (let ((mpl (@ (gnu packages python-xyz) python2-matplotlib))) |
ccda8f7d LC |
382 | (lset= eq? |
383 | (package-transitive-native-search-paths mpl) | |
384 | (manifest-entry-search-paths | |
385 | (package->manifest-entry mpl))))) | |
386 | ||
07340cbe LP |
387 | (test-assert "packages->manifest, no duplicates" |
388 | (let ((expected | |
389 | (manifest | |
390 | (list | |
391 | (package->manifest-entry packages:guile-2.2)))) | |
392 | (manifest (packages->manifest | |
393 | (list packages:guile-2.2 packages:guile-2.2)))) | |
394 | (every manifest-entry=? (manifest-entries expected) | |
395 | (manifest-entries manifest)))) | |
396 | ||
55b4715f LC |
397 | (test-equal "packages->manifest, propagated inputs" |
398 | (map (match-lambda | |
399 | ((label package) | |
400 | (list (package-name package) (package-version package) | |
401 | package))) | |
402 | (package-propagated-inputs packages:guile-2.2)) | |
403 | (map (lambda (entry) | |
404 | (list (manifest-entry-name entry) | |
405 | (manifest-entry-version entry) | |
406 | (manifest-entry-item entry))) | |
407 | (manifest-entry-dependencies | |
408 | (package->manifest-entry packages:guile-2.2)))) | |
409 | ||
b3a00885 LC |
410 | (test-assert "manifest-entry-parent" |
411 | (let ((entry (package->manifest-entry packages:guile-2.2))) | |
412 | (match (manifest-entry-dependencies entry) | |
413 | ((dependencies ..1) | |
414 | (and (every (lambda (parent) | |
415 | (eq? entry (force parent))) | |
416 | (map manifest-entry-parent dependencies)) | |
417 | (not (force (manifest-entry-parent entry)))))))) | |
418 | ||
55b4715f LC |
419 | (test-assertm "read-manifest" |
420 | (mlet* %store-monad ((manifest -> (packages->manifest | |
421 | (list (package | |
422 | (inherit %bootstrap-guile) | |
423 | (native-search-paths | |
424 | (package-native-search-paths | |
425 | packages:guile-2.0)))))) | |
426 | (drv (profile-derivation manifest | |
427 | #:hooks '() | |
428 | #:locales? #f)) | |
429 | (out -> (derivation->output-path drv))) | |
430 | (define (entry->sexp entry) | |
431 | (list (manifest-entry-name entry) | |
432 | (manifest-entry-version entry) | |
433 | (manifest-entry-search-paths entry) | |
b3a00885 LC |
434 | (manifest-entry-dependencies entry) |
435 | (force (manifest-entry-parent entry)))) | |
55b4715f LC |
436 | |
437 | (mbegin %store-monad | |
438 | (built-derivations (list drv)) | |
439 | (let ((manifest2 (profile-manifest out))) | |
440 | (return (equal? (map entry->sexp (manifest-entries manifest)) | |
441 | (map entry->sexp (manifest-entries manifest2)))))))) | |
442 | ||
a654dc4b LC |
443 | (test-equal "collision" |
444 | '(("guile-bootstrap" "2.0") ("guile-bootstrap" "42")) | |
445 | (guard (c ((profile-collision-error? c) | |
446 | (let ((entry1 (profile-collision-error-entry c)) | |
447 | (entry2 (profile-collision-error-conflict c))) | |
448 | (list (list (manifest-entry-name entry1) | |
449 | (manifest-entry-version entry1)) | |
450 | (list (manifest-entry-name entry2) | |
451 | (manifest-entry-version entry2)))))) | |
452 | (run-with-store %store | |
453 | (mlet* %store-monad ((p0 -> (package | |
454 | (inherit %bootstrap-guile) | |
455 | (version "42"))) | |
456 | (p1 -> (dummy-package "p1" | |
457 | (propagated-inputs `(("p0" ,p0))))) | |
458 | (manifest -> (packages->manifest | |
459 | (list %bootstrap-guile p1))) | |
460 | (drv (profile-derivation manifest | |
461 | #:hooks '() | |
462 | #:locales? #f))) | |
463 | (return #f))))) | |
464 | ||
465 | (test-equal "collision of propagated inputs" | |
466 | '(("guile-bootstrap" "2.0") ("guile-bootstrap" "42")) | |
467 | (guard (c ((profile-collision-error? c) | |
468 | (let ((entry1 (profile-collision-error-entry c)) | |
469 | (entry2 (profile-collision-error-conflict c))) | |
470 | (list (list (manifest-entry-name entry1) | |
471 | (manifest-entry-version entry1)) | |
472 | (list (manifest-entry-name entry2) | |
473 | (manifest-entry-version entry2)))))) | |
474 | (run-with-store %store | |
475 | (mlet* %store-monad ((p0 -> (package | |
476 | (inherit %bootstrap-guile) | |
477 | (version "42"))) | |
478 | (p1 -> (dummy-package "p1" | |
479 | (propagated-inputs | |
480 | `(("guile" ,%bootstrap-guile))))) | |
481 | (p2 -> (dummy-package "p2" | |
482 | (propagated-inputs | |
483 | `(("guile" ,p0))))) | |
484 | (manifest -> (packages->manifest (list p1 p2))) | |
485 | (drv (profile-derivation manifest | |
486 | #:hooks '() | |
487 | #:locales? #f))) | |
488 | (return #f))))) | |
489 | ||
490 | (test-assertm "no collision" | |
491 | ;; Here we have an entry that is "lowered" (its 'item' field is a store file | |
492 | ;; name) and another entry (its 'item' field is a package) that is | |
493 | ;; equivalent. | |
494 | (mlet* %store-monad ((p -> (dummy-package "p" | |
495 | (propagated-inputs | |
496 | `(("guile" ,%bootstrap-guile))))) | |
497 | (guile (package->derivation %bootstrap-guile)) | |
498 | (entry -> (manifest-entry | |
499 | (inherit (package->manifest-entry | |
500 | %bootstrap-guile)) | |
501 | (item (derivation->output-path guile)))) | |
502 | (manifest -> (manifest | |
503 | (list entry | |
504 | (package->manifest-entry p)))) | |
505 | (drv (profile-derivation manifest))) | |
506 | (return (->bool drv)))) | |
507 | ||
d664f1b4 LC |
508 | (test-assertm "etc/profile" |
509 | ;; Make sure we get an 'etc/profile' file that at least defines $PATH. | |
510 | (mlet* %store-monad | |
511 | ((guile -> (package | |
512 | (inherit %bootstrap-guile) | |
513 | (native-search-paths | |
514 | (package-native-search-paths packages:guile-2.0)))) | |
515 | (entry -> (package->manifest-entry guile)) | |
516 | (drv (profile-derivation (manifest (list entry)) | |
a6562c7e LC |
517 | #:hooks '() |
518 | #:locales? #f)) | |
d664f1b4 LC |
519 | (profile -> (derivation->output-path drv))) |
520 | (mbegin %store-monad | |
521 | (built-derivations (list drv)) | |
522 | (let* ((pipe (open-input-pipe | |
9e006fb3 TUBK |
523 | (string-append "unset GUIX_PROFILE; " |
524 | ;; 'source' is a Bashism; use '.' (dot). | |
525 | ". " profile "/etc/profile; " | |
526 | ;; Don't try to parse set(1) output because | |
527 | ;; it differs among shells; just use echo. | |
528 | "echo $PATH"))) | |
529 | (path (get-string-all pipe))) | |
d664f1b4 LC |
530 | (return |
531 | (and (zero? (close-pipe pipe)) | |
9e006fb3 | 532 | (string-contains path (string-append profile "/bin")))))))) |
d664f1b4 | 533 | |
a0dac7a0 LC |
534 | (test-assertm "etc/profile when etc/ already exists" |
535 | ;; Here 'union-build' makes the profile's etc/ a symlink to the package's | |
536 | ;; etc/ directory, which makes it read-only. Make sure the profile build | |
537 | ;; handles that. | |
538 | (mlet* %store-monad | |
539 | ((thing -> (dummy-package "dummy" | |
540 | (build-system trivial-build-system) | |
541 | (arguments | |
542 | `(#:guile ,%bootstrap-guile | |
543 | #:builder | |
544 | (let ((out (assoc-ref %outputs "out"))) | |
545 | (mkdir out) | |
546 | (mkdir (string-append out "/etc")) | |
547 | (call-with-output-file (string-append out "/etc/foo") | |
548 | (lambda (port) | |
1e868858 MW |
549 | (display "foo!" port))) |
550 | #t))))) | |
a0dac7a0 LC |
551 | (entry -> (package->manifest-entry thing)) |
552 | (drv (profile-derivation (manifest (list entry)) | |
a6562c7e LC |
553 | #:hooks '() |
554 | #:locales? #f)) | |
a0dac7a0 LC |
555 | (profile -> (derivation->output-path drv))) |
556 | (mbegin %store-monad | |
557 | (built-derivations (list drv)) | |
558 | (return (and (file-exists? (string-append profile "/etc/profile")) | |
559 | (string=? (call-with-input-file | |
560 | (string-append profile "/etc/foo") | |
561 | get-string-all) | |
562 | "foo!")))))) | |
563 | ||
113c17a0 LC |
564 | (test-assertm "etc/profile when etc/ is a symlink" |
565 | ;; When etc/ is a symlink, the unsymlink code in 0.8.2 would fail | |
566 | ;; gracelessly because 'scandir' would return #f. | |
567 | (mlet* %store-monad | |
568 | ((thing -> (dummy-package "dummy" | |
569 | (build-system trivial-build-system) | |
570 | (arguments | |
571 | `(#:guile ,%bootstrap-guile | |
572 | #:builder | |
573 | (let ((out (assoc-ref %outputs "out"))) | |
574 | (mkdir out) | |
575 | (mkdir (string-append out "/foo")) | |
576 | (symlink "foo" (string-append out "/etc")) | |
577 | (call-with-output-file (string-append out "/etc/bar") | |
578 | (lambda (port) | |
1e868858 MW |
579 | (display "foo!" port))) |
580 | #t))))) | |
113c17a0 LC |
581 | (entry -> (package->manifest-entry thing)) |
582 | (drv (profile-derivation (manifest (list entry)) | |
a6562c7e LC |
583 | #:hooks '() |
584 | #:locales? #f)) | |
113c17a0 LC |
585 | (profile -> (derivation->output-path drv))) |
586 | (mbegin %store-monad | |
587 | (built-derivations (list drv)) | |
588 | (return (and (file-exists? (string-append profile "/etc/profile")) | |
589 | (string=? (call-with-input-file | |
590 | (string-append profile "/etc/bar") | |
591 | get-string-all) | |
592 | "foo!")))))) | |
593 | ||
2225d56a LC |
594 | (test-assertm "profile-derivation when etc/ is a relative symlink" |
595 | ;; See <https://bugs.gnu.org/32686>. | |
596 | (mlet* %store-monad | |
597 | ((etc (gexp->derivation | |
598 | "etc" | |
599 | #~(begin | |
600 | (mkdir #$output) | |
601 | (call-with-output-file (string-append #$output "/foo") | |
602 | (lambda (port) | |
603 | (display "Heya!" port)))))) | |
604 | (thing -> (dummy-package "dummy" | |
605 | (build-system trivial-build-system) | |
606 | (inputs | |
607 | `(("etc" ,etc))) | |
608 | (arguments | |
609 | `(#:guile ,%bootstrap-guile | |
610 | #:builder | |
611 | (let ((out (assoc-ref %outputs "out")) | |
612 | (etc (assoc-ref %build-inputs "etc"))) | |
613 | (mkdir out) | |
614 | (symlink etc (string-append out "/etc")) | |
615 | #t))))) | |
616 | (entry -> (package->manifest-entry thing)) | |
617 | (drv (profile-derivation (manifest (list entry)) | |
618 | #:relative-symlinks? #t | |
619 | #:hooks '() | |
620 | #:locales? #f)) | |
621 | (profile -> (derivation->output-path drv))) | |
622 | (mbegin %store-monad | |
623 | (built-derivations (list drv)) | |
624 | (return (string=? (call-with-input-file | |
625 | (string-append profile "/etc/foo") | |
626 | get-string-all) | |
627 | "Heya!"))))) | |
628 | ||
22ef06b8 LC |
629 | (test-equalm "union vs. dangling symlink" ;<https://bugs.gnu.org/26949> |
630 | "does-not-exist" | |
631 | (mlet* %store-monad | |
632 | ((thing1 -> (dummy-package "dummy" | |
633 | (build-system trivial-build-system) | |
634 | (arguments | |
635 | `(#:guile ,%bootstrap-guile | |
636 | #:builder | |
637 | (let ((out (assoc-ref %outputs "out"))) | |
638 | (mkdir out) | |
639 | (symlink "does-not-exist" | |
640 | (string-append out "/dangling")) | |
641 | #t))))) | |
642 | (thing2 -> (package (inherit thing1) (name "dummy2"))) | |
643 | (drv (profile-derivation (packages->manifest | |
644 | (list thing1 thing2)) | |
645 | #:hooks '() | |
646 | #:locales? #f)) | |
647 | (profile -> (derivation->output-path drv))) | |
648 | (mbegin %store-monad | |
649 | (built-derivations (list drv)) | |
650 | (return (readlink (readlink (string-append profile "/dangling"))))))) | |
651 | ||
38b77f34 LC |
652 | (test-equalm "profile in profile" |
653 | '("foo" "0") | |
654 | ||
655 | ;; Make sure we can build a profile that has another profile has one of its | |
656 | ;; entries. The new profile's /manifest and /etc/profile must override the | |
657 | ;; other's. | |
658 | (mlet* %store-monad | |
659 | ((prof0 (profile-derivation | |
660 | (manifest | |
661 | (list (package->manifest-entry %bootstrap-guile))) | |
662 | #:hooks '() | |
663 | #:locales? #f)) | |
664 | (prof1 (profile-derivation | |
665 | (manifest (list (manifest-entry | |
666 | (name "foo") | |
667 | (version "0") | |
668 | (item prof0)))) | |
669 | #:hooks '() | |
670 | #:locales? #f))) | |
671 | (mbegin %store-monad | |
672 | (built-derivations (list prof1)) | |
673 | (let ((out (derivation->output-path prof1))) | |
674 | (return (and (file-exists? | |
675 | (string-append out "/bin/guile")) | |
676 | (let ((manifest (profile-manifest out))) | |
677 | (match (manifest-entries manifest) | |
678 | ((entry) | |
679 | (list (manifest-entry-name entry) | |
680 | (manifest-entry-version entry))))))))))) | |
681 | ||
a2078770 LC |
682 | (test-end "profiles") |
683 | ||
a2078770 LC |
684 | ;;; Local Variables: |
685 | ;;; eval: (put 'dummy-package 'scheme-indent-function 1) | |
686 | ;;; End: |