guix-package-net.sh 7.1 KB

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