From 4c8dbdbb85b5198dd68a30c825679c0897d2d742 Mon Sep 17 00:00:00 2001 From: interfector18 Date: Mon, 16 Mar 2020 17:54:30 +0100 Subject: [PATCH] Ninja (#391) Use ninja to build if found on system (in /bin/ninja) Make make simulate ninja's default parallelism Should help with travis_ci as default build environments have 2 cores. --- build.sh | 33 +++++++++++++++++++++++++++++---- test.sh | 31 ++++++++++++++++++++++++++++--- 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/build.sh b/build.sh index 4166596e..07803961 100755 --- a/build.sh +++ b/build.sh @@ -28,9 +28,9 @@ function build_drogon() { echo "Start building drogon ..." if [ $1 -eq 1 ]; then - cmake .. -DBUILD_TESTING=YES + cmake .. -DBUILD_TESTING=YES $cmake_gen else - cmake .. + cmake .. $cmake_gen fi #If errors then exit @@ -38,7 +38,7 @@ function build_drogon() { exit -1 fi - make + $make_program $make_flags #If errors then exit if [ "$?" != "0" ]; then @@ -46,13 +46,38 @@ function build_drogon() { fi echo "Installing ..." - sudo make install + sudo $make_program install #Go back to the current directory cd $current_dir #Ok! } +make_program=make +make_flags='' +cmake_gen='' +parallel=1 + +# simulate ninja's parallelism +case $(nproc) in + 1) + parallel=$(( $(nproc) + 1 )) + ;; + 2) + parallel=$(( $(nproc) + 1 )) + ;; + *) + parallel=$(( $(nproc) + 2 )) + ;; +esac + +if [ -f /bin/ninja ]; then + make_program=ninja + cmake_gen='-G Ninja' +else + make_flags="$make_flags -j$parallel" +fi + if [ "$1" = "-t" ]; then build_drogon 1 else diff --git a/test.sh b/test.sh index 319f596b..343f624a 100755 --- a/test.sh +++ b/test.sh @@ -4,6 +4,31 @@ drogon_ctl_exec=`pwd`/build/drogon_ctl/drogon_ctl echo ${drogon_ctl_exec} cd build/examples/ +make_program=make +make_flags='' +cmake_gen='' +parallel=1 + +# simulate ninja's parallelism +case $(nproc) in + 1) + parallel=$(( $(nproc) + 1 )) + ;; + 2) + parallel=$(( $(nproc) + 1 )) + ;; + *) + parallel=$(( $(nproc) + 2 )) + ;; +esac + +if [ -f /bin/ninja ]; then + make_program=ninja + cmake_gen='-G Ninja' +else + make_flags="$make_flags -j$parallel" +fi + #Make webapp run as a daemon sed -i -e "s/\"run_as_daemon.*$/\"run_as_daemon\": true\,/" config.example.json sed -i -e "s/\"relaunch_on_error.*$/\"relaunch_on_error\": true\,/" config.example.json @@ -93,14 +118,14 @@ if [ ! -f "Test_TestPlugin.h" -o ! -f "Test_TestPlugin.cc" ]; then fi cd ../build -cmake .. +cmake .. $cmake_gen if [ $? -ne 0 ]; then echo "Error in testing" exit -1 fi -make +$make_program $make_flags if [ $? -ne 0 ]; then echo "Error in testing" @@ -119,7 +144,7 @@ if [ "$1" = "-t" ]; then #unit testing cd ../ echo "Unit testing" - make test + $make_program $make_flags test if [ $? -ne 0 ]; then echo "Error in unit testing" exit -1