pack.scm 9.7 KB

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