Skip to content

Commit bb2c32f

Browse files
committed
Cross platform solution to getting amount of cpu cores
1 parent 8b20844 commit bb2c32f

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

bin/journey-test.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
TRACK=java
66
TRACK_REPO="$TRACK"
77
TRACK_SRC_EXT="java"
8+
CPU_CORES=`getconf NPROCESSORS_ONLN 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1`
89

910
on_exit() {
1011
echo ">>> on_exit()"
@@ -98,6 +99,14 @@ get_cpu_architecture() {
9899
esac
99100
}
100101

102+
get_optimal_amount_of_jobs() {
103+
if [ "$CPU_CORES" -gt "1" ]; then
104+
echo $((CPU_CORES-1))
105+
else
106+
echo 1
107+
fi
108+
}
109+
101110
download_exercism_cli() {
102111
local os="$1"
103112
local arch="$2"
@@ -164,7 +173,7 @@ make_local_trackler() {
164173
cp -r ${track_root}/exercises tracks/${TRACK}
165174

166175
gem install bundler
167-
bundle install --jobs $((`nproc --all`-1))
176+
bundle install --jobs $(get_optimal_amount_of_jobs)
168177
gem build trackler.gemspec
169178

170179
# Make *this* the gem that x-api uses when we build x-api.
@@ -181,7 +190,7 @@ start_x_api() {
181190
pushd $xapi_home
182191

183192
gem install bundler
184-
bundle install --jobs $((`nproc --all`-1))
193+
bundle install --jobs $(get_optimal_amount_of_jobs)
185194
RACK_ENV=development rackup &
186195
xapi_pid=$!
187196
sleep 5

0 commit comments

Comments
 (0)