PageRenderTime 3569ms CodeModel.GetById 38ms RepoModel.GetById 1ms app.codeStats 0ms

/ci/test/04_install.sh

https://github.com/denis2342/bitcoin
Shell | 122 lines | 92 code | 19 blank | 11 comment | 27 complexity | 6ddb82b0836fd7537d9e367b1e02d239 MD5 | raw file
  1. #!/usr/bin/env bash
  2. #
  3. # Copyright (c) 2018-2020 The Bitcoin Core developers
  4. # Distributed under the MIT software license, see the accompanying
  5. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
  6. export LC_ALL=C.UTF-8
  7. if [[ $QEMU_USER_CMD == qemu-s390* ]]; then
  8. export LC_ALL=C
  9. fi
  10. if [ "$CI_OS_NAME" == "macos" ]; then
  11. sudo -H pip3 install --upgrade pip
  12. IN_GETOPT_BIN="/usr/local/opt/gnu-getopt/bin/getopt" ${CI_RETRY_EXE} pip3 install --user $PIP_PACKAGES
  13. fi
  14. # Create folders that are mounted into the docker
  15. mkdir -p "${CCACHE_DIR}"
  16. mkdir -p "${PREVIOUS_RELEASES_DIR}"
  17. export ASAN_OPTIONS="detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1"
  18. export LSAN_OPTIONS="suppressions=${BASE_ROOT_DIR}/test/sanitizer_suppressions/lsan"
  19. export TSAN_OPTIONS="suppressions=${BASE_ROOT_DIR}/test/sanitizer_suppressions/tsan:halt_on_error=1:log_path=${BASE_SCRATCH_DIR}/sanitizer-output/tsan"
  20. export UBSAN_OPTIONS="suppressions=${BASE_ROOT_DIR}/test/sanitizer_suppressions/ubsan:print_stacktrace=1:halt_on_error=1:report_error_type=1"
  21. env | grep -E '^(BITCOIN_CONFIG|BASE_|QEMU_|CCACHE_|LC_ALL|BOOST_TEST_RANDOM|DEBIAN_FRONTEND|CONFIG_SHELL|(ASAN|LSAN|TSAN|UBSAN)_OPTIONS|PREVIOUS_RELEASES_DIR)' | tee /tmp/env
  22. if [[ $BITCOIN_CONFIG = *--with-sanitizers=*address* ]]; then # If ran with (ASan + LSan), Docker needs access to ptrace (https://github.com/google/sanitizers/issues/764)
  23. DOCKER_ADMIN="--cap-add SYS_PTRACE"
  24. fi
  25. export P_CI_DIR="$PWD"
  26. if [ -z "$DANGER_RUN_CI_ON_HOST" ]; then
  27. echo "Creating $DOCKER_NAME_TAG container to run in"
  28. ${CI_RETRY_EXE} docker pull "$DOCKER_NAME_TAG"
  29. if [ -n "${RESTART_CI_DOCKER_BEFORE_RUN}" ] ; then
  30. echo "Restart docker before run to stop and clear all containers started with --rm"
  31. systemctl restart docker
  32. fi
  33. DOCKER_ID=$(docker run $DOCKER_ADMIN --rm --interactive --detach --tty \
  34. --mount type=bind,src=$BASE_ROOT_DIR,dst=/ro_base,readonly \
  35. --mount type=bind,src=$CCACHE_DIR,dst=$CCACHE_DIR \
  36. --mount type=bind,src=$DEPENDS_DIR,dst=$DEPENDS_DIR \
  37. --mount type=bind,src=$PREVIOUS_RELEASES_DIR,dst=$PREVIOUS_RELEASES_DIR \
  38. -w $BASE_ROOT_DIR \
  39. --env-file /tmp/env \
  40. --name $CONTAINER_NAME \
  41. $DOCKER_NAME_TAG)
  42. export DOCKER_CI_CMD_PREFIX="docker exec $DOCKER_ID"
  43. else
  44. echo "Running on host system without docker wrapper"
  45. fi
  46. DOCKER_EXEC () {
  47. $DOCKER_CI_CMD_PREFIX bash -c "export PATH=$BASE_SCRATCH_DIR/bins/:\$PATH && cd $P_CI_DIR && $*"
  48. }
  49. export -f DOCKER_EXEC
  50. if [ -n "$DPKG_ADD_ARCH" ]; then
  51. DOCKER_EXEC dpkg --add-architecture "$DPKG_ADD_ARCH"
  52. fi
  53. if [[ $DOCKER_NAME_TAG == centos* ]]; then
  54. ${CI_RETRY_EXE} DOCKER_EXEC dnf -y install epel-release
  55. ${CI_RETRY_EXE} DOCKER_EXEC dnf -y --allowerasing install $DOCKER_PACKAGES $PACKAGES
  56. elif [ "$CI_USE_APT_INSTALL" != "no" ]; then
  57. ${CI_RETRY_EXE} DOCKER_EXEC apt-get update
  58. ${CI_RETRY_EXE} DOCKER_EXEC apt-get install --no-install-recommends --no-upgrade -y $PACKAGES $DOCKER_PACKAGES
  59. if [ -n "$PIP_PACKAGES" ]; then
  60. ${CI_RETRY_EXE} pip3 install --user $PIP_PACKAGES
  61. fi
  62. fi
  63. if [ "$CI_OS_NAME" == "macos" ]; then
  64. top -l 1 -s 0 | awk ' /PhysMem/ {print}'
  65. echo "Number of CPUs: $(sysctl -n hw.logicalcpu)"
  66. else
  67. DOCKER_EXEC free -m -h
  68. DOCKER_EXEC echo "Number of CPUs \(nproc\):" \$\(nproc\)
  69. DOCKER_EXEC echo $(lscpu | grep Endian)
  70. fi
  71. DOCKER_EXEC echo "Free disk space:"
  72. DOCKER_EXEC df -h
  73. if [ "$RUN_FUZZ_TESTS" = "true" ] || [ "$RUN_UNIT_TESTS" = "true" ] || [ "$RUN_UNIT_TESTS_SEQUENTIAL" = "true" ]; then
  74. if [ ! -d ${DIR_QA_ASSETS} ]; then
  75. DOCKER_EXEC git clone --depth=1 https://github.com/bitcoin-core/qa-assets ${DIR_QA_ASSETS}
  76. fi
  77. export DIR_FUZZ_IN=${DIR_QA_ASSETS}/fuzz_seed_corpus/
  78. export DIR_UNIT_TEST_DATA=${DIR_QA_ASSETS}/unit_test_data/
  79. fi
  80. DOCKER_EXEC mkdir -p "${BASE_SCRATCH_DIR}/sanitizer-output/"
  81. if [[ ${USE_MEMORY_SANITIZER} == "true" ]]; then
  82. DOCKER_EXEC "update-alternatives --install /usr/bin/clang++ clang++ \$(which clang++-9) 100"
  83. DOCKER_EXEC "update-alternatives --install /usr/bin/clang clang \$(which clang-9) 100"
  84. DOCKER_EXEC "mkdir -p ${BASE_SCRATCH_DIR}/msan/build/"
  85. DOCKER_EXEC "git clone --depth=1 https://github.com/llvm/llvm-project -b llvmorg-12.0.0 ${BASE_SCRATCH_DIR}/msan/llvm-project"
  86. DOCKER_EXEC "cd ${BASE_SCRATCH_DIR}/msan/build/ && cmake -DLLVM_ENABLE_PROJECTS='libcxx;libcxxabi' -DCMAKE_BUILD_TYPE=Release -DLLVM_USE_SANITIZER=Memory -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLLVM_TARGETS_TO_BUILD=X86 ../llvm-project/llvm/"
  87. DOCKER_EXEC "cd ${BASE_SCRATCH_DIR}/msan/build/ && make $MAKEJOBS cxx"
  88. fi
  89. if [ -z "$DANGER_RUN_CI_ON_HOST" ]; then
  90. echo "Create $BASE_ROOT_DIR"
  91. DOCKER_EXEC rsync -a /ro_base/ $BASE_ROOT_DIR
  92. fi
  93. if [ "$USE_BUSY_BOX" = "true" ]; then
  94. echo "Setup to use BusyBox utils"
  95. DOCKER_EXEC mkdir -p $BASE_SCRATCH_DIR/bins/
  96. # tar excluded for now because it requires passing in the exact archive type in ./depends (fixed in later BusyBox version)
  97. # find excluded for now because it does not recognize the -delete option in ./depends (fixed in later BusyBox version)
  98. # ar excluded for now because it does not recognize the -q option in ./depends (unknown if fixed)
  99. # shellcheck disable=SC1010
  100. DOCKER_EXEC for util in \$\(busybox --list \| grep -v "^ar$" \| grep -v "^tar$" \| grep -v "^find$"\)\; do ln -s \$\(command -v busybox\) $BASE_SCRATCH_DIR/bins/\$util\; done
  101. # Print BusyBox version
  102. DOCKER_EXEC patch --help
  103. fi