[Refactor] Create `nvm_get_make_jobs` to abstract out “-j” logic.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Jordan Harband · committed by Jordan Harband · parent dc8b63c · Browse files · 1 file·+43 added−34 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+43 added−34 removed
- other:+43 added−34 removed
Provenance
- Commit
2541baa- Tree
19f5446- Author
Jordan Harband <ljharb@gmail.com>- Committer
Jordan Harband <ljharb@gmail.com>- Parent
dc8b63c
1 file changed+43 added−34 removed
modified:nvm.sh+43 added-34 removed
1198 unmodified lines1199 fi1200 return 21201 }1202 1203+nvm_get_make_jobs() {1204+ if nvm_is_natural_num "$1"; then1205+ NVM_MAKE_JOBS="$1"1206+ echo "number of \`make\` jobs: $NVM_MAKE_JOBS"1207+ return1208+ elif [ -n "$1" ]; then1209+ unset NVM_MAKE_JOBS1210+ echo >&2 "$1 is invalid for number of \`make\` jobs, must be a natural number"1211+ fi1212+ local NVM_OS1213+ NVM_OS="$(nvm_get_os)"1214+ local NVM_CPU_THREADS1215+ if [ "_$NVM_OS" = "_linux" ]; then1216+ NVM_CPU_THREADS="$(grep -c 'core id' /proc/cpuinfo)"1217+ elif [ "_$NVM_OS" = "_freebsd" ] || [ "_$NVM_OS" = "_darwin" ]; then1218+ NVM_CPU_THREADS="$(sysctl -n hw.ncpu)"1219+ elif [ "_$NVM_OS" = "_sunos" ]; then1220+ NVM_CPU_THREADS="$(psrinfo | wc -l)"1221+ fi1222+ if ! nvm_is_natural_num "$NVM_CPU_THREADS" ; then1223+ echo "Can not determine how many thread(s) we can use, set to only 1 now." >&21224+ echo "Please report an issue on GitHub to help us make it better and run it faster on your computer!" >&21225+ NVM_MAKE_JOBS=11226+ else1227+ echo "Detected that you have $NVM_CPU_THREADS CPU thread(s)"1228+ if [ $NVM_CPU_THREADS -gt 2 ]; then1229+ NVM_MAKE_JOBS=$(($NVM_CPU_THREADS - 1))1230+ echo "Set the number of jobs to $NVM_CPU_THREADS - 1 = $NVM_MAKE_JOBS jobs to speed up the build"1231+ else1232+ NVM_MAKE_JOBS=11233+ echo "Number of CPU thread(s) less or equal to 2 will have only one job a time for 'make'"1234+ fi1235+ fi1236+}1237+1238 nvm_install_node_source() {1239 local VERSION1240 VERSION="$1"1241+ local NVM_MAKE_JOBS1242+ NVM_MAKE_JOBS="$2"1243 local ADDITIONAL_PARAMETERS1207- ADDITIONAL_PARAMETERS="$2"1244+ ADDITIONAL_PARAMETERS="$3"1245 1246 local NVM_ARCH1247 NVM_ARCH="$(nvm_get_arch)"1248 if [ "_$NVM_ARCH" = '_armv6l' ] || [ "_$NVM_ARCH" = '_armv7l' ]; then19 unmodified lines1268 make='gmake'1269 MAKE_CXX="CXX=c++"1270 fi1271 1235- 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- if ! nvm_is_natural_num "$NVM_CPU_THREADS" ; then1244- echo "Can not determine how many thread(s) we can use, set to only 1 now." 1>&21245- echo "Please report an issue on GitHub to help us make it better and run it faster on your computer!" 1>&21246- NVM_MAKE_JOBS="1"1247- else1248- echo "Detected that you have $NVM_CPU_THREADS CPU thread(s)"1249- if [ $NVM_CPU_THREADS -gt 2 ]; then1250- NVM_MAKE_JOBS=$(($NVM_CPU_THREADS - 1))1251- echo "Set the number of jobs to $NVM_CPU_THREADS - 1 = $NVM_MAKE_JOBS jobs to speed up the build"1252- else1253- NVM_MAKE_JOBS=11254- echo "Number of CPU thread(s) less or equal to 2 will have only one job a time for 'make'"1255- fi1256- fi1257- fi1272 local tmpdir1273 tmpdir="$NVM_DIR/src"1274 local tmptarball1275 tmptarball="$tmpdir/node-$VERSION.tar.gz"315 unmodified lines1591 shift1592 1593 local nobinary1594 nobinary=01595+ local make_jobs1596 while [ $# -ne 0 ]1597 do1598 case "$1" in1599 -s)1 unmodified line1601 nobinary=11602 ;;1603 -j)1604 shift # consume "-j"1590- if nvm_is_natural_num "$1"; then1591- NVM_MAKE_JOBS=$11592- echo "number of \`make\` jobs: $NVM_MAKE_JOBS"1593- else1594- unset NVM_MAKE_JOBS1595- echo >&2 "$1 is invalid for number of \`make\` jobs, must be a natural number"1596- fi1605+ nvm_get_make_jobs "$1"1606 shift # consume job count1607 ;;1608 *)1609 break # stop parsing args91 unmodified lines1701 fi1702 fi1703 if [ "$NVM_INSTALL_SUCCESS" != true ]; then1704 if [ "$NVM_IOJS" != true ] && [ "$NVM_NODE_MERGED" != true ]; then1696- if nvm_install_node_source "$VERSION" "$ADDITIONAL_PARAMETERS"; then1705+ if nvm_install_node_source "$VERSION" "$NVM_MAKE_JOBS" "$ADDITIONAL_PARAMETERS"; then1706 NVM_INSTALL_SUCCESS=true1707 fi1708 elif [ "$NVM_IOJS" = true ]; then1700- # nvm_install_iojs_source "$VERSION" "$ADDITIONAL_PARAMETERS"1709+ # nvm_install_iojs_source "$VERSION" "$NVM_MAKE_JOBS" "$ADDITIONAL_PARAMETERS"1710 echo "Installing iojs from source is not currently supported" >&21711 return 1051712 elif [ "$NVM_NODE_MERGED" = true ]; then1704- # nvm_install_merged_node_source "$VERSION" "$ADDITIONAL_PARAMETERS"1713+ # nvm_install_merged_node_source "$VERSION" "$NVM_MAKE_JOBS" "$ADDITIONAL_PARAMETERS"1714 echo "Installing node v1.0 and greater from source is not currently supported" >&21715 return 1061716 fi1717 fi630 unmodified lines