Skip to content

Commit ffe4261

Browse files
committed
Merge bitcoin/bitcoin#30935: ci: Approximate MAKEJOBS in image build phase
fa71bed ci: Approximate MAKEJOBS in image build phase (MarcoFalke) Pull request description: The `MAKEJOBS` env var is the default in image builds, which is fine, because it is only relevant when building msan (or iwyu) and only differs when setting MAKEJOBS to something other than `nproc` (currently used as an approximation). So the normal workflow of `MAKEJOBS="-j$(nproc)" FILE_ENV="./ci/test/00_setup_env_native_msan.sh" ./ci/test_run_all.sh` already works today. However, `MAKEJOBS="-j1" FILE_ENV="./ci/test/00_setup_env_native_msan.sh" ./ci/test_run_all.sh` does not. This is hard to fix, because making the env var a build arg means that changing it (and only it) requires a new (expensive and redundant) build. So add an option `HAVE_CGROUP_CPUSET`, which can be set to approximate `MAKEJOBS` a bit. Can be tested via: `HAVE_CGROUP_CPUSET=yo MAKEJOBS="-j_something" FILE_ENV="./ci/test/00_setup_env_native_msan.sh" ./ci/test_run_all.sh` ACKs for top commit: fanquake: ACK fa71bed Tree-SHA512: 43ef194c71d726f4cfa3fe08a5894c7872150f37da7e4fa0c2d89e4572bc63acadb5dae3286a5e5cc14a8ce3e1ebcc14571f1a3541e8db2d18d2f7503764a2f3
2 parents 28ce159 + fa71bed commit ffe4261

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

ci/test/01_base_install.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ if [ "$(git config --global ${CFG_DONE})" == "true" ]; then
1515
exit 0
1616
fi
1717

18+
MAKEJOBS="-j$( nproc )" # Use nproc, because MAKEJOBS is the default in docker image builds.
19+
1820
if [ -n "$DPKG_ADD_ARCH" ]; then
1921
dpkg --add-architecture "$DPKG_ADD_ARCH"
2022
fi
@@ -45,7 +47,7 @@ if [[ ${USE_MEMORY_SANITIZER} == "true" ]]; then
4547
-DLLVM_ENABLE_RUNTIMES="compiler-rt;libcxx;libcxxabi;libunwind" \
4648
-S /msan/llvm-project/llvm
4749

48-
ninja -C /msan/clang_build/ "-j$( nproc )" # Use nproc, because MAKEJOBS is the default in docker image builds
50+
ninja -C /msan/clang_build/ "$MAKEJOBS"
4951
ninja -C /msan/clang_build/ install-runtimes
5052

5153
update-alternatives --install /usr/bin/clang++ clang++ /msan/clang_build/bin/clang++ 100
@@ -64,7 +66,7 @@ if [[ ${USE_MEMORY_SANITIZER} == "true" ]]; then
6466
-DLIBCXX_HARDENING_MODE=debug \
6567
-S /msan/llvm-project/runtimes
6668

67-
ninja -C /msan/cxx_build/ "-j$( nproc )" # Use nproc, because MAKEJOBS is the default in docker image builds
69+
ninja -C /msan/cxx_build/ "$MAKEJOBS"
6870

6971
# Clear no longer needed source folder
7072
du -sh /msan/llvm-project
@@ -74,7 +76,7 @@ fi
7476
if [[ "${RUN_TIDY}" == "true" ]]; then
7577
${CI_RETRY_EXE} git clone --depth=1 https://github.com/include-what-you-use/include-what-you-use -b clang_"${TIDY_LLVM_V}" /include-what-you-use
7678
cmake -B /iwyu-build/ -G 'Unix Makefiles' -DCMAKE_PREFIX_PATH=/usr/lib/llvm-"${TIDY_LLVM_V}" -S /include-what-you-use
77-
make -C /iwyu-build/ install "-j$( nproc )" # Use nproc, because MAKEJOBS is the default in docker image builds
79+
make -C /iwyu-build/ install "$MAKEJOBS"
7880
fi
7981

8082
mkdir -p "${DEPENDS_DIR}/SDKs" "${DEPENDS_DIR}/sdk-sources"

ci/test/02_run_container.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,22 @@ if [ -z "$DANGER_RUN_CI_ON_HOST" ]; then
1515
python3 -c 'import os; [print(f"{key}={value}") for key, value in os.environ.items() if "\n" not in value and "HOME" != key and "PATH" != key and "USER" != key]' | tee "/tmp/env-$USER-$CONTAINER_NAME"
1616
# System-dependent env vars must be kept as is. So read them from the container.
1717
docker run --rm "${CI_IMAGE_NAME_TAG}" bash -c "env | grep --extended-regexp '^(HOME|PATH|USER)='" | tee --append "/tmp/env-$USER-$CONTAINER_NAME"
18+
19+
# Env vars during the build can not be changed. For example, a modified
20+
# $MAKEJOBS is ignored in the build process. Use --cpuset-cpus as an
21+
# approximation to respect $MAKEJOBS somewhat, if cpuset is available.
22+
MAYBE_CPUSET=""
23+
if [ "$HAVE_CGROUP_CPUSET" ]; then
24+
MAYBE_CPUSET="--cpuset-cpus=$( python3 -c "import random;P=$( nproc );M=min(P,int('$MAKEJOBS'.lstrip('-j')));print(','.join(map(str,sorted(random.sample(range(P),M)))))" )"
25+
fi
1826
echo "Creating $CI_IMAGE_NAME_TAG container to run in"
1927

28+
# shellcheck disable=SC2086
2029
DOCKER_BUILDKIT=1 docker build \
2130
--file "${BASE_READ_ONLY_DIR}/ci/test_imagefile" \
2231
--build-arg "CI_IMAGE_NAME_TAG=${CI_IMAGE_NAME_TAG}" \
2332
--build-arg "FILE_ENV=${FILE_ENV}" \
33+
$MAYBE_CPUSET \
2434
--label="${CI_IMAGE_LABEL}" \
2535
--tag="${CONTAINER_NAME}" \
2636
"${BASE_READ_ONLY_DIR}"

0 commit comments

Comments
 (0)