You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

163 lines
5.6 KiB

  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. GUIX_LOG_DIRECTORY="@GUIX_TEST_ROOT@/var/log/guix"
  45. GUIX_DATABASE_DIRECTORY="@GUIX_TEST_ROOT@/db"
  46. # Choose a PID-dependent name to allow for parallel builds. Note
  47. # that the directory name must be chosen so that the socket's file
  48. # name is less than 108-char long (the size of `sun_path' in glibc).
  49. # Currently, in Nix builds, we're at ~106 chars...
  50. GUIX_STATE_DIRECTORY="@GUIX_TEST_ROOT@/var/$$"
  51. # We can't exit when we reach the limit, because perhaps the test doesn't
  52. # actually rely on the daemon, but at least warn.
  53. if test "`echo -n "$GUIX_STATE_DIRECTORY/daemon-socket/socket" | wc -c`" -ge 108
  54. then
  55. echo "warning: exceeding socket file name limit; test may fail!" >&2
  56. fi
  57. # The configuration directory, for import/export signing keys.
  58. GUIX_CONFIGURATION_DIRECTORY="@GUIX_TEST_ROOT@/etc"
  59. if [ ! -d "$GUIX_CONFIGURATION_DIRECTORY" ]
  60. then
  61. # Copy the keys so that the secret key has the right permissions (the
  62. # daemon errors out when this is not the case.)
  63. mkdir -p "$GUIX_CONFIGURATION_DIRECTORY"
  64. cp "@abs_top_srcdir@/tests/signing-key.sec" \
  65. "@abs_top_srcdir@/tests/signing-key.pub" \
  66. "$GUIX_CONFIGURATION_DIRECTORY"
  67. chmod 400 "$GUIX_CONFIGURATION_DIRECTORY/signing-key.sec"
  68. fi
  69. # A place to store data of the substituter.
  70. GUIX_BINARY_SUBSTITUTE_URL="file://$GUIX_STATE_DIRECTORY/substituter-data"
  71. rm -rf "$GUIX_STATE_DIRECTORY/substituter-data"
  72. mkdir -p "$GUIX_STATE_DIRECTORY/substituter-data"
  73. # For a number of tests, we want to allow unsigned narinfos, for
  74. # simplicity.
  75. GUIX_ALLOW_UNAUTHENTICATED_SUBSTITUTES=yes
  76. # Place for the substituter's cache.
  77. XDG_CACHE_HOME="$GUIX_STATE_DIRECTORY/cache-$$"
  78. # For the (guix import snix) tests.
  79. NIXPKGS="@NIXPKGS@"
  80. export NIX_IGNORE_SYMLINK_STORE NIX_STORE_DIR \
  81. GUIX_LOG_DIRECTORY GUIX_STATE_DIRECTORY GUIX_DATABASE_DIRECTORY \
  82. GUIX_BINARY_SUBSTITUTE_URL \
  83. GUIX_ALLOW_UNAUTHENTICATED_SUBSTITUTES \
  84. GUIX_CONFIGURATION_DIRECTORY XDG_CACHE_HOME NIXPKGS
  85. # Launch the daemon without chroot support because is may be
  86. # unavailable, for instance if we're not running as root.
  87. "@abs_top_builddir@/pre-inst-env" \
  88. "@abs_top_builddir@/guix-daemon" --disable-chroot \
  89. --substitute-urls="$GUIX_BINARY_SUBSTITUTE_URL" &
  90. daemon_pid=$!
  91. trap "kill $daemon_pid ; rm -rf $GUIX_STATE_DIRECTORY" EXIT
  92. # The test suite expects the 'guile-bootstrap' package to be available.
  93. # Normally the Guile bootstrap tarball is downloaded by a fixed-output
  94. # derivation but when network access is missing we allow users to drop
  95. # the tarball in 'gnu/packages/bootstrap/SYSTEM' and "intern" it here.
  96. bootstrap_directory="@abs_top_builddir@/gnu/packages/bootstrap/@guix_system@"
  97. if [ -d "$bootstrap_directory" ]
  98. then
  99. # Make sure 'guix-daemon' is listening before invoking 'guix
  100. # download'.
  101. "@abs_top_builddir@/pre-inst-env" "@GUILE@" -c \
  102. '(use-modules (guix))
  103. (let loop ((i 10))
  104. (catch #t
  105. (lambda () (open-connection))
  106. (lambda (key . args)
  107. (if (zero? i)
  108. (apply throw key args)
  109. (begin (usleep 500000) (loop (- i 1)))))))'
  110. for file in "$bootstrap_directory"/guile-*
  111. do
  112. [ -f "$file" ] && \
  113. "@abs_top_builddir@/pre-inst-env" \
  114. guix download "file://$file" > /dev/null
  115. done
  116. fi
  117. fi
  118. # Avoid issues that could stem from l10n, such as language/encoding
  119. # mismatches.
  120. unset LANGUAGE
  121. LC_MESSAGES=C
  122. export LC_MESSAGES
  123. # Disable grafts by default because they can cause things to be built
  124. # regardless of '--dry-run'.
  125. GUIX_BUILD_OPTIONS="--no-grafts"
  126. export GUIX_BUILD_OPTIONS
  127. # Ignore user settings.
  128. unset GUIX_PACKAGE_PATH
  129. storedir="@storedir@"
  130. prefix="@prefix@"
  131. datarootdir="@datarootdir@"
  132. datadir="@datadir@"
  133. localstatedir="@localstatedir@"
  134. export storedir prefix datarootdir datadir localstatedir
  135. "@abs_top_builddir@/pre-inst-env" "$@"
  136. exit $?