guix-package-net.sh 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. # GNU Guix --- Functional package management for GNU
  2. # Copyright © 2012-2015, 2017, 2019, 2022 Ludovic Courtès <ludo@gnu.org>
  3. # Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
  4. # Copyright © 2020 Simon Tournier <zimon.toutoune@gmail.com>
  5. #
  6. # This file is part of GNU Guix.
  7. #
  8. # GNU Guix is free software; you can redistribute it and/or modify it
  9. # under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 3 of the License, or (at
  11. # your option) any later version.
  12. #
  13. # GNU Guix is distributed in the hope that it will be useful, but
  14. # WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. # Test the `guix package' command-line utility. This test requires network
  22. # access and is skipped when that is lacking.
  23. #
  24. guix package --version
  25. readlink_base ()
  26. {
  27. basename `readlink "$1"`
  28. }
  29. # Return true if a typical shebang in the store would exceed Linux's default
  30. # static limit.
  31. shebang_too_long ()
  32. {
  33. test `echo $NIX_STORE_DIR/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bootstrap-binaries-0/bin/bash | wc -c` \
  34. -ge 128
  35. }
  36. if ! guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null \
  37. || shebang_too_long
  38. then
  39. # Skipping.
  40. exit 77
  41. fi
  42. profile="t-profile-$$"
  43. profile_alt="t-profile-alt-$$"
  44. rm -f "$profile"
  45. module_dir="t-guix-package-net-$$"
  46. mkdir "$module_dir"
  47. trap 'rm -f "$profile" "$profile_alt" "$profile.lock" "$profile_alt.lock" "$profile-"[0-9]* "$profile_alt-"[0-9]* ; rm -r "$module_dir" t-home-'"$$" EXIT
  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. boot_make="(@ (guix tests) gnu-make-for-tests)"
  53. boot_make_drv="`guix build -e "$boot_make" | grep -v -e -debug`"
  54. guix package --bootstrap -p "$profile" -i "$boot_make_drv"
  55. test -L "$profile-2-link"
  56. test -f "$profile/bin/make" && test -f "$profile/bin/guile"
  57. # Check whether `--list-installed' works.
  58. # XXX: Change the tests when `--install' properly extracts the package
  59. # name and version string.
  60. installed="`guix package -p "$profile" --list-installed | cut -f1 | xargs echo | sort`"
  61. case "x$installed" in
  62. "guile-bootstrap make-boot0")
  63. true;;
  64. "make-boot0 guile-bootstrap")
  65. true;;
  66. "*")
  67. false;;
  68. esac
  69. test "`guix package -p "$profile" -I 'g.*e' | cut -f1`" = "guile-bootstrap"
  70. guix package --bootstrap -p "$profile_alt" -i gcc-bootstrap
  71. installed="`guix package -p "$profile" -p "$profile_alt" -I | cut -f1 | xargs echo | sort`"
  72. case "x$installed" in
  73. "gcc-bootstrap guile-bootstrap make-boot0")
  74. true;;
  75. "*")
  76. false;;
  77. esac
  78. test "`guix package -p "$profile_alt" -p "$profile" -I | wc -l`" = "3"
  79. rm "$profile_alt"
  80. # List generations.
  81. test "`guix package -p "$profile" -l | cut -f1 | grep guile | head -n1`" \
  82. = " guile-bootstrap"
  83. # Exit with 1 when a generation does not exist.
  84. guix package -p "$profile" --list-generations=42 && false
  85. guix package -p "$profile" --switch-generation=99 && false
  86. # Remove a package.
  87. guix package --bootstrap -p "$profile" -r "guile-bootstrap"
  88. test -L "$profile-3-link"
  89. test -f "$profile/bin/make" && test ! -f "$profile/bin/guile"
  90. # Roll back.
  91. guix package --roll-back -p "$profile"
  92. test "`readlink_base "$profile"`" = "$profile-2-link"
  93. test -x "$profile/bin/guile" && test -x "$profile/bin/make"
  94. guix package --roll-back -p "$profile"
  95. test "`readlink_base "$profile"`" = "$profile-1-link"
  96. test -x "$profile/bin/guile" && test ! -x "$profile/bin/make"
  97. # Switch to the rolled generation and switch back.
  98. guix package -p "$profile" --switch-generation=2
  99. test "`readlink_base "$profile"`" = "$profile-2-link"
  100. guix package -p "$profile" --switch-generation=-1
  101. test "`readlink_base "$profile"`" = "$profile-1-link"
  102. # Move to the empty profile.
  103. for i in `seq 1 3`
  104. do
  105. guix package --bootstrap --roll-back -p "$profile"
  106. test ! -f "$profile/bin"
  107. test ! -f "$profile/lib"
  108. test "`readlink_base "$profile"`" = "$profile-0-link"
  109. done
  110. # Test that '--list-generations' does not output the zeroth generation.
  111. test -z "`guix package -p "$profile" -l 0`"
  112. # Reinstall after roll-back to the empty profile.
  113. guix package --bootstrap -p "$profile" -e "$boot_make"
  114. test "`readlink_base "$profile"`" = "$profile-1-link"
  115. test -x "$profile/bin/guile" && test ! -x "$profile/bin/make"
  116. # Check that the first generation is the current one.
  117. test "`guix package -p "$profile" -l 1 | cut -f3 | head -n1`" = "(current)"
  118. # Roll-back to generation 0, and install---all at once.
  119. guix package --bootstrap -p "$profile" --roll-back -i guile-bootstrap
  120. test "`readlink_base "$profile"`" = "$profile-1-link"
  121. test -x "$profile/bin/guile" && test ! -x "$profile/bin/make"
  122. # Install Make.
  123. guix package --bootstrap -p "$profile" -e "$boot_make"
  124. test "`readlink_base "$profile"`" = "$profile-2-link"
  125. test -x "$profile/bin/guile" && test -x "$profile/bin/make"
  126. grep "`guix build -e "$boot_make"`" "$profile/manifest"
  127. # Make a "hole" in the list of generations, and make sure we can
  128. # roll back and switch "over" it.
  129. rm "$profile-1-link"
  130. guix package --bootstrap -p "$profile" --roll-back
  131. test "`readlink_base "$profile"`" = "$profile-0-link"
  132. guix package -p "$profile" --switch-generation=+1
  133. test "`readlink_base "$profile"`" = "$profile-2-link"
  134. # Make sure LIBRARY_PATH gets listed by `--search-paths'.
  135. guix package --bootstrap -p "$profile" -i guile-bootstrap -i gcc-bootstrap
  136. guix package -p "$profile" --search-paths | grep LIBRARY_PATH
  137. # Roll back so we can delete #3 below.
  138. guix package -p "$profile" --switch-generation=2
  139. # Delete the third generation and check that it was actually deleted.
  140. guix package -p "$profile" --delete-generations=3
  141. test -z "`guix package -p "$profile" -l 3`"
  142. # Search path of combined profiles. 'LIBRARY_PATH' should show up only in the
  143. # combination, not in the individual profiles.
  144. rm "$profile"
  145. guix package --bootstrap -p "$profile" -i guile-bootstrap
  146. guix package --bootstrap -p "$profile_alt" -i gcc-bootstrap
  147. guix package -p "$profile" --search-paths | grep LIBRARY_PATH && false
  148. guix package -p "$profile" -p "$profile_alt" --search-paths \
  149. | grep "LIBRARY_PATH.*$profile/lib.$profile_alt/lib"
  150. # Simulate an upgrade and make sure the package order is preserved.
  151. cat > "$module_dir/new.scm" <<EOF
  152. (define-module (new)
  153. #:use-module (guix)
  154. #:use-module (gnu packages bootstrap))
  155. (define-public new-guile
  156. (package (inherit %bootstrap-guile)
  157. (version (string-append "42." (getenv "V_MINOR")))))
  158. (define-public new-gcc
  159. (package (inherit %bootstrap-gcc)
  160. (version (string-append "77." (getenv "V_MINOR")))))
  161. EOF
  162. guix package --bootstrap -p "$profile" -i gcc-bootstrap
  163. installed="`guix package -p "$profile" -I | cut -f1`"
  164. # Dry-run upgrade. Make sure no new generation is created when things are
  165. # already in store and '-n' is used: <https://issues.guix.gnu.org/53267>.
  166. V_MINOR=0
  167. export V_MINOR
  168. profile_before="$(readlink "$profile")"
  169. guix package -p "$profile" --bootstrap -L "$module_dir" -u # build the profile
  170. guix package -p "$profile" --roll-back
  171. guix package -p "$profile" --bootstrap -L "$module_dir" -u . -n # check '-n'
  172. test "$(readlink "$profile")" = "$profile_before"
  173. for i in 1 2
  174. do
  175. V_MINOR="$i"
  176. export V_MINOR
  177. guix package -p "$profile" --bootstrap -L "$module_dir" -u .
  178. post_upgrade="`guix package -p "$profile" -I | cut -f1`"
  179. test "$post_upgrade" = "$installed"
  180. done
  181. #
  182. # Try with the default profile.
  183. #
  184. XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
  185. export XDG_CACHE_HOME
  186. HOME="$PWD/t-home-$$"
  187. export HOME
  188. mkdir -p "$HOME"
  189. # Get the canonical directory name so that 'guix package' recognizes it.
  190. HOME="`cd $HOME; pwd -P`"
  191. guix package --bootstrap -e "$boot_make"
  192. test -f "$HOME/.guix-profile/bin/make"
  193. guix package --bootstrap --roll-back
  194. test ! -f "$HOME/.guix-profile/bin/make"