gnu: linux-libre@4.9: Update to 4.9.181.
[guix.git] / tests / pack.scm
blobea88cd89f24d898ea810300c16c9f5b294d1ec66
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net>
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/>.
20 (define-module (test-pack)
21   #:use-module (guix scripts pack)
22   #:use-module (guix store)
23   #:use-module (guix derivations)
24   #:use-module (guix profiles)
25   #:use-module (guix packages)
26   #:use-module (guix monads)
27   #:use-module (guix grafts)
28   #:use-module (guix tests)
29   #:use-module (guix gexp)
30   #:use-module (gnu packages bootstrap)
31   #:use-module ((gnu packages compression) #:select (squashfs-tools-next))
32   #:use-module (srfi srfi-64))
34 (define %store
35   (open-connection-for-tests))
37 ;; Globally disable grafts because they can trigger early builds.
38 (%graft? #f)
40 (define-syntax-rule (test-assertm name store exp)
41   (test-assert name
42     (let ((guile (package-derivation store %bootstrap-guile)))
43       (run-with-store store exp
44                       #:guile-for-build guile))))
46 (define %gzip-compressor
47   ;; Compressor that uses the bootstrap 'gzip'.
48   ((@ (guix scripts pack) compressor) "gzip"
49    "gz"
50    #~(#+(file-append %bootstrap-coreutils&co "/bin/gzip") "-6n")))
52 (define %tar-bootstrap %bootstrap-coreutils&co)
55 (test-begin "pack")
57 (unless (network-reachable?) (test-skip 1))
58 (test-assertm "self-contained-tarball" %store
59   (mlet* %store-monad
60       ((profile (profile-derivation (packages->manifest
61                                      (list %bootstrap-guile))
62                                     #:hooks '()
63                                     #:locales? #f))
64        (tarball (self-contained-tarball "pack" profile
65                                         #:symlinks '(("/bin/Guile"
66                                                       -> "bin/guile"))
67                                         #:compressor %gzip-compressor
68                                         #:archiver %tar-bootstrap))
69        (check   (gexp->derivation
70                  "check-tarball"
71                  (with-imported-modules '((guix build utils))
72                    #~(begin
73                        (use-modules (guix build utils)
74                                     (srfi srfi-1))
76                        (define store
77                          ;; The unpacked store.
78                          (string-append "." (%store-directory) "/"))
80                        (define (canonical? file)
81                          ;; Return #t if FILE is read-only and its mtime is 1.
82                          (let ((st (lstat file)))
83                            (or (not (string-prefix? store file))
84                                (eq? 'symlink (stat:type st))
85                                (and (= 1 (stat:mtime st))
86                                     (zero? (logand #o222
87                                                    (stat:mode st)))))))
89                        (define bin
90                          (string-append "." #$profile "/bin"))
92                        (setenv "PATH"
93                                (string-append #$%tar-bootstrap "/bin"))
94                        (system* "tar" "xvf" #$tarball)
95                        (mkdir #$output)
96                        (exit
97                         (and (file-exists? (string-append bin "/guile"))
98                              (file-exists? store)
99                              (every canonical?
100                                     (find-files "." (const #t)
101                                                 #:directories? #t))
102                              (string=? (string-append #$%bootstrap-guile "/bin")
103                                        (readlink bin))
104                              (string=? (string-append ".." #$profile
105                                                       "/bin/guile")
106                                        (readlink "bin/Guile")))))))))
107     (built-derivations (list check))))
109 ;; The following test needs guile-sqlite3, libgcrypt, etc. as a consequence of
110 ;; commit c45477d2a1a651485feede20fe0f3d15aec48b39 and related changes.  Thus,
111 ;; run it on the user's store, if it's available, on the grounds that these
112 ;; dependencies may be already there, or we can get substitutes or build them
113 ;; quite inexpensively; see <https://bugs.gnu.org/32184>.
115 (with-external-store store
116   (unless store (test-skip 1))
117   (test-assertm "self-contained-tarball + localstatedir" store
118     (mlet* %store-monad
119         ((guile   (set-guile-for-build (default-guile)))
120          (profile (profile-derivation (packages->manifest
121                                        (list %bootstrap-guile))
122                                       #:hooks '()
123                                       #:locales? #f))
124          (tarball (self-contained-tarball "tar-pack" profile
125                                           #:localstatedir? #t))
126          (check   (gexp->derivation
127                    "check-tarball"
128                    #~(let ((bin (string-append "." #$profile "/bin")))
129                        (setenv "PATH"
130                                (string-append #$%tar-bootstrap "/bin"))
131                        (system* "tar" "xvf" #$tarball)
132                        (mkdir #$output)
133                        (exit
134                         (and (file-exists? "var/guix/db/db.sqlite")
135                              (string=? (string-append #$%bootstrap-guile "/bin")
136                                        (readlink bin))))))))
137       (built-derivations (list check))))
139   (unless store (test-skip 1))
140   (test-assertm "docker-image + localstatedir" store
141     (mlet* %store-monad
142         ((guile   (set-guile-for-build (default-guile)))
143          (profile (profile-derivation (packages->manifest
144                                        (list %bootstrap-guile))
145                                       #:hooks '()
146                                       #:locales? #f))
147          (tarball (docker-image "docker-pack" profile
148                                 #:symlinks '(("/bin/Guile" -> "bin/guile"))
149                                 #:localstatedir? #t))
150          (check   (gexp->derivation
151                    "check-tarball"
152                    (with-imported-modules '((guix build utils))
153                      #~(begin
154                          (use-modules (guix build utils)
155                                       (ice-9 match))
157                          (define bin
158                            (string-append "." #$profile "/bin"))
160                          (setenv "PATH" (string-append #$%tar-bootstrap "/bin"))
161                          (mkdir "base")
162                          (with-directory-excursion "base"
163                            (invoke "tar" "xvf" #$tarball))
165                          (match (find-files "base" "layer.tar")
166                            ((layer)
167                             (invoke "tar" "xvf" layer)))
169                          (when
170                           (and (file-exists? (string-append bin "/guile"))
171                                (file-exists? "var/guix/db/db.sqlite")
172                                (string=? (string-append #$%bootstrap-guile "/bin")
173                                          (pk 'binlink (readlink bin)))
174                                (string=? (string-append #$profile "/bin/guile")
175                                          (pk 'guilelink (readlink "bin/Guile"))))
176                           (mkdir #$output)))))))
177       (built-derivations (list check))))
179   (unless store (test-skip 1))
180   (test-assertm "squashfs-image + localstatedir" store
181     (mlet* %store-monad
182         ((guile   (set-guile-for-build (default-guile)))
183          (profile (profile-derivation (packages->manifest
184                                        (list %bootstrap-guile))
185                                       #:hooks '()
186                                       #:locales? #f))
187          (image   (squashfs-image "squashfs-pack" profile
188                                   #:symlinks '(("/bin" -> "bin"))
189                                   #:localstatedir? #t))
190          (check   (gexp->derivation
191                    "check-tarball"
192                    (with-imported-modules '((guix build utils))
193                      #~(begin
194                          (use-modules (guix build utils)
195                                       (ice-9 match))
197                          (define bin
198                            (string-append "." #$profile "/bin"))
200                          (setenv "PATH"
201                                  (string-append #$squashfs-tools-next "/bin"))
202                          (invoke "unsquashfs" #$image)
203                          (with-directory-excursion "squashfs-root"
204                            (when (and (file-exists? (string-append bin
205                                                                    "/guile"))
206                                       (file-exists? "var/guix/db/db.sqlite")
207                                       (string=? (string-append #$%bootstrap-guile "/bin")
208                                                 (pk 'binlink (readlink bin)))
210                                       ;; This is a relative symlink target.
211                                       (string=? (string-drop
212                                                  (string-append #$profile "/bin")
213                                                  1)
214                                                 (pk 'guilelink (readlink "bin"))))
215                              (mkdir #$output))))))))
216       (built-derivations (list check)))))
218 (test-end)
220 ;; Local Variables:
221 ;; eval: (put 'test-assertm 'scheme-indent-function 2)
222 ;; End: