Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1#!/usr/bin/env bash2#3# Copyright (c) 2018-present The Bitcoin Core developers4# Distributed under the MIT software license, see the accompanying5# file COPYING or http://www.opensource.org/licenses/mit-license.php.7export LC_ALL=C.UTF-89set -o errexit -o xtrace -o pipefail11if [ "${DANGER_RUN_CI_ON_HOST}" != "1" ]; then12echo "This script will make unsafe local and global modifications, so it can only be run inside a container and requires DANGER_RUN_CI_ON_HOST=1"13exit 114fi16cd "${BASE_ROOT_DIR}"18export PATH="/path_with space:${PATH}"19export ASAN_OPTIONS="detect_leaks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1"20export LSAN_OPTIONS="suppressions=${BASE_ROOT_DIR}/test/sanitizer_suppressions/lsan:print_suppressions=0"21export TSAN_OPTIONS="suppressions=${BASE_ROOT_DIR}/test/sanitizer_suppressions/tsan:halt_on_error=1:second_deadlock_stack=1"22export UBSAN_OPTIONS="suppressions=${BASE_ROOT_DIR}/test/sanitizer_suppressions/ubsan:print_stacktrace=1:halt_on_error=1:report_error_type=1"24echo "Number of available processing units: $(nproc)"25if [ "$CI_OS_NAME" == "macos" ]; then26top -l 1 -s 0 | awk ' /PhysMem/ {print}'27else28free -m -h29echo "System info: $(uname --kernel-name --kernel-release)"30lscpu31fi32echo "Free disk space:"33df -h35# We force an install of linux-headers again here via $PACKAGES to fix any36# kernel mismatch between a cached docker image and the underlying host.37# This can happen occasionally on hosted runners if the runner image is updated.38if [[ "$CONTAINER_NAME" == "ci_native_asan" ]]; then39$CI_RETRY_EXE apt-get update40${CI_RETRY_EXE} bash -c "apt-get install --no-install-recommends --no-upgrade -y $PACKAGES"41fi43# What host to compile for. See also ./depends/README.md44# Tests that need cross-compilation export the appropriate HOST.45# Tests that run natively guess the host46export HOST=${HOST:-$("$BASE_ROOT_DIR/depends/config.guess")}48echo "=== BEGIN env ==="49env50echo "=== END env ==="52# The CI framework should be flexible where it is run from. For example, from53# a git-archive, a git-worktree, or a normal git repo.54# The iwyu task requires a working git repo, which may not always be55# available, so initialize one with force.56if [[ "${RUN_IWYU}" == true ]]; then57mv .git .git_ci_backup || true58git init59git add ./src # the git diff command used later for iwyu only cares about ./src60git config user.email "ci@ci"61git config user.name "CI"62git commit -m "dummy CI ./src init for IWYU"63fi65if [ "$RUN_FUZZ_TESTS" = "true" ]; then66export DIR_FUZZ_IN=${DIR_QA_ASSETS}/fuzz_corpora/67if [ ! -d "$DIR_FUZZ_IN" ]; then68${CI_RETRY_EXE} git clone --depth=1 https://github.com/bitcoin-core/qa-assets "${DIR_QA_ASSETS}"69fi70(71cd "${DIR_QA_ASSETS}"72echo "Using qa-assets repo from commit ..."73git log -174)75elif [ "$RUN_UNIT_TESTS" = "true" ]; then76export DIR_UNIT_TEST_DATA=${DIR_QA_ASSETS}/unit_test_data/77if [ ! -d "$DIR_UNIT_TEST_DATA" ]; then78mkdir -p "$DIR_UNIT_TEST_DATA"79${CI_RETRY_EXE} curl --location --fail https://github.com/bitcoin-core/qa-assets/raw/main/unit_test_data/script_assets_test.json -o "${DIR_UNIT_TEST_DATA}/script_assets_test.json"80fi81fi83# Make sure default datadir does not exist and is never read by creating a dummy file84if [ "$CI_OS_NAME" == "macos" ]; then85echo > "${HOME}/Library/Application Support/Bitcoin"86else87echo > "${HOME}/.bitcoin"88fi90if [ -z "$NO_DEPENDS" ]; then91if [[ $CI_IMAGE_NAME_TAG == *alpine* ]]; then92SHELL_OPTS="CONFIG_SHELL=/usr/bin/dash"93else94SHELL_OPTS="CONFIG_SHELL="95fi96bash -c "$SHELL_OPTS make $MAKEJOBS -C depends HOST=$HOST $DEP_OPTS LOG=1"97fi98if [ "$DOWNLOAD_PREVIOUS_RELEASES" = "true" ]; then99test/get_previous_releases.py100fi102BITCOIN_CONFIG_ALL="-DCMAKE_COMPILE_WARNING_AS_ERROR=ON -DBUILD_BENCH=ON -DBUILD_FUZZ_BINARY=ON"103if [ -z "$NO_DEPENDS" ]; then104BITCOIN_CONFIG_ALL="${BITCOIN_CONFIG_ALL} -DCMAKE_TOOLCHAIN_FILE=$DEPENDS_DIR/$HOST/toolchain.cmake"105fi107ccache --zero-stats109# Folder where the build is done.110BASE_BUILD_DIR=${BASE_BUILD_DIR:-$BASE_SCRATCH_DIR/build-$HOST}112BITCOIN_CONFIG_ALL="$BITCOIN_CONFIG_ALL '-DCMAKE_INSTALL_PREFIX=$BASE_OUTDIR' -Werror=dev"114if [[ "${RUN_IWYU}" == true || "${RUN_TIDY}" == true ]]; then115BITCOIN_CONFIG_ALL="$BITCOIN_CONFIG_ALL -DCMAKE_EXPORT_COMPILE_COMMANDS=ON"116fi118eval "CMAKE_ARGS=($BITCOIN_CONFIG_ALL $BITCOIN_CONFIG)"119cmake -S "$BASE_ROOT_DIR" -B "$BASE_BUILD_DIR" "${CMAKE_ARGS[@]}" || (120cd "${BASE_BUILD_DIR}"121# shellcheck disable=SC2046122cat $(cmake -P "${BASE_ROOT_DIR}/ci/test/GetCMakeLogFiles.cmake")123false124)126BUILD_TARGETS="${GOAL}"127if [[ "${GOAL}" != all && "${GOAL}" != *codegen* ]]; then128BUILD_TARGETS="all ${GOAL}"129fi131# shellcheck disable=SC2086132cmake --build "${BASE_BUILD_DIR}" "$MAKEJOBS" --target $BUILD_TARGETS || (133echo "Build failure. Verbose build follows."134# shellcheck disable=SC2086135cmake --build "${BASE_BUILD_DIR}" -j1 --target $BUILD_TARGETS --verbose136false137)139ccache --version | head -n 1 && ccache --show-stats --verbose140ccache --print-stats | python3 -c '141import os142import sys144for line in sys.stdin:145key, value = line.split("\t", 1)146# "primary storage" fallback only needed for ccache version 4.5.1147if key in ("local_storage_hit", "primary_storage_hit"):148hits = int(value)149elif key in ("local_storage_miss", "primary_storage_miss"):150miss = int(value)152calls = hits + miss153# codegen has no calls, so skip that here154if calls:155rate = (hits / calls * 100)156print(f"{rate:.2f}")157if rate < 75:158container = os.environ["CONTAINER_NAME"]159print(160"::notice title=low ccache hitrate::"161f"Ccache hit-rate in {container} was {rate:.2f}%"162)163'164du -sh "${DEPENDS_DIR}"/*/165du -sh "${PREVIOUS_RELEASES_DIR}"167if [ -n "${CI_LIMIT_STACK_SIZE}" ]; then168ulimit -s 512169fi171if [[ ${BARE_METAL_RISCV} == "true" ]]; then172export BASE_BUILD_DIR173"${BASE_ROOT_DIR}/ci/test/link-riscv.sh"174fi176if [ -n "$USE_VALGRIND" ]; then177"${BASE_ROOT_DIR}/ci/test/wrap-valgrind.py"178fi180if [ "$RUN_CHECK_DEPS" = "true" ]; then181"${BASE_ROOT_DIR}/contrib/devtools/check-deps.sh" "${BASE_BUILD_DIR}"182fi184if [[ "$CI_OS_NAME" == "macos" && "${GOAL}" = "install deploy" ]]; then185unzip "${BASE_BUILD_DIR}/bitcoin-macos-app.zip" -d "${BASE_BUILD_DIR}/deploy"186if ! ( codesign --verify --deep --strict "${BASE_BUILD_DIR}/deploy/Bitcoin-Qt.app" ); then187echo "Codesigning failed."188false189fi190fi192if [ "$RUN_UNIT_TESTS" = "true" ]; then193DIR_UNIT_TEST_DATA="${DIR_UNIT_TEST_DATA}" \194LD_LIBRARY_PATH="${DEPENDS_DIR}/${HOST}/lib" \195CTEST_OUTPUT_ON_FAILURE=ON \196ctest --test-dir "${BASE_BUILD_DIR}" \197--stop-on-failure \198"${MAKEJOBS}" \199--timeout $(( TEST_RUNNER_TIMEOUT_FACTOR * 60 ))200fi202if [ "$RUN_FUNCTIONAL_TESTS" = "true" ]; then203# parses TEST_RUNNER_EXTRA as an array which allows for multiple arguments such as TEST_RUNNER_EXTRA='--exclude "rpc_bind.py --ipv6"'204eval "TEST_RUNNER_EXTRA=($TEST_RUNNER_EXTRA)"205LD_LIBRARY_PATH="${DEPENDS_DIR}/${HOST}/lib" \206"${BASE_BUILD_DIR}/test/functional/test_runner.py" \207"${MAKEJOBS}" \208--tmpdirprefix "${BASE_SCRATCH_DIR}/test_runner/" \209--ansi \210--combinedlogslen=99999999 \211--timeout-factor="${TEST_RUNNER_TIMEOUT_FACTOR}" \212"${TEST_RUNNER_EXTRA[@]}" \213--quiet \214--failfast215fi217if [ "${RUN_TIDY}" = "true" ]; then218cmake -B /tidy-build -DLLVM_DIR=/usr/lib/llvm-"${TIDY_LLVM_V}"/cmake -DCMAKE_BUILD_TYPE=Release -S "${BASE_ROOT_DIR}"/contrib/devtools/bitcoin-tidy219cmake --build /tidy-build "$MAKEJOBS"220cmake --build /tidy-build --target bitcoin-tidy-tests "$MAKEJOBS"222set -eo pipefail223# Filter out:224# * qt qrc and moc generated files225jq 'map(select(.file | test("src/qt/.*_autogen/.*\\.cpp$") | not))' "${BASE_BUILD_DIR}/compile_commands.json" > tmp.json226mv tmp.json "${BASE_BUILD_DIR}/compile_commands.json"228cd "${BASE_BUILD_DIR}/src/"229if ! ( run-clang-tidy-"${TIDY_LLVM_V}" -config-file="${BASE_ROOT_DIR}/src/.clang-tidy" -quiet -load="/tidy-build/libbitcoin-tidy.so" "${MAKEJOBS}" | tee tmp.tidy-out.txt ); then230grep -C5 "error: " tmp.tidy-out.txt231echo "^^^ ⚠️ Failure generated from clang-tidy"232false233fi234fi236if [[ "${RUN_IWYU}" == true ]]; then237# TODO: Consider enforcing IWYU across the entire codebase.238FILES_WITH_ENFORCED_IWYU='/src/((bench|common|consensus|crypto|index|init|kernel|primitives|rpc|script|univalue/(lib|test)|util|zmq)/.*|node/(blockstorage|interfaces|miner|mining_args|utxo_snapshot)|test/fuzz/(kitchen_sink|minisketch|parse_univalue)|clientversion|core_io|rest|signet|init)\.cpp'239jq --arg patterns "$FILES_WITH_ENFORCED_IWYU" 'map(select(.file | test($patterns)))' "${BASE_BUILD_DIR}/compile_commands.json" > "${BASE_BUILD_DIR}/compile_commands_iwyu_errors.json"240jq --arg patterns "$FILES_WITH_ENFORCED_IWYU" 'map(select(.file | test($patterns) | not))' "${BASE_BUILD_DIR}/compile_commands.json" > "${BASE_BUILD_DIR}/compile_commands_iwyu_warnings.json"242cd "${BASE_ROOT_DIR}"244run_iwyu() {245mv "${BASE_BUILD_DIR}/$1" "${BASE_BUILD_DIR}/compile_commands.json"246{247python3 /include-what-you-use/mapgen/iwyu-mapgen-clang-intrin.py --lang imp "$("clang-${IWYU_LLVM_V}" -print-resource-dir)/include" > "${BASE_BUILD_DIR}/clang.intrinsics.imp"248python3 /include-what-you-use/iwyu_tool.py \249-p "${BASE_BUILD_DIR}" "${MAKEJOBS}" -- \250-Xiwyu --cxx17ns \
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.