guix-environment.sh 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. # GNU Guix --- Functional package management for GNU
  2. # Copyright © 2015, 2016, 2017 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. # Make sure the exit value is preserved.
  42. if guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
  43. -- guile -c '(exit 42)'
  44. then
  45. false
  46. else
  47. test $? = 42
  48. fi
  49. # Make sure 'GUIX_ENVIRONMENT' points to the profile.
  50. guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
  51. -- "$SHELL" -c 'test -f "$GUIX_ENVIRONMENT/bin/guile"'
  52. # Make sure '-r' works as expected.
  53. rm -f "$gcroot"
  54. expected="`guix environment --bootstrap --ad-hoc guile-bootstrap \
  55. -- "$SHELL" -c 'echo $GUIX_ENVIRONMENT'`"
  56. guix environment --bootstrap -r "$gcroot" --ad-hoc guile-bootstrap \
  57. -- guile -c 1
  58. test `readlink "$gcroot"` = "$expected"
  59. # Make sure '-r' is idempotent.
  60. guix environment --bootstrap -r "$gcroot" --ad-hoc guile-bootstrap \
  61. -- guile -c 1
  62. test `readlink "$gcroot"` = "$expected"
  63. rm "$gcroot"
  64. # Same with an absolute file name.
  65. guix environment --bootstrap -r "$PWD/$gcroot" --ad-hoc guile-bootstrap \
  66. -- guile -c 1
  67. test `readlink "$gcroot"` = "$expected"
  68. case "`uname -m`" in
  69. x86_64)
  70. # On x86_64, we should be able to create a 32-bit environment.
  71. guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
  72. -- guile -c '(exit (string-prefix? "x86_64" %host-type))'
  73. guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
  74. -s i686-linux \
  75. -- guile -c '(exit (string-prefix? "i686" %host-type))'
  76. ;;
  77. *)
  78. echo "nothing to do" >&2
  79. ;;
  80. esac
  81. # Same as above, but with deprecated -E flag.
  82. if guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
  83. -E "guile -c '(exit 42)'"
  84. then
  85. false
  86. else
  87. test $? = 42
  88. fi
  89. # Make sure we can build the environment of 'guix'. There may be collisions
  90. # in its profile (e.g., for 'gzip'), but we have to accept them.
  91. guix environment guix --bootstrap -n
  92. if guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null
  93. then
  94. # Compute the build environment for the initial GNU Make.
  95. guix environment --bootstrap --no-substitutes --search-paths --pure \
  96. -e '(@@ (gnu packages commencement) gnu-make-boot0)' > "$tmpdir/a"
  97. # Make sure bootstrap binaries are in the profile.
  98. profile=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
  99. # Make sure the bootstrap binaries are all listed where they belong.
  100. grep -E "^export PATH=\"$profile/bin\"" "$tmpdir/a"
  101. grep -E "^export CPATH=\"$profile/include\"" "$tmpdir/a"
  102. grep -E "^export LIBRARY_PATH=\"$profile/lib\"" "$tmpdir/a"
  103. for dep in bootstrap-binaries-0 gcc-bootstrap-0 glibc-bootstrap-0
  104. do
  105. guix gc --references "$profile" | grep "$dep"
  106. done
  107. # 'make-boot0' itself must not be listed.
  108. if guix gc --references "$profile" | grep make-boot0
  109. then false; else true; fi
  110. # Make sure that the shell spawned with '--exec' sees the same environment
  111. # as returned by '--search-paths'.
  112. guix environment --bootstrap --no-substitutes --pure \
  113. -e '(@@ (gnu packages commencement) gnu-make-boot0)' \
  114. -- /bin/sh -c 'echo $PATH $CPATH $LIBRARY_PATH' > "$tmpdir/b"
  115. ( . "$tmpdir/a" ; echo $PATH $CPATH $LIBRARY_PATH ) > "$tmpdir/c"
  116. cmp "$tmpdir/b" "$tmpdir/c"
  117. rm "$tmpdir"/*
  118. # Compute the build environment for the initial GNU Findutils.
  119. guix environment --bootstrap --no-substitutes --search-paths --pure \
  120. -e '(@@ (gnu packages commencement) findutils-boot0)' > "$tmpdir/a"
  121. profile=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
  122. # Make sure the bootstrap binaries are all listed where they belong.
  123. grep -E "^export PATH=\"$profile/bin\"" "$tmpdir/a"
  124. grep -E "^export CPATH=\"$profile/include\"" "$tmpdir/a"
  125. grep -E "^export LIBRARY_PATH=\"$profile/lib\"" "$tmpdir/a"
  126. for dep in bootstrap-binaries-0 gcc-bootstrap-0 glibc-bootstrap-0 \
  127. make-boot0
  128. do
  129. guix gc --references "$profile" | grep "$dep"
  130. done
  131. # The following test assumes 'make-boot0' has a "debug" output.
  132. make_boot0_debug="`guix build -e '(@@ (gnu packages commencement) gnu-make-boot0)' | grep -e -debug`"
  133. test "x$make_boot0_debug" != "x"
  134. # Make sure the "debug" output is not listed.
  135. if guix gc --references "$profile" | grep "$make_boot0_debug"
  136. then false; else true; fi
  137. # Compute the build environment for the initial GNU Make, but add in the
  138. # bootstrap Guile as an ad-hoc addition.
  139. guix environment --bootstrap --no-substitutes --search-paths --pure \
  140. -e '(@@ (gnu packages commencement) gnu-make-boot0)' \
  141. --ad-hoc guile-bootstrap > "$tmpdir/a"
  142. profile=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
  143. # Make sure the bootstrap binaries are all listed where they belong.
  144. grep -E "^export PATH=\"$profile/bin\"" "$tmpdir/a"
  145. grep -E "^export CPATH=\"$profile/include\"" "$tmpdir/a"
  146. grep -E "^export LIBRARY_PATH=\"$profile/lib\"" "$tmpdir/a"
  147. for dep in bootstrap-binaries-0 gcc-bootstrap-0 glibc-bootstrap-0 \
  148. guile-bootstrap
  149. do
  150. guix gc --references "$profile" | grep "$dep"
  151. done
  152. # Make sure a package list with plain package objects and package+output
  153. # tuples can be used with -e.
  154. expr_list_test_code="
  155. (list (@@ (gnu packages commencement) gnu-make-boot0)
  156. (list (@ (gnu packages bootstrap) %bootstrap-guile) \"out\"))"
  157. guix environment --bootstrap --ad-hoc --no-substitutes --search-paths \
  158. --pure -e "$expr_list_test_code" > "$tmpdir/a"
  159. profile=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
  160. for dep in make-boot0 guile-bootstrap
  161. do
  162. guix gc --references "$profile" | grep "$dep"
  163. done
  164. fi