From 58ca27984b672877bb0434313fe8a078bdd9bf46 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Tue, 1 Nov 2022 09:57:16 -0400 Subject: [PATCH] script: move get_processors to lib-build.sh This function can be more useful because the NPROC value can be provided regardless of how many cores nproc actually detects and may be handy in a restricted environment like a container. The new version quotes some values and uses $((...)) as per shellcheck warning that "expr is antiquated". Signed-off-by: John Mulligan (cherry picked from commit a76a0cfdc63b8f7daefefeb1af542db56310a2da) --- src/script/lib-build.sh | 17 +++++++++++++++++ src/script/run-make.sh | 13 ------------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/script/lib-build.sh b/src/script/lib-build.sh index a6ff447c99e..17c2fe72148 100644 --- a/src/script/lib-build.sh +++ b/src/script/lib-build.sh @@ -31,3 +31,20 @@ function ci_debug() { echo "CI_DEBUG: $*" fi } + +# get_processors returns 1/2 the value of the value returned by +# the nproc program OR the value of the environment variable NPROC +# allowing the user to tune the number of cores visible to the +# build scripts. +function get_processors() { + # get_processors() depends on coreutils nproc. + if [ -n "$NPROC" ]; then + echo "$NPROC" + else + if [ "$(nproc)" -ge 2 ]; then + echo "$(($(nproc) / 2))" + else + echo 1 + fi + fi +} diff --git a/src/script/run-make.sh b/src/script/run-make.sh index 3ab00861519..4331e581aa5 100755 --- a/src/script/run-make.sh +++ b/src/script/run-make.sh @@ -27,19 +27,6 @@ function clean_up_after_myself() { restore_ccache_conf } -function get_processors() { - # get_processors() depends on coreutils nproc. - if test -n "$NPROC" ; then - echo $NPROC - else - if test $(nproc) -ge 2 ; then - expr $(nproc) / 2 - else - echo 1 - fi - fi -} - function detect_ceph_dev_pkgs() { local cmake_opts="-DWITH_FMT_VERSION=9.0.0" local boost_root=/opt/ceph -- 2.39.5