guix-package.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. # GNU Guix --- Functional package management for GNU
  2. # Copyright © 2012, 2013, 2014, 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
  3. # Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
  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. # Test the `guix package' command-line utility.
  21. #
  22. guix package --version
  23. readlink_base ()
  24. {
  25. basename `readlink "$1"`
  26. }
  27. module_dir="t-guix-package-$$"
  28. profile="t-profile-$$"
  29. tmpfile="t-guix-package-file-$$"
  30. rm -f "$profile" "$tmpfile"
  31. trap 'rm -f "$profile" "$profile-"[0-9]* "$tmpfile"; rm -rf "$module_dir" t-home-'"$$" EXIT
  32. # Use `-e' with a non-package expression.
  33. if guix package --bootstrap -e +;
  34. then false; else true; fi
  35. # Install a store item and make sure the version and output in the manifest
  36. # are correct.
  37. guix package --bootstrap -p "$profile" -i `guix build guile-bootstrap`
  38. test "`guix package -A guile-bootstrap | cut -f 1-2`" \
  39. = "`guix package -p "$profile" -I | cut -f 1-2`"
  40. test "`guix package -p "$profile" -I | cut -f 3`" = "out"
  41. rm "$profile"
  42. guix package --bootstrap -p "$profile" -i guile-bootstrap
  43. test -L "$profile" && test -L "$profile-1-link"
  44. test -f "$profile/bin/guile"
  45. # Make sure the profile is a GC root.
  46. guix gc --list-live | grep "`readlink "$profile-1-link"`"
  47. # Installing the same package a second time does nothing.
  48. guix package --bootstrap -p "$profile" -i guile-bootstrap
  49. test -L "$profile" && test -L "$profile-1-link"
  50. ! test -f "$profile-2-link"
  51. test -f "$profile/bin/guile"
  52. # No search path env. var. here.
  53. guix package -p "$profile" --search-paths
  54. guix package -p "$profile" --search-paths | grep '^export PATH='
  55. test "`guix package -p "$profile" --search-paths | wc -l`" = 1 # $PATH
  56. ( set -e; set -x; \
  57. eval `guix package --search-paths=prefix -p "$PWD/$profile"`; \
  58. test "`type -P guile`" = "$PWD/$profile/bin/guile" ; \
  59. type -P rm )
  60. # Exit with 1 when a generation does not exist.
  61. if guix package -p "$profile" --delete-generations=42;
  62. then false; else true; fi
  63. # Exit with 0 when trying to delete the zeroth generation.
  64. guix package -p "$profile" --delete-generations=0
  65. # Make sure multiple arguments to -i works.
  66. guix package --bootstrap -i guile gcc -p "$profile" -n
  67. # Make sure the `:' syntax works.
  68. guix package --bootstrap -i "glibc:debug" -p "$profile" -n
  69. # Make sure nonexistent outputs are reported.
  70. guix package --bootstrap -i "guile-bootstrap:out" -p "$profile" -n
  71. if guix package --bootstrap -i "guile-bootstrap:does-not-exist" -p "$profile" -n;
  72. then false; else true; fi
  73. if guix package --bootstrap -i "guile-bootstrap:does-not-exist" -p "$profile";
  74. then false; else true; fi
  75. # Check whether `--list-available' returns something sensible.
  76. guix package -p "$profile" -A 'gui.*e' | grep guile
  77. # Check whether `--show' returns something sensible.
  78. guix package --show=guile | grep "^name: guile"
  79. # Ensure `--show' doesn't fail for packages with non-package inputs.
  80. guix package --show=texlive
  81. # Search.
  82. LC_MESSAGES=C
  83. export LC_MESSAGES
  84. test "`guix package -s "An example GNU package" | grep ^name:`" = \
  85. "name: hello"
  86. test -z "`guix package -s "n0t4r341p4ck4g3"`"
  87. # Search with one and then two regexps.
  88. # First we get printed circuit boards *and* board games.
  89. guix package -s '\<board\>' > "$tmpfile"
  90. grep '^name: pcb' "$tmpfile"
  91. grep '^name: gnubg' "$tmpfile"
  92. # Second we get only board games.
  93. guix package -s '\<board\>' -s game > "$tmpfile"
  94. grep -v '^name: pcb' "$tmpfile" > /dev/null
  95. grep '^name: gnubg' "$tmpfile"
  96. rm -f "$tmpfile"
  97. # Make sure `--search' can display all the packages.
  98. guix package --search="" > /dev/null
  99. # There's no generation older than 12 months, so the following command should
  100. # have no effect.
  101. generation="`readlink_base "$profile"`"
  102. if guix package -p "$profile" --delete-generations=12m;
  103. then false; else true; fi
  104. test "`readlink_base "$profile"`" = "$generation"
  105. # The following command should not delete the current generation, even though
  106. # it matches the given pattern (see <http://bugs.gnu.org/19978>.) And since
  107. # there's nothing else to delete, it should just fail.
  108. guix package --list-generations -p "$profile"
  109. if guix package --bootstrap -p "$profile" --delete-generations=1..
  110. then false; else true; fi
  111. test "`readlink_base "$profile"`" = "$generation"
  112. # Make sure $profile is a GC root at this point.
  113. real_profile="`readlink -f "$profile"`"
  114. if guix gc -d "$real_profile"
  115. then false; else true; fi
  116. test -d "$real_profile"
  117. # Now, let's remove all the symlinks to $real_profile, and make sure
  118. # $real_profile is no longer a GC root.
  119. rm "$profile" "$profile"-[0-9]-link
  120. guix gc -d "$real_profile"
  121. [ ! -d "$real_profile" ]
  122. # Package transformations.
  123. # Make sure we get the right version number when using '--with-source'.
  124. mkdir "$module_dir"
  125. emacs_tarball="$module_dir/emacs-42.5.9rc7.tar.gz"
  126. touch "$emacs_tarball"
  127. guix package -p "$profile" -i emacs --with-source="$emacs_tarball" -n \
  128. 2> "$tmpfile"
  129. grep -E 'emacs[[:blank:]]+42\.5\.9rc7[[:blank:]]+.*-emacs-42.5.9rc7' \
  130. "$tmpfile"
  131. rm "$emacs_tarball" "$tmpfile"
  132. rmdir "$module_dir"
  133. #
  134. # Try with the default profile.
  135. #
  136. XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
  137. export XDG_CACHE_HOME
  138. HOME="$PWD/t-home-$$"
  139. export HOME
  140. mkdir -p "$HOME"
  141. # Get the canonical directory name so that 'guix package' recognizes it.
  142. HOME="`cd $HOME; pwd -P`"
  143. guix package --bootstrap -i guile-bootstrap
  144. test -L "$HOME/.guix-profile"
  145. test -f "$HOME/.guix-profile/bin/guile"
  146. # Move to the empty profile.
  147. default_profile="`readlink "$HOME/.guix-profile"`"
  148. for i in `seq 1 3`
  149. do
  150. # Make sure the current generation is a GC root.
  151. profile_link="`readlink "$default_profile"`"
  152. guix gc --list-live | grep "`readlink "$profile_link"`"
  153. guix package --bootstrap --roll-back
  154. ! test -f "$HOME/.guix-profile/bin"
  155. ! test -f "$HOME/.guix-profile/lib"
  156. test "`readlink "$default_profile"`" = "$default_profile-0-link"
  157. done
  158. # Check whether '-p ~/.guix-profile' makes any difference.
  159. # See <http://bugs.gnu.org/17939>.
  160. if test -e "$HOME/.guix-profile-0-link"; then false; fi
  161. if test -e "$HOME/.guix-profile-1-link"; then false; fi
  162. guix package --bootstrap -p "$HOME/.guix-profile" -i guile-bootstrap
  163. if test -e "$HOME/.guix-profile-1-link"; then false; fi
  164. guix package --bootstrap --roll-back -p "$HOME/.guix-profile"
  165. if test -e "$HOME/.guix-profile-0-link"; then false; fi
  166. # Extraneous argument.
  167. if guix package install foo-bar;
  168. then false; else true; fi
  169. # Make sure the "broken pipe" doesn't yield an error.
  170. # Note: 'pipefail' is a Bash-specific option.
  171. set -o pipefail || true
  172. guix package -A g | head -1 2> "$HOME/err1"
  173. guix package -I | head -1 2> "$HOME/err2"
  174. test "`cat "$HOME/err1" "$HOME/err2"`" = ""
  175. # Make sure '-L' extends the package module search path.
  176. mkdir "$module_dir"
  177. cat > "$module_dir/foo.scm"<<EOF
  178. (define-module (foo)
  179. #:use-module (guix packages)
  180. #:use-module (gnu packages emacs))
  181. (define-public x
  182. (package (inherit emacs)
  183. (name "emacs-foo-bar")
  184. (version "42")))
  185. EOF
  186. guix package -A emacs-foo-bar -L "$module_dir" | grep 42
  187. guix package -i emacs-foo-bar@42 -n -L "$module_dir"
  188. # Same thing using the 'GUIX_PACKAGE_PATH' environment variable.
  189. GUIX_PACKAGE_PATH="$module_dir"
  190. export GUIX_PACKAGE_PATH
  191. guix package -A emacs-foo-bar | grep 42
  192. guix package -i emacs-foo-bar@42 -n
  193. # Make sure patches that live under $GUIX_PACKAGE_PATH are found.
  194. cat > "$module_dir/emacs.patch"<<EOF
  195. This is a fake patch.
  196. EOF
  197. cat > "$module_dir/foo.scm"<<EOF
  198. (define-module (foo)
  199. #:use-module (guix packages)
  200. #:use-module (gnu packages)
  201. #:use-module (gnu packages emacs))
  202. (define-public x
  203. (package (inherit emacs)
  204. (source (origin (inherit (package-source emacs))
  205. (patches (list (search-patch "emacs.patch")))))
  206. (name "emacs-foo-bar-patched")
  207. (version "42")))
  208. (define-public y
  209. (package (inherit emacs)
  210. (name "super-non-portable-emacs")
  211. (supported-systems '("foobar64-hurd"))))
  212. EOF
  213. guix package -i emacs-foo-bar-patched -n
  214. # Same when -L is used.
  215. ( unset GUIX_PACKAGE_PATH; \
  216. guix package -L "$module_dir" -i emacs-foo-bar-patched -n )
  217. # Make sure installing from a file works.
  218. cat > "$module_dir/package.scm"<<EOF
  219. (use-modules (gnu))
  220. (use-package-modules bootstrap)
  221. %bootstrap-guile
  222. EOF
  223. guix package --bootstrap --install-from-file="$module_dir/package.scm"
  224. # This one should not show up in searches since it's no supported on the
  225. # current system.
  226. test "`guix package -A super-non-portable-emacs`" = ""
  227. test "`guix package -s super-non-portable-emacs | grep ^systems:`" = "systems: "
  228. # Don't upgrade packages marked for removal: <http://bugs.gnu.org/27262>.
  229. guix package --bootstrap -p "$profile" -i guile-bootstrap
  230. cat > "$module_dir/foo.scm"<<EOF
  231. (define-module (foo)
  232. #:use-module (guix)
  233. #:use-module (gnu packages bootstrap))
  234. (define-public x
  235. (package (inherit %bootstrap-guile) (version "42")))
  236. EOF
  237. guix package --bootstrap -p "$profile" -r guile-bootstrap -u guile
  238. test ! -f "$profile/bin/guile"
  239. guix package --bootstrap -p "$profile" --roll-back
  240. test -f "$profile/bin/guile"
  241. rm "$profile-2-link"
  242. unset GUIX_PACKAGE_PATH
  243. # Using 'GUIX_BUILD_OPTIONS'.
  244. available="`guix package -A | sort`"
  245. GUIX_BUILD_OPTIONS="--dry-run --no-grafts"
  246. export GUIX_BUILD_OPTIONS
  247. # Make sure $GUIX_BUILD_OPTIONS is not simply appended to the command-line,
  248. # which would break 'guix package -A' and similar.
  249. available2="`guix package -A | sort`"
  250. test "$available2" = "$available"
  251. guix package -I
  252. # Restore '--no-grafts', which makes sure we don't end up building stuff when
  253. # '--dry-run' is passed.
  254. GUIX_BUILD_OPTIONS="--no-grafts"
  255. # Applying a manifest file.
  256. cat > "$module_dir/manifest.scm"<<EOF
  257. (use-package-modules bootstrap)
  258. (packages->manifest (list %bootstrap-guile))
  259. EOF
  260. guix package --bootstrap -m "$module_dir/manifest.scm"
  261. guix package -I | grep guile
  262. test `guix package -I | wc -l` -eq 1
  263. # Error reporting.
  264. cat > "$module_dir/manifest.scm"<<EOF
  265. (use-package-modules bootstrap)
  266. (packages->manifest
  267. (list %bootstrap-guile
  268. wonderful-package-that-does-not-exist))
  269. EOF
  270. if guix package --bootstrap -n -m "$module_dir/manifest.scm" \
  271. 2> "$module_dir/stderr"
  272. then false
  273. else
  274. cat "$module_dir/stderr"
  275. grep "manifest.scm:[1-3]:.*wonderful-package.*: unbound variable" \
  276. "$module_dir/stderr"
  277. fi