pack.scm 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2017, 2018, 2019, 2020 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/>.
  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 packages)
  25. #:use-module (guix monads)
  26. #:use-module (guix grafts)
  27. #:use-module (guix tests)
  28. #:use-module (guix gexp)
  29. #:use-module (guix modules)
  30. #:use-module (gnu packages)
  31. #:use-module ((gnu packages base) #:select (glibc-utf8-locales))
  32. #:use-module (gnu packages bootstrap)
  33. #:use-module ((gnu packages compression) #:select (squashfs-tools))
  34. #:use-module ((gnu packages guile) #:select (guile-sqlite3))
  35. #:use-module ((gnu packages gnupg) #:select (guile-gcrypt))
  36. #:use-module (srfi srfi-64))
  37. (define %store
  38. (open-connection-for-tests))
  39. ;; Globally disable grafts because they can trigger early builds.
  40. (%graft? #f)
  41. (define-syntax-rule (test-assertm name store exp)
  42. (test-assert name
  43. (let ((guile (package-derivation store %bootstrap-guile)))
  44. (run-with-store store exp
  45. #: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")))
  51. (define %tar-bootstrap %bootstrap-coreutils&co)
  52. (test-begin "pack")
  53. (unless (network-reachable?) (test-skip 1))
  54. (test-assertm "self-contained-tarball" %store
  55. (mlet* %store-monad
  56. ((profile -> (profile
  57. (content (packages->manifest (list %bootstrap-guile)))
  58. (hooks '())
  59. (locales? #f)))
  60. (tarball (self-contained-tarball "pack" profile
  61. #:symlinks '(("/bin/Guile"
  62. -> "bin/guile"))
  63. #:compressor %gzip-compressor
  64. #:archiver %tar-bootstrap))
  65. (check (gexp->derivation
  66. "check-tarball"
  67. (with-imported-modules '((guix build utils))
  68. #~(begin
  69. (use-modules (guix build utils)
  70. (srfi srfi-1))
  71. (define store
  72. ;; The unpacked store.
  73. (string-append "." (%store-directory) "/"))
  74. (define (canonical? file)
  75. ;; Return #t if FILE is read-only and its mtime is 1.
  76. (let ((st (lstat file)))
  77. (or (not (string-prefix? store file))
  78. (eq? 'symlink (stat:type st))
  79. (and (= 1 (stat:mtime st))
  80. (zero? (logand #o222
  81. (stat:mode st)))))))
  82. (define bin
  83. (string-append "." #$profile "/bin"))
  84. (setenv "PATH"
  85. (string-append #$%tar-bootstrap "/bin"))
  86. (system* "tar" "xvf" #$tarball)
  87. (mkdir #$output)
  88. (exit
  89. (and (file-exists? (string-append bin "/guile"))
  90. (file-exists? store)
  91. (every canonical?
  92. (find-files "." (const #t)
  93. #:directories? #t))
  94. (string=? (string-append #$%bootstrap-guile "/bin")
  95. (readlink bin))
  96. (string=? (string-append ".." #$profile
  97. "/bin/guile")
  98. (readlink "bin/Guile")))))))))
  99. (built-derivations (list check))))
  100. ;; The following test needs guile-sqlite3, libgcrypt, etc. as a consequence of
  101. ;; commit c45477d2a1a651485feede20fe0f3d15aec48b39 and related changes. Thus,
  102. ;; run it on the user's store, if it's available, on the grounds that these
  103. ;; dependencies may be already there, or we can get substitutes or build them
  104. ;; quite inexpensively; see <https://bugs.gnu.org/32184>.
  105. (with-external-store store
  106. (unless store (test-skip 1))
  107. (test-assertm "self-contained-tarball + localstatedir" store
  108. (mlet* %store-monad
  109. ((guile (set-guile-for-build (default-guile)))
  110. (profile (profile-derivation (packages->manifest
  111. (list %bootstrap-guile))
  112. #:hooks '()
  113. #:locales? #f))
  114. (tarball (self-contained-tarball "tar-pack" profile
  115. #:localstatedir? #t))
  116. (check (gexp->derivation
  117. "check-tarball"
  118. #~(let ((bin (string-append "." #$profile "/bin")))
  119. (setenv "PATH"
  120. (string-append #$%tar-bootstrap "/bin"))
  121. (system* "tar" "xvf" #$tarball)
  122. (mkdir #$output)
  123. (exit
  124. (and (file-exists? "var/guix/db/db.sqlite")
  125. (string=? (string-append #$%bootstrap-guile "/bin")
  126. (readlink bin))))))))
  127. (built-derivations (list check))))
  128. (unless store (test-skip 1))
  129. (test-assertm "self-contained-tarball + localstatedir, UTF-8 file names" store
  130. (mlet* %store-monad
  131. ((guile (set-guile-for-build (default-guile)))
  132. (tree (interned-file-tree
  133. `("directory-with-utf8-file-names" directory
  134. ("α" regular (data "alpha"))
  135. ("λ" regular (data "lambda")))))
  136. (tarball (self-contained-tarball "tar-pack" tree
  137. #:localstatedir? #t))
  138. (check (gexp->derivation
  139. "check-tarball"
  140. (with-extensions (list guile-sqlite3 guile-gcrypt)
  141. (with-imported-modules (source-module-closure
  142. '((guix store database)))
  143. #~(begin
  144. (use-modules (guix store database)
  145. (rnrs io ports)
  146. (srfi srfi-1))
  147. (define (valid-file? basename data)
  148. (define file
  149. (string-append "./" #$tree "/" basename))
  150. (string=? (call-with-input-file (pk 'file file)
  151. get-string-all)
  152. data))
  153. (setenv "PATH"
  154. (string-append #$%tar-bootstrap "/bin"))
  155. (system* "tar" "xvf" #$tarball)
  156. (sql-schema
  157. #$(local-file (search-path %load-path
  158. "guix/store/schema.sql")))
  159. (with-database "var/guix/db/db.sqlite" db
  160. ;; Make sure non-ASCII file names are properly
  161. ;; handled.
  162. (setenv "GUIX_LOCPATH"
  163. #+(file-append glibc-utf8-locales
  164. "/lib/locale"))
  165. (setlocale LC_ALL "en_US.utf8")
  166. (mkdir #$output)
  167. (exit
  168. (and (every valid-file?
  169. '("α" "λ")
  170. '("alpha" "lambda"))
  171. (integer? (path-id db #$tree)))))))))))
  172. (built-derivations (list check))))
  173. (unless store (test-skip 1))
  174. (test-assertm "docker-image + localstatedir" store
  175. (mlet* %store-monad
  176. ((guile (set-guile-for-build (default-guile)))
  177. (profile (profile-derivation (packages->manifest
  178. (list %bootstrap-guile))
  179. #:hooks '()
  180. #:locales? #f))
  181. (tarball (docker-image "docker-pack" profile
  182. #:symlinks '(("/bin/Guile" -> "bin/guile"))
  183. #:localstatedir? #t))
  184. (check (gexp->derivation
  185. "check-tarball"
  186. (with-imported-modules '((guix build utils))
  187. #~(begin
  188. (use-modules (guix build utils)
  189. (ice-9 match))
  190. (define bin
  191. (string-append "." #$profile "/bin"))
  192. (setenv "PATH" (string-append #$%tar-bootstrap "/bin"))
  193. (mkdir "base")
  194. (with-directory-excursion "base"
  195. (invoke "tar" "xvf" #$tarball))
  196. (match (find-files "base" "layer.tar")
  197. ((layer)
  198. (invoke "tar" "xvf" layer)))
  199. (when
  200. (and (file-exists? (string-append bin "/guile"))
  201. (file-exists? "var/guix/db/db.sqlite")
  202. (file-is-directory? "tmp")
  203. (string=? (string-append #$%bootstrap-guile "/bin")
  204. (pk 'binlink (readlink bin)))
  205. (string=? (string-append #$profile "/bin/guile")
  206. (pk 'guilelink (readlink "bin/Guile"))))
  207. (mkdir #$output)))))))
  208. (built-derivations (list check))))
  209. (unless store (test-skip 1))
  210. (test-assertm "squashfs-image + localstatedir" store
  211. (mlet* %store-monad
  212. ((guile (set-guile-for-build (default-guile)))
  213. (profile (profile-derivation (packages->manifest
  214. (list %bootstrap-guile))
  215. #:hooks '()
  216. #:locales? #f))
  217. (image (squashfs-image "squashfs-pack" profile
  218. #:symlinks '(("/bin" -> "bin"))
  219. #:localstatedir? #t))
  220. (check (gexp->derivation
  221. "check-tarball"
  222. (with-imported-modules '((guix build utils))
  223. #~(begin
  224. (use-modules (guix build utils)
  225. (ice-9 match))
  226. (define bin
  227. (string-append "." #$profile "/bin"))
  228. (setenv "PATH"
  229. (string-append #$squashfs-tools "/bin"))
  230. (invoke "unsquashfs" #$image)
  231. (with-directory-excursion "squashfs-root"
  232. (when (and (file-exists? (string-append bin
  233. "/guile"))
  234. (file-exists? "var/guix/db/db.sqlite")
  235. (string=? (string-append #$%bootstrap-guile "/bin")
  236. (pk 'binlink (readlink bin)))
  237. ;; This is a relative symlink target.
  238. (string=? (string-drop
  239. (string-append #$profile "/bin")
  240. 1)
  241. (pk 'guilelink (readlink "bin"))))
  242. (mkdir #$output))))))))
  243. (built-derivations (list check)))))
  244. (test-end)
  245. ;; Local Variables:
  246. ;; eval: (put 'test-assertm 'scheme-indent-function 2)
  247. ;; End: