guix-shell.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. # GNU Guix --- Functional package management for GNU
  2. # Copyright © 2021-2022 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 the 'guix shell' alias.
  20. #
  21. guix shell --version
  22. configdir="t-guix-shell-config-$$"
  23. tmpdir="t-guix-shell-$$"
  24. trap 'rm -r "$tmpdir" "$configdir"' EXIT
  25. mkdir "$tmpdir" "$configdir" "$configdir/guix"
  26. XDG_CONFIG_HOME="$(realpath $configdir)"
  27. export XDG_CONFIG_HOME
  28. guix shell --bootstrap --pure guile-bootstrap -- guile --version
  29. # '--ad-hoc' is a thing of the past.
  30. ! guix shell --ad-hoc guile-bootstrap
  31. # Rejecting unsupported packages.
  32. ! guix shell -s armhf-linux intelmetool -n
  33. # Ignoring unauthorized files.
  34. cat > "$tmpdir/guix.scm" <<EOF
  35. This is a broken guix.scm file.
  36. EOF
  37. ! (cd "$tmpdir"; SHELL="$(type -P true)" guix shell --bootstrap 2> "stderr")
  38. grep "not authorized" "$tmpdir/stderr"
  39. rm "$tmpdir/stderr"
  40. # Authorize the directory.
  41. echo "$(realpath "$tmpdir")" > "$configdir/guix/shell-authorized-directories"
  42. # Ignoring 'manifest.scm' and 'guix.scm' in non-interactive use.
  43. (cd "$tmpdir"; guix shell --bootstrap -- true)
  44. mv "$tmpdir/guix.scm" "$tmpdir/manifest.scm"
  45. (cd "$tmpdir"; guix shell --bootstrap -- true)
  46. rm "$tmpdir/manifest.scm"
  47. # Honoring the local 'manifest.scm' file.
  48. cat > "$tmpdir/manifest.scm" <<EOF
  49. (specifications->manifest '("guile-bootstrap"))
  50. EOF
  51. cat > "$tmpdir/fake-shell.sh" <<EOF
  52. #!$SHELL
  53. # This fake shell allows us to test interactive use.
  54. exec echo "\$GUIX_ENVIRONMENT"
  55. EOF
  56. chmod +x "$tmpdir/fake-shell.sh"
  57. profile1="$(cd "$tmpdir"; SHELL="$(realpath fake-shell.sh)" guix shell --bootstrap)"
  58. profile2="$(guix shell --bootstrap guile-bootstrap -- "$SHELL" -c 'echo $GUIX_ENVIRONMENT')"
  59. test -n "$profile1"
  60. test "$profile1" = "$profile2"
  61. rm "$tmpdir/manifest.scm"
  62. # Do not read manifest when passed '-q'.
  63. echo "Broken manifest." > "$tmpdir/manifest.scm"
  64. (cd "$tmpdir"; SHELL="$(realpath fake-shell.sh)" guix shell --bootstrap -q)
  65. rm "$tmpdir/manifest.scm"
  66. # Make sure '-D' affects only the immediately following '-f', and not packages
  67. # that appear later: <https://issues.guix.gnu.org/52093>.
  68. cat > "$tmpdir/empty-package.scm" <<EOF
  69. (use-modules (guix) (guix tests)
  70. (guix build-system trivial))
  71. (dummy-package "empty-package"
  72. (build-system trivial-build-system)) ;zero inputs
  73. EOF
  74. guix shell --bootstrap --pure -D -f "$tmpdir/empty-package.scm" \
  75. guile-bootstrap -- guile --version
  76. rm "$tmpdir/empty-package.scm"
  77. if guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null
  78. then
  79. # Compute the build environment for the initial GNU Make.
  80. guix shell --bootstrap --no-substitutes --search-paths --pure \
  81. -D -e '(@ (guix tests) gnu-make-for-tests)' > "$tmpdir/a"
  82. # Make sure bootstrap binaries are in the profile.
  83. profile=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
  84. # Make sure the bootstrap binaries are all listed where they belong.
  85. grep -E "^export PATH=\"$profile/bin\"" "$tmpdir/a"
  86. grep -E "^export C_INCLUDE_PATH=\"$profile/include\"" "$tmpdir/a"
  87. grep -E "^export LIBRARY_PATH=\"$profile/lib\"" "$tmpdir/a"
  88. for dep in bootstrap-binaries-0 gcc-bootstrap-0 glibc-bootstrap-0
  89. do
  90. guix gc --references "$profile" | grep "$dep"
  91. done
  92. # 'make-boot0' itself must not be listed.
  93. ! guix gc --references "$profile" | grep make-boot0
  94. # Honoring the local 'guix.scm' file.
  95. echo '(@ (guix tests) gnu-make-for-tests)' > "$tmpdir/guix.scm"
  96. (cd "$tmpdir"; guix shell --bootstrap --search-paths --pure > "b")
  97. cmp "$tmpdir/a" "$tmpdir/b"
  98. rm "$tmpdir/guix.scm"
  99. fi