test-env.in 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #!/bin/sh
  2. # GNU Guix --- Functional package management for GNU
  3. # Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.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. # Usage: ./test-env COMMAND ARG...
  20. #
  21. # Run the daemon in the build directory, and run COMMAND within
  22. # `pre-inst-env'. This is used to run unit tests with the just-built
  23. # daemon, unless `--disable-daemon' was passed at configure time.
  24. # Make sure 'cd' behaves deterministically and doesn't write anything to
  25. # stdout.
  26. unset CDPATH
  27. case "$1" in
  28. --quiet-stderr)
  29. # Silence the daemon's output, which is often useless, as well as that
  30. # of Bash (such as "Terminated" messages when 'guix-daemon' is
  31. # killed.)
  32. exec 2> /dev/null
  33. shift
  34. ;;
  35. esac
  36. if [ -x "@abs_top_builddir@/guix-daemon" ]
  37. then
  38. NIX_STORE_DIR="@GUIX_TEST_ROOT@/store"
  39. # Do that because store.scm calls `canonicalize-path' on it.
  40. mkdir -p "$NIX_STORE_DIR"
  41. # Canonicalize the store directory name in an attempt to avoid symlinks in
  42. # it or its parent directories. See <http://bugs.gnu.org/17935>.
  43. NIX_STORE_DIR="`cd "@GUIX_TEST_ROOT@/store"; pwd -P`"
  44. NIX_LOCALSTATE_DIR="@GUIX_TEST_ROOT@/var"
  45. GUIX_LOG_DIRECTORY="@GUIX_TEST_ROOT@/var/log/guix"
  46. GUIX_DATABASE_DIRECTORY="@GUIX_TEST_ROOT@/db"
  47. NIX_ROOT_FINDER="@abs_top_builddir@/nix/scripts/list-runtime-roots"
  48. # Choose a PID-dependent name to allow for parallel builds. Note
  49. # that the directory name must be chosen so that the socket's file
  50. # name is less than 108-char long (the size of `sun_path' in glibc).
  51. # Currently, in Nix builds, we're at ~106 chars...
  52. GUIX_STATE_DIRECTORY="@GUIX_TEST_ROOT@/var/$$"
  53. # We can't exit when we reach the limit, because perhaps the test doesn't
  54. # actually rely on the daemon, but at least warn.
  55. if test "`echo -n "$GUIX_STATE_DIRECTORY/daemon-socket/socket" | wc -c`" -ge 108
  56. then
  57. echo "warning: exceeding socket file name limit; test may fail!" >&2
  58. fi
  59. # The configuration directory, for import/export signing keys.
  60. GUIX_CONFIGURATION_DIRECTORY="@GUIX_TEST_ROOT@/etc"
  61. if [ ! -d "$GUIX_CONFIGURATION_DIRECTORY" ]
  62. then
  63. # Copy the keys so that the secret key has the right permissions (the
  64. # daemon errors out when this is not the case.)
  65. mkdir -p "$GUIX_CONFIGURATION_DIRECTORY"
  66. cp "@abs_top_srcdir@/tests/signing-key.sec" \
  67. "@abs_top_srcdir@/tests/signing-key.pub" \
  68. "$GUIX_CONFIGURATION_DIRECTORY"
  69. chmod 400 "$GUIX_CONFIGURATION_DIRECTORY/signing-key.sec"
  70. fi
  71. # A place to store data of the substituter.
  72. GUIX_BINARY_SUBSTITUTE_URL="file://$GUIX_STATE_DIRECTORY/substituter-data"
  73. rm -rf "$GUIX_STATE_DIRECTORY/substituter-data"
  74. mkdir -p "$GUIX_STATE_DIRECTORY/substituter-data"
  75. # For a number of tests, we want to allow unsigned narinfos, for
  76. # simplicity.
  77. GUIX_ALLOW_UNAUTHENTICATED_SUBSTITUTES=yes
  78. # Place for the substituter's cache.
  79. XDG_CACHE_HOME="$GUIX_STATE_DIRECTORY/cache-$$"
  80. # For the (guix import snix) tests.
  81. NIXPKGS="@NIXPKGS@"
  82. export NIX_IGNORE_SYMLINK_STORE NIX_STORE_DIR \
  83. NIX_LOCALSTATE_DIR GUIX_LOG_DIRECTORY GUIX_STATE_DIRECTORY GUIX_DATABASE_DIRECTORY \
  84. NIX_ROOT_FINDER GUIX_BINARY_SUBSTITUTE_URL \
  85. GUIX_ALLOW_UNAUTHENTICATED_SUBSTITUTES \
  86. GUIX_CONFIGURATION_DIRECTORY XDG_CACHE_HOME NIXPKGS
  87. # Launch the daemon without chroot support because is may be
  88. # unavailable, for instance if we're not running as root.
  89. "@abs_top_builddir@/pre-inst-env" \
  90. "@abs_top_builddir@/guix-daemon" --disable-chroot \
  91. --substitute-urls="$GUIX_BINARY_SUBSTITUTE_URL" &
  92. daemon_pid=$!
  93. trap "kill $daemon_pid ; rm -rf $GUIX_STATE_DIRECTORY" EXIT
  94. # The test suite expects the 'guile-bootstrap' package to be available.
  95. # Normally the Guile bootstrap tarball is downloaded by a fixed-output
  96. # derivation but when network access is missing we allow users to drop
  97. # the tarball in 'gnu/packages/bootstrap/SYSTEM' and "intern" it here.
  98. bootstrap_directory="@abs_top_builddir@/gnu/packages/bootstrap/@guix_system@"
  99. if [ -d "$bootstrap_directory" ]
  100. then
  101. # Make sure 'guix-daemon' is listening before invoking 'guix
  102. # download'.
  103. "@abs_top_builddir@/pre-inst-env" "@GUILE@" -c \
  104. '(use-modules (guix))
  105. (let loop ((i 10))
  106. (catch #t
  107. (lambda () (open-connection))
  108. (lambda (key . args)
  109. (if (zero? i)
  110. (apply throw key args)
  111. (begin (usleep 500000) (loop (- i 1)))))))'
  112. for file in "$bootstrap_directory"/guile-*
  113. do
  114. [ -f "$file" ] && \
  115. "@abs_top_builddir@/pre-inst-env" \
  116. guix download "file://$file" > /dev/null
  117. done
  118. fi
  119. fi
  120. # Avoid issues that could stem from l10n, such as language/encoding
  121. # mismatches.
  122. unset LANGUAGE
  123. LC_MESSAGES=C
  124. export LC_MESSAGES
  125. # Disable grafts by default because they can cause things to be built
  126. # regardless of '--dry-run'.
  127. GUIX_BUILD_OPTIONS="--no-grafts"
  128. export GUIX_BUILD_OPTIONS
  129. # Ignore user settings.
  130. unset GUIX_PACKAGE_PATH
  131. storedir="@storedir@"
  132. prefix="@prefix@"
  133. datarootdir="@datarootdir@"
  134. datadir="@datadir@"
  135. localstatedir="@localstatedir@"
  136. export storedir prefix datarootdir datadir localstatedir
  137. "@abs_top_builddir@/pre-inst-env" "$@"
  138. exit $?