Skip to content

Commit

Permalink
script: move get_processors to lib-build.sh
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
phlogistonjohn committed Feb 7, 2023
1 parent 1361f2e commit a76a0cf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
17 changes: 17 additions & 0 deletions src/script/lib-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
13 changes: 0 additions & 13 deletions src/script/run-make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a76a0cf

Please sign in to comment.