guix-environment.sh 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. # GNU Guix --- Functional package management for GNU
  2. # Copyright © 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
  3. #
  4. # This file is part of GNU Guix.
  5. #
  6. # GNU Guix is free software; you can redistribute it and/or modify it
  7. # under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3 of the License, or (at
  9. # your option) any later version.
  10. #
  11. # GNU Guix is distributed in the hope that it will be useful, but
  12. # WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. # Test 'guix environment'.
  20. #
  21. set -e
  22. guix environment --version
  23. tmpdir="t-guix-environment-$$"
  24. gcroot="t-guix-environment-gc-root-$$"
  25. trap 'rm -r "$tmpdir"; rm -f "$gcroot"' EXIT
  26. mkdir "$tmpdir"
  27. # 'guix environment' launches /bin/sh if 'SHELL' is unset, so export 'SHELL'
  28. # since we know it's valid (build environments lack /bin/sh.)
  29. export SHELL
  30. # Check the environment variables for the bootstrap Guile.
  31. guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
  32. --search-paths > "$tmpdir/a"
  33. guix environment --bootstrap --ad-hoc guile-bootstrap:out --pure \
  34. --search-paths > "$tmpdir/b"
  35. # $PATH must appear in the search paths, and nothing else.
  36. grep -E '^export PATH=.*profile/bin' "$tmpdir/a"
  37. test "`wc -l < "$tmpdir/a"`" = 1
  38. # Guile must be on $PATH.
  39. test -x `sed -r 's/^export PATH="(.*)"/\1/' "$tmpdir/a"`/guile
  40. cmp "$tmpdir/a" "$tmpdir/b"
  41. # Check '--preserve'.
  42. GUIX_TEST_ABC=1
  43. GUIX_TEST_DEF=2
  44. GUIX_TEST_XYZ=3
  45. export GUIX_TEST_ABC GUIX_TEST_DEF GUIX_TEST_XYZ
  46. guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
  47. --preserve='^GUIX_TEST_A' --preserve='^GUIX_TEST_D' \
  48. -- "$SHELL" -c set > "$tmpdir/a"
  49. grep '^PATH=' "$tmpdir/a"
  50. grep '^GUIX_TEST_ABC=' "$tmpdir/a"
  51. grep '^GUIX_TEST_DEF=' "$tmpdir/a"
  52. ! grep '^GUIX_TEST_XYZ=' "$tmpdir/a"
  53. # Make sure the exit value is preserved.
  54. if guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
  55. -- guile -c '(exit 42)'
  56. then
  57. false
  58. else
  59. test $? = 42
  60. fi
  61. # Make sure 'GUIX_ENVIRONMENT' points to the profile.
  62. guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
  63. -- "$SHELL" -c 'test -f "$GUIX_ENVIRONMENT/bin/guile"'
  64. # Make sure 'GUIX_ENVIRONMENT' points to the profile when building from a
  65. # manifest.
  66. echo "(use-modules (guix profiles) (gnu packages bootstrap))
  67. (packages->manifest (list %bootstrap-guile))
  68. " > $tmpdir/manifest.scm
  69. guix environment --bootstrap --manifest=$tmpdir/manifest.scm --pure \
  70. -- "$SHELL" -c 'test -f "$GUIX_ENVIRONMENT/bin/guile"'
  71. # Make sure '--manifest' can be specified multiple times.
  72. cat > "$tmpdir/manifest2.scm" <<EOF
  73. (use-modules (guix) (guix profiles)
  74. (guix build-system trivial)
  75. (gnu packages bootstrap))
  76. (packages->manifest
  77. (list (package
  78. (inherit %bootstrap-guile)
  79. (name "eliug")
  80. (build-system trivial-build-system)
  81. (arguments
  82. (quasiquote
  83. (#:guile ,%bootstrap-guile
  84. #:builder
  85. (begin
  86. (mkdir %output)
  87. (mkdir (string-append %output "/eliug")))))))))
  88. EOF
  89. guix environment --bootstrap -m "$tmpdir/manifest.scm" \
  90. -m "$tmpdir/manifest2.scm" --pure \
  91. -- "$SHELL" -c 'test -f "$GUIX_ENVIRONMENT/bin/guile" && test -d "$GUIX_ENVIRONMENT/eliug"'
  92. # Make sure '-r' works as expected.
  93. rm -f "$gcroot"
  94. expected="`guix environment --bootstrap --ad-hoc guile-bootstrap \
  95. -- "$SHELL" -c 'echo $GUIX_ENVIRONMENT'`"
  96. guix environment --bootstrap -r "$gcroot" --ad-hoc guile-bootstrap \
  97. -- guile -c 1
  98. test `readlink "$gcroot"` = "$expected"
  99. # Make sure '-r' is idempotent.
  100. guix environment --bootstrap -r "$gcroot" --ad-hoc guile-bootstrap \
  101. -- guile -c 1
  102. test `readlink "$gcroot"` = "$expected"
  103. rm "$gcroot"
  104. # Same with an absolute file name.
  105. guix environment --bootstrap -r "$PWD/$gcroot" --ad-hoc guile-bootstrap \
  106. -- guile -c 1
  107. test `readlink "$gcroot"` = "$expected"
  108. case "`uname -m`" in
  109. x86_64)
  110. # On x86_64, we should be able to create a 32-bit environment.
  111. guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
  112. -- guile -c '(exit (string-prefix? "x86_64" %host-type))'
  113. guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
  114. -s i686-linux \
  115. -- guile -c '(exit (string-prefix? "i686" %host-type))'
  116. ;;
  117. *)
  118. echo "nothing to do" >&2
  119. ;;
  120. esac
  121. # Make sure we can build the environment of 'guix'. There may be collisions
  122. # in its profile (e.g., for 'gzip'), but we have to accept them.
  123. guix environment guix --bootstrap -n
  124. # Try program transformation options.
  125. mkdir "$tmpdir/emacs-36.8"
  126. drv="`guix environment --ad-hoc emacs -n 2>&1 | grep 'emacs.*\.drv'`"
  127. transformed_drv="`guix environment --ad-hoc emacs --with-source="$tmpdir/emacs-36.8" -n 2>&1 | grep 'emacs.*\.drv'`"
  128. test -n "$drv"
  129. test "$drv" != "$transformed_drv"
  130. case "$transformed_drv" in
  131. *-emacs-36.8.drv) true;;
  132. *) false;;
  133. esac
  134. rmdir "$tmpdir/emacs-36.8"
  135. # Transformation options without '--ad-hoc'.
  136. drv="`guix environment -n emacs-geiser 2>&1 | grep '\.drv$'`"
  137. transformed_drv="`guix environment -n emacs-geiser \
  138. --with-input=emacs-minimal=vim 2>&1 | grep '\.drv$'`"
  139. test "$drv" != "$transformed_drv"
  140. case "$drv" in
  141. *-emacs-minimal*.drv*) true;;
  142. *) false;;
  143. esac
  144. case "$transformed_drv" in
  145. *-emacs-minimal*.drv*) false;;
  146. *) true;;
  147. esac
  148. case "$transformed_drv" in
  149. *-vim*.drv*) true;;
  150. *) false;;
  151. esac
  152. if guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null
  153. then
  154. # Compute the build environment for the initial GNU Make.
  155. guix environment --bootstrap --no-substitutes --search-paths --pure \
  156. -e '(@ (guix tests) gnu-make-for-tests)' > "$tmpdir/a"
  157. # Make sure bootstrap binaries are in the profile.
  158. profile=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
  159. # Make sure the bootstrap binaries are all listed where they belong.
  160. grep -E "^export PATH=\"$profile/bin\"" "$tmpdir/a"
  161. grep -E "^export CPATH=\"$profile/include\"" "$tmpdir/a"
  162. grep -E "^export LIBRARY_PATH=\"$profile/lib\"" "$tmpdir/a"
  163. for dep in bootstrap-binaries-0 gcc-bootstrap-0 glibc-bootstrap-0
  164. do
  165. guix gc --references "$profile" | grep "$dep"
  166. done
  167. # 'make-boot0' itself must not be listed.
  168. ! guix gc --references "$profile" | grep make-boot0
  169. # Make sure that the shell spawned with '--exec' sees the same environment
  170. # as returned by '--search-paths'.
  171. guix environment --bootstrap --no-substitutes --pure \
  172. -e '(@ (guix tests) gnu-make-for-tests)' \
  173. -- /bin/sh -c 'echo $PATH $CPATH $LIBRARY_PATH' > "$tmpdir/b"
  174. ( . "$tmpdir/a" ; echo $PATH $CPATH $LIBRARY_PATH ) > "$tmpdir/c"
  175. cmp "$tmpdir/b" "$tmpdir/c"
  176. rm "$tmpdir"/*
  177. # The following test assumes 'make-boot0' has a "debug" output.
  178. make_boot0_debug="`guix build -e '(@ (guix tests) gnu-make-for-tests)' | grep -e -debug`"
  179. test "x$make_boot0_debug" != "x"
  180. # Make sure the "debug" output is not listed.
  181. ! guix gc --references "$profile" | grep "$make_boot0_debug"
  182. # Compute the build environment for the initial GNU Make, but add in the
  183. # bootstrap Guile as an ad-hoc addition.
  184. guix environment --bootstrap --no-substitutes --search-paths --pure \
  185. -e '(@ (guix tests) gnu-make-for-tests)' \
  186. --ad-hoc guile-bootstrap > "$tmpdir/a"
  187. profile=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
  188. # Make sure the bootstrap binaries are all listed where they belong.
  189. grep -E "^export PATH=\"$profile/bin\"" "$tmpdir/a"
  190. grep -E "^export CPATH=\"$profile/include\"" "$tmpdir/a"
  191. grep -E "^export LIBRARY_PATH=\"$profile/lib\"" "$tmpdir/a"
  192. for dep in bootstrap-binaries-0 gcc-bootstrap-0 glibc-bootstrap-0 \
  193. guile-bootstrap
  194. do
  195. guix gc --references "$profile" | grep "$dep"
  196. done
  197. # Make sure a package list with plain package objects and package+output
  198. # tuples can be used with -e.
  199. expr_list_test_code="
  200. (list (@ (guix tests) gnu-make-for-tests)
  201. (list (@ (gnu packages bootstrap) %bootstrap-guile) \"out\"))"
  202. guix environment --bootstrap --ad-hoc --no-substitutes --search-paths \
  203. --pure -e "$expr_list_test_code" > "$tmpdir/a"
  204. profile=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
  205. for dep in make-test-boot0 guile-bootstrap
  206. do
  207. guix gc --references "$profile" | grep "$dep"
  208. done
  209. fi