Skip to content
Myr

Merge pull request #752 from PeterDaveHelloKitchen/parallel_build

Before adoption: this commit came in with the history the project adopted, so no landing records it.

[New] `nvm install`: Enable multiple jobs for make when build from source via `-j`

authored by Jordan Harband · committed by Jordan Harband · parents f851716, cfccf03 · Browse files · 2 files+86 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+86 added−2 removed

  • tests:+33 added−0 removed
  • other:+53 added−2 removed

2 files+86 added−2 removed

added:test/installation/node/install from source with thread parameter+33 added
1#!/bin/sh23die () { echo $@ ; exit 1; }45. ../../../nvm.sh67NVM_TEST_VERSION=v0.10.4189# STAGE 1 #1011# Remove the stuff we're clobbering.12[ -e ../../../$NVM_TEST_VERSION ] && rm -R ../../../$NVM_TEST_VERSION1314# Install from source with 1 CPU thread parameter15nvm install -s -j 1 $NVM_TEST_VERSION || die "'nvm install -s $NVM_TEST_VERSION' failed"1617# Check18[ -d ../../../$NVM_TEST_VERSION ]19nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION || "'nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION' failed"20212223# STAGE 2 #2425# Remove the stuff we're clobbering.26[ -e ../../../$NVM_TEST_VERSION ] && rm -R ../../../$NVM_TEST_VERSION2728# Install from source with 2 CPU threads parameter29nvm install -s -j 2 $NVM_TEST_VERSION || die "'nvm install -s $NVM_TEST_VERSION' failed"3031# Check32[ -d ../../../$NVM_TEST_VERSION ]33nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION || "'nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION' failed"
modified:nvm.sh+53 added-2 removed
1229 unmodified lines
1230 if [ "_$NVM_OS" = "_freebsd" ]; then1231 make='gmake'1232 MAKE_CXX="CXX=c++"1233 fi12341235 if [ -z "$NVM_MAKE_JOBS" ]; then1236 if [ "_$NVM_OS" = "_linux" ]; then1237 NVM_CPU_THREADS="$(grep -c 'core id' /proc/cpuinfo)"1238 elif [ "_$NVM_OS" = "_freebsd" ] || [ "_$NVM_OS" = "_darwin" ]; then1239 NVM_CPU_THREADS="$(sysctl -n hw.ncpu)"1240 elif [ "_$NVM_OS" = "_sunos" ]; then1241 NVM_CPU_THREADS="$(psrinfo | wc -l)"1242 fi1243 local NVM_CPU_THREAD_VALID1244 NVM_CPU_THREAD_VALID=$(nvm_is_natural_num $NVM_CPU_THREADS)1245 if [ -z "$NVM_CPU_THREADS" ] || [ "$NVM_CPU_THREAD_VALID" != "true" ] ; then1246 echo "Can not determine how many thread(s) we can use, set to only 1 now." 1>&21247 echo "Please report an issue on GitHub to help us make it better and run it faster on your computer!" 1>&21248 NVM_MAKE_JOBS="1"1249 else1250 echo "Detected that you have $NVM_CPU_THREADS CPU thread(s)"1251 if [ $NVM_CPU_THREADS -gt 2 ]; then1252 NVM_MAKE_JOBS=$(($NVM_CPU_THREADS - 1))1253 echo "Set the number of jobs to $NVM_CPU_THREADS - 1 = $NVM_MAKE_JOBS jobs to speed up the build"1254 else1255 NVM_MAKE_JOBS=11256 echo "Number of CPU thread(s) less or equal to 2 will have only one job a time for 'make'"1257 fi1258 fi1259 fi1260 local tmpdir1261 tmpdir="$NVM_DIR/src"1262 local tmptarball1263 tmptarball="$tmpdir/node-$VERSION.tar.gz"
13 unmodified lines
1277 nvm_checksum "$tmptarball" "$sum" && \1278 command tar -xzf "$tmptarball" -C "$tmpdir" && \1279 cd "$tmpdir/node-$VERSION" && \1280 ./configure --prefix="$VERSION_PATH" $ADDITIONAL_PARAMETERS && \1255 $make $MAKE_CXX && \1281 $make -j $NVM_MAKE_JOBS $MAKE_CXX && \1282 command rm -f "$VERSION_PATH" 2>/dev/null && \1257 $make $MAKE_CXX install1283 $make -j $NVM_MAKE_JOBS $MAKE_CXX install1284 )1285 then1286 if ! nvm_has "npm" ; then1287 echo "Installing npm..."
167 unmodified lines
1455 fi1456 echo "$SANITIZED_PATH" | command sed "s#$HOME#\$HOME#g"1457}14581459nvm_is_natural_num() {1460 echo $1 | command egrep -q '^[0-9]{1,}$' &> /dev/null1461 local IS_NATURAL_NUM=$?1462 if [ "$IS_NATURAL_NUM" = "0" ]; then1463 echo true1464 else1465 echo false1466 fi1467}14681469nvm() {1470 if [ $# -lt 1 ]; then1471 nvm help1472 return
107 unmodified lines
1580 nobinary=01581 if [ "_$1" = "_-s" ]; then1582 nobinary=11583 shift1584 if [ "_$1" = "_-j" ]; then1585 shift1586 local NVM_CPU_THREAD_VALID1587 NVM_CPU_THREAD_VALID=$(nvm_is_natural_num $1)1588 if [ "$NVM_CPU_THREAD_VALID" = "true" ]; then1589 NVM_MAKE_JOBS=$11590 echo "Set number of jobs to $MAKE_JOBS for 'make' utility"1591 else1592 unset NVM_MAKE_JOBS1593 echo >&2 "$1 is invalid for CPU threads, should be a natural number"1594 fi1595 shift1596 else1597 unset NVM_MAKE_JOBS1598 fi1599 fi16001601 provided_version="$1"1602
731 unmodified lines