guix-package-net.sh 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. # GNU Guix --- Functional package management for GNU
  2. # Copyright © 2012, 2013, 2014, 2015, 2017, 2019 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. trap 'rm -f "$profile" "$profile_alt" "$profile-"[0-9]* "$profile_alt-"[0-9]* ; rm -rf t-home-'"$$" EXIT
  46. guix package --bootstrap -p "$profile" -i guile-bootstrap
  47. test -L "$profile" && test -L "$profile-1-link"
  48. ! test -f "$profile-2-link"
  49. test -f "$profile/bin/guile"
  50. boot_make="(@ (guix tests) gnu-make-for-tests)"
  51. boot_make_drv="`guix build -e "$boot_make" | grep -v -e -debug`"
  52. guix package --bootstrap -p "$profile" -i "$boot_make_drv"
  53. test -L "$profile-2-link"
  54. test -f "$profile/bin/make" && test -f "$profile/bin/guile"
  55. # Check whether `--list-installed' works.
  56. # XXX: Change the tests when `--install' properly extracts the package
  57. # name and version string.
  58. installed="`guix package -p "$profile" --list-installed | cut -f1 | xargs echo | sort`"
  59. case "x$installed" in
  60. "guile-bootstrap make-boot0")
  61. true;;
  62. "make-boot0 guile-bootstrap")
  63. true;;
  64. "*")
  65. false;;
  66. esac
  67. test "`guix package -p "$profile" -I 'g.*e' | cut -f1`" = "guile-bootstrap"
  68. guix package --bootstrap -p "$profile_alt" -i gcc-bootstrap
  69. installed="`guix package -p "$profile" -p "$profile_alt" -I | cut -f1 | xargs echo | sort`"
  70. case "x$installed" in
  71. "gcc-bootstrap guile-bootstrap make-boot0")
  72. true;;
  73. "*")
  74. false;;
  75. esac
  76. test "`guix package -p "$profile_alt" -p "$profile" -I | wc -l`" = "3"
  77. rm "$profile_alt"
  78. # List generations.
  79. test "`guix package -p "$profile" -l | cut -f1 | grep guile | head -n1`" \
  80. = " guile-bootstrap"
  81. # Exit with 1 when a generation does not exist.
  82. ! guix package -p "$profile" --list-generations=42
  83. ! guix package -p "$profile" --switch-generation=99
  84. # Remove a package.
  85. guix package --bootstrap -p "$profile" -r "guile-bootstrap"
  86. test -L "$profile-3-link"
  87. test -f "$profile/bin/make" && ! test -f "$profile/bin/guile"
  88. # Roll back.
  89. guix package --roll-back -p "$profile"
  90. test "`readlink_base "$profile"`" = "$profile-2-link"
  91. test -x "$profile/bin/guile" && test -x "$profile/bin/make"
  92. guix package --roll-back -p "$profile"
  93. test "`readlink_base "$profile"`" = "$profile-1-link"
  94. test -x "$profile/bin/guile" && ! test -x "$profile/bin/make"
  95. # Switch to the rolled generation and switch back.
  96. guix package -p "$profile" --switch-generation=2
  97. test "`readlink_base "$profile"`" = "$profile-2-link"
  98. guix package -p "$profile" --switch-generation=-1
  99. test "`readlink_base "$profile"`" = "$profile-1-link"
  100. # Move to the empty profile.
  101. for i in `seq 1 3`
  102. do
  103. guix package --bootstrap --roll-back -p "$profile"
  104. ! test -f "$profile/bin"
  105. ! test -f "$profile/lib"
  106. test "`readlink_base "$profile"`" = "$profile-0-link"
  107. done
  108. # Test that '--list-generations' does not output the zeroth generation.
  109. test -z "`guix package -p "$profile" -l 0`"
  110. # Reinstall after roll-back to the empty profile.
  111. guix package --bootstrap -p "$profile" -e "$boot_make"
  112. test "`readlink_base "$profile"`" = "$profile-1-link"
  113. test -x "$profile/bin/guile" && ! test -x "$profile/bin/make"
  114. # Check that the first generation is the current one.
  115. test "`guix package -p "$profile" -l 1 | cut -f3 | head -n1`" = "(current)"
  116. # Roll-back to generation 0, and install---all at once.
  117. guix package --bootstrap -p "$profile" --roll-back -i guile-bootstrap
  118. test "`readlink_base "$profile"`" = "$profile-1-link"
  119. test -x "$profile/bin/guile" && ! test -x "$profile/bin/make"
  120. # Install Make.
  121. guix package --bootstrap -p "$profile" -e "$boot_make"
  122. test "`readlink_base "$profile"`" = "$profile-2-link"
  123. test -x "$profile/bin/guile" && test -x "$profile/bin/make"
  124. grep "`guix build -e "$boot_make"`" "$profile/manifest"
  125. # Make a "hole" in the list of generations, and make sure we can
  126. # roll back and switch "over" it.
  127. rm "$profile-1-link"
  128. guix package --bootstrap -p "$profile" --roll-back
  129. test "`readlink_base "$profile"`" = "$profile-0-link"
  130. guix package -p "$profile" --switch-generation=+1
  131. test "`readlink_base "$profile"`" = "$profile-2-link"
  132. # Make sure LIBRARY_PATH gets listed by `--search-paths'.
  133. guix package --bootstrap -p "$profile" -i guile-bootstrap -i gcc-bootstrap
  134. guix package -p "$profile" --search-paths | grep LIBRARY_PATH
  135. # Roll back so we can delete #3 below.
  136. guix package -p "$profile" --switch-generation=2
  137. # Delete the third generation and check that it was actually deleted.
  138. guix package -p "$profile" --delete-generations=3
  139. test -z "`guix package -p "$profile" -l 3`"
  140. # Search path of combined profiles. 'LIBRARY_PATH' should show up only in the
  141. # combination, not in the individual profiles.
  142. rm "$profile"
  143. guix package --bootstrap -p "$profile" -i guile-bootstrap
  144. guix package --bootstrap -p "$profile_alt" -i gcc-bootstrap
  145. ! guix package -p "$profile" --search-paths | grep LIBRARY_PATH
  146. guix package -p "$profile" -p "$profile_alt" --search-paths \
  147. | grep "LIBRARY_PATH.*$profile/lib.$profile_alt/lib"
  148. # Simulate an upgrade and make sure the package order is preserved.
  149. module_dir="t-guix-package-net-$$"
  150. trap 'rm -rf "$module_dir"' EXIT
  151. mkdir "$module_dir"
  152. cat > "$module_dir/new.scm" <<EOF
  153. (define-module (new)
  154. #:use-module (guix)
  155. #:use-module (gnu packages bootstrap))
  156. (define-public new-guile
  157. (package (inherit %bootstrap-guile)
  158. (version (string-append "42." (getenv "V_MINOR")))))
  159. (define-public new-gcc
  160. (package (inherit %bootstrap-gcc)
  161. (version (string-append "77." (getenv "V_MINOR")))))
  162. EOF
  163. guix package --bootstrap -p "$profile" -i gcc-bootstrap
  164. installed="`guix package -p "$profile" -I | cut -f1`"
  165. for i in 1 2
  166. do
  167. V_MINOR="$i"
  168. export V_MINOR
  169. guix package -p "$profile" --bootstrap -L "$module_dir" -u .
  170. post_upgrade="`guix package -p "$profile" -I | cut -f1`"
  171. test "$post_upgrade" = "$installed"
  172. done
  173. #
  174. # Try with the default profile.
  175. #
  176. XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
  177. export XDG_CACHE_HOME
  178. HOME="$PWD/t-home-$$"
  179. export HOME
  180. mkdir -p "$HOME"
  181. # Get the canonical directory name so that 'guix package' recognizes it.
  182. HOME="`cd $HOME; pwd -P`"
  183. guix package --bootstrap -e "$boot_make"
  184. test -f "$HOME/.guix-profile/bin/make"
  185. guix package --bootstrap --roll-back
  186. ! test -f "$HOME/.guix-profile/bin/make"