guix-environment.sh 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 '--inherit'.
  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. --inherit='^GUIX_TEST_A' --inherit='^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. if grep '^GUIX_TEST_XYZ=' "$tmpdir/a"; then false; else true; fi
  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 '-r' works as expected.
  72. rm -f "$gcroot"
  73. expected="`guix environment --bootstrap --ad-hoc guile-bootstrap \
  74. -- "$SHELL" -c 'echo $GUIX_ENVIRONMENT'`"
  75. guix environment --bootstrap -r "$gcroot" --ad-hoc guile-bootstrap \
  76. -- guile -c 1
  77. test `readlink "$gcroot"` = "$expected"
  78. # Make sure '-r' is idempotent.
  79. guix environment --bootstrap -r "$gcroot" --ad-hoc guile-bootstrap \
  80. -- guile -c 1
  81. test `readlink "$gcroot"` = "$expected"
  82. rm "$gcroot"
  83. # Same with an absolute file name.
  84. guix environment --bootstrap -r "$PWD/$gcroot" --ad-hoc guile-bootstrap \
  85. -- guile -c 1
  86. test `readlink "$gcroot"` = "$expected"
  87. case "`uname -m`" in
  88. x86_64)
  89. # On x86_64, we should be able to create a 32-bit environment.
  90. guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
  91. -- guile -c '(exit (string-prefix? "x86_64" %host-type))'
  92. guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
  93. -s i686-linux \
  94. -- guile -c '(exit (string-prefix? "i686" %host-type))'
  95. ;;
  96. *)
  97. echo "nothing to do" >&2
  98. ;;
  99. esac
  100. # Same as above, but with deprecated -E flag.
  101. if guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
  102. -E "guile -c '(exit 42)'"
  103. then
  104. false
  105. else
  106. test $? = 42
  107. fi
  108. # Make sure we can build the environment of 'guix'. There may be collisions
  109. # in its profile (e.g., for 'gzip'), but we have to accept them.
  110. guix environment guix --bootstrap -n
  111. # Try program transformation options.
  112. mkdir "$tmpdir/emacs-36.8"
  113. drv="`guix environment --ad-hoc emacs -n 2>&1 | grep 'emacs.*\.drv'`"
  114. transformed_drv="`guix environment --ad-hoc emacs --with-source="$tmpdir/emacs-36.8" -n 2>&1 | grep 'emacs.*\.drv'`"
  115. test -n "$drv"
  116. test "$drv" != "$transformed_drv"
  117. case "$transformed_drv" in
  118. *-emacs-36.8.drv) true;;
  119. *) false;;
  120. esac
  121. rmdir "$tmpdir/emacs-36.8"
  122. if guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null
  123. then
  124. # Compute the build environment for the initial GNU Make.
  125. guix environment --bootstrap --no-substitutes --search-paths --pure \
  126. -e '(@@ (gnu packages commencement) gnu-make-boot0)' > "$tmpdir/a"
  127. # Make sure bootstrap binaries are in the profile.
  128. profile=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
  129. # Make sure the bootstrap binaries are all listed where they belong.
  130. grep -E "^export PATH=\"$profile/bin\"" "$tmpdir/a"
  131. grep -E "^export CPATH=\"$profile/include\"" "$tmpdir/a"
  132. grep -E "^export LIBRARY_PATH=\"$profile/lib\"" "$tmpdir/a"
  133. for dep in bootstrap-binaries-0 gcc-bootstrap-0 glibc-bootstrap-0
  134. do
  135. guix gc --references "$profile" | grep "$dep"
  136. done
  137. # 'make-boot0' itself must not be listed.
  138. if guix gc --references "$profile" | grep make-boot0
  139. then false; else true; fi
  140. # Make sure that the shell spawned with '--exec' sees the same environment
  141. # as returned by '--search-paths'.
  142. guix environment --bootstrap --no-substitutes --pure \
  143. -e '(@@ (gnu packages commencement) gnu-make-boot0)' \
  144. -- /bin/sh -c 'echo $PATH $CPATH $LIBRARY_PATH' > "$tmpdir/b"
  145. ( . "$tmpdir/a" ; echo $PATH $CPATH $LIBRARY_PATH ) > "$tmpdir/c"
  146. cmp "$tmpdir/b" "$tmpdir/c"
  147. rm "$tmpdir"/*
  148. # Compute the build environment for the initial GNU Findutils.
  149. guix environment --bootstrap --no-substitutes --search-paths --pure \
  150. -e '(@@ (gnu packages commencement) findutils-boot0)' > "$tmpdir/a"
  151. profile=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
  152. # Make sure the bootstrap binaries are all listed where they belong.
  153. grep -E "^export PATH=\"$profile/bin\"" "$tmpdir/a"
  154. grep -E "^export CPATH=\"$profile/include\"" "$tmpdir/a"
  155. grep -E "^export LIBRARY_PATH=\"$profile/lib\"" "$tmpdir/a"
  156. for dep in bootstrap-binaries-0 gcc-bootstrap-0 glibc-bootstrap-0 \
  157. make-boot0
  158. do
  159. guix gc --references "$profile" | grep "$dep"
  160. done
  161. # The following test assumes 'make-boot0' has a "debug" output.
  162. make_boot0_debug="`guix build -e '(@@ (gnu packages commencement) gnu-make-boot0)' | grep -e -debug`"
  163. test "x$make_boot0_debug" != "x"
  164. # Make sure the "debug" output is not listed.
  165. if guix gc --references "$profile" | grep "$make_boot0_debug"
  166. then false; else true; fi
  167. # Compute the build environment for the initial GNU Make, but add in the
  168. # bootstrap Guile as an ad-hoc addition.
  169. guix environment --bootstrap --no-substitutes --search-paths --pure \
  170. -e '(@@ (gnu packages commencement) gnu-make-boot0)' \
  171. --ad-hoc guile-bootstrap > "$tmpdir/a"
  172. profile=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
  173. # Make sure the bootstrap binaries are all listed where they belong.
  174. grep -E "^export PATH=\"$profile/bin\"" "$tmpdir/a"
  175. grep -E "^export CPATH=\"$profile/include\"" "$tmpdir/a"
  176. grep -E "^export LIBRARY_PATH=\"$profile/lib\"" "$tmpdir/a"
  177. for dep in bootstrap-binaries-0 gcc-bootstrap-0 glibc-bootstrap-0 \
  178. guile-bootstrap
  179. do
  180. guix gc --references "$profile" | grep "$dep"
  181. done
  182. # Make sure a package list with plain package objects and package+output
  183. # tuples can be used with -e.
  184. expr_list_test_code="
  185. (list (@@ (gnu packages commencement) gnu-make-boot0)
  186. (list (@ (gnu packages bootstrap) %bootstrap-guile) \"out\"))"
  187. guix environment --bootstrap --ad-hoc --no-substitutes --search-paths \
  188. --pure -e "$expr_list_test_code" > "$tmpdir/a"
  189. profile=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
  190. for dep in make-boot0 guile-bootstrap
  191. do
  192. guix gc --references "$profile" | grep "$dep"
  193. done
  194. fi