summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am1
-rw-r--r--guix/scripts/pack.scm13
-rw-r--r--tests/pack.scm79
3 files changed, 91 insertions, 2 deletions
diff --git a/Makefile.am b/Makefile.am
index 23171ae8377..dea70de00fb 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -297,6 +297,7 @@ SCM_TESTS = \
297 tests/services.scm \ 297 tests/services.scm \
298 tests/scripts-build.scm \ 298 tests/scripts-build.scm \
299 tests/containers.scm \ 299 tests/containers.scm \
300 tests/pack.scm \
300 tests/import-utils.scm 301 tests/import-utils.scm
301 302
302if HAVE_GUILE_JSON 303if HAVE_GUILE_JSON
diff --git a/guix/scripts/pack.scm b/guix/scripts/pack.scm
index c3d85c568c2..067b1227e0e 100644
--- a/guix/scripts/pack.scm
+++ b/guix/scripts/pack.scm
@@ -70,7 +70,8 @@ found."
70 #:key deduplicate? 70 #:key deduplicate?
71 (compressor (first %compressors)) 71 (compressor (first %compressors))
72 localstatedir? 72 localstatedir?
73 (symlinks '())) 73 (symlinks '())
74 (tar tar))
74 "Return a self-contained tarball containing a store initialized with the 75 "Return a self-contained tarball containing a store initialized with the
75closure of PROFILE, a derivation. The tarball contains /gnu/store; if 76closure of PROFILE, a derivation. The tarball contains /gnu/store; if
76LOCALSTATEDIR? is true, it also contains /var/guix, including /var/guix/db 77LOCALSTATEDIR? is true, it also contains /var/guix, including /var/guix/db
@@ -104,6 +105,14 @@ added to the pack."
104 ;; Fully-qualified symlinks. 105 ;; Fully-qualified symlinks.
105 (append-map symlink->directives '#$symlinks)) 106 (append-map symlink->directives '#$symlinks))
106 107
108 ;; The --sort option was added to GNU tar in version 1.28, released
109 ;; 2014-07-28. For testing, we use the bootstrap tar, which is
110 ;; older and doesn't support it.
111 (define tar-supports-sort?
112 (zero? (system* (string-append #+tar "/bin/tar")
113 "cf" "/dev/null" "--files-from=/dev/null"
114 "--sort=name")))
115
107 ;; We need Guix here for 'guix-register'. 116 ;; We need Guix here for 'guix-register'.
108 (setenv "PATH" 117 (setenv "PATH"
109 (string-append #$(if localstatedir? 118 (string-append #$(if localstatedir?
@@ -137,7 +146,7 @@ added to the pack."
137 ;; mtime = 1, not zero, because that is what the 146 ;; mtime = 1, not zero, because that is what the
138 ;; daemon does for files in the store (see the 147 ;; daemon does for files in the store (see the
139 ;; 'mtimeStore' constant in local-store.cc.) 148 ;; 'mtimeStore' constant in local-store.cc.)
140 "--sort=name" 149 (if tar-supports-sort? "--sort=name" "--mtime=@1")
141 "--mtime=@1" ;for files in /var/guix 150 "--mtime=@1" ;for files in /var/guix
142 "--owner=root:0" 151 "--owner=root:0"
143 "--group=root:0" 152 "--group=root:0"
diff --git a/tests/pack.scm b/tests/pack.scm
new file mode 100644
index 00000000000..de9ef8e6ab3
--- /dev/null
+++ b/tests/pack.scm
@@ -0,0 +1,79 @@
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2017 Ludovic Courtès <ludo@gnu.org>
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-pack)
20 #:use-module (guix scripts pack)
21 #:use-module (guix store)
22 #:use-module (guix derivations)
23 #:use-module (guix profiles)
24 #:use-module (guix monads)
25 #:use-module (guix grafts)
26 #:use-module (guix tests)
27 #:use-module (guix gexp)
28 #:use-module (gnu packages bootstrap)
29 #:use-module (srfi srfi-64))
30
31(define %store
32 (open-connection-for-tests))
33
34;; Globally disable grafts because they can trigger early builds.
35(%graft? #f)
36
37(define-syntax-rule (test-assertm name exp)
38 (test-assert name
39 (run-with-store %store exp
40 #:guile-for-build (%guile-for-build))))
41
42(define %gzip-compressor
43 ;; Compressor that uses the bootstrap 'gzip'.
44 ((@ (guix scripts pack) compressor) "gzip"
45 %bootstrap-coreutils&co "gz" '("gzip" "-6n")))
46
47(define %tar-bootstrap %bootstrap-coreutils&co)
48
49
50(test-begin "pack")
51
52(test-assertm "self-contained-tarball"
53 (mlet* %store-monad
54 ((profile (profile-derivation (packages->manifest
55 (list %bootstrap-guile))
56 #:hooks '()
57 #:locales? #f))
58 (tarball (self-contained-tarball "pack" profile
59 #:symlinks '(("/bin/Guile"
60 -> "bin/guile"))
61 #:compressor %gzip-compressor
62 #:tar %tar-bootstrap))
63 (check (gexp->derivation
64 "check-tarball"
65 #~(let ((guile (string-append "." #$profile "/bin")))
66 (setenv "PATH"
67 (string-append #$%tar-bootstrap "/bin"))
68 (system* "tar" "xvf" #$tarball)
69 (mkdir #$output)
70 (exit
71 (and (file-exists? (string-append guile "/guile"))
72 (string=? (string-append #$%bootstrap-guile "/bin")
73 (readlink guile))
74 (string=? (string-append (string-drop guile 1)
75 "/guile")
76 (readlink "bin/Guile"))))))))
77 (built-derivations (list check))))
78
79(test-end)