]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
script: move get_processors to lib-build.sh
authorJohn Mulligan <jmulligan@redhat.com>
Tue, 1 Nov 2022 13:57:16 +0000 (09:57 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Tue, 18 Feb 2025 22:58:08 +0000 (17:58 -0500)
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 <jmulligan@redhat.com>
(cherry picked from commit a76a0cfdc63b8f7daefefeb1af542db56310a2da)

src/script/lib-build.sh
src/script/run-make.sh

index a6ff447c99ee4eadbed311a3397f5abad90cb554..17c2fe72148c7198565c5c371f340e5084b9cc30 100644 (file)
@@ -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
+}
index 3ab00861519d995ebdb02c7ab3c6dc174c6f17e9..4331e581aa5849a0e5985d4bfd9c3a94748f64ce 100755 (executable)
@@ -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