Skip to content

Commit fa71bed

Browse files
author
MarcoFalke
committed
ci: Approximate MAKEJOBS in image build phase
1 parent 03696bb commit fa71bed

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

ci/test/01_base_install.sh

+5-3
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

+10
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)