From 6b3479108fea37a96efccb1d79a15c67174a830f Mon Sep 17 00:00:00 2001 From: yalpul Date: Wed, 25 Mar 2020 21:51:40 +0300 Subject: [PATCH] CI: Make processor count consistent Code formatting script was using `sysctl -n hw.physicalcpu` on macOS machines to get the CPU count. This command returns the physical CPUs. `nproc`, however, returns logical CPU count on Linux machines. It should be `sysctl -n hw.logicalcpu` to make it consistent with its Linux counterpart. But there also another way. `getconf _NPROCESSORS_ONLN` gives the number of logical CPUs on both Linux and macOS. --- formatcode.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/formatcode.sh b/formatcode.sh index 87a54785e..f585bc2b3 100755 --- a/formatcode.sh +++ b/formatcode.sh @@ -14,10 +14,8 @@ set -o nounset # Get CPU count OS=$(uname) NPROC=1 -if [[ $OS = "Linux" ]] ; then - NPROC=$(nproc) -elif [[ ${OS} = "Darwin" ]] ; then - NPROC=$(sysctl -n hw.physicalcpu) +if [[ $OS = "Linux" || $OS = "Darwin" ]] ; then + NPROC=$(getconf _NPROCESSORS_ONLN) fi # Discover clang-format