[Refactor] `nvm install`: make `-j` and `-s` order-independent.
parent
1a6f85da46
commit
31457fec3f
32
nvm.sh
32
nvm.sh
|
@ -1554,10 +1554,8 @@ nvm() {
|
|||
;;
|
||||
|
||||
"install" | "i" )
|
||||
local nobinary
|
||||
local version_not_provided
|
||||
version_not_provided=0
|
||||
local provided_version
|
||||
local NVM_OS
|
||||
NVM_OS="$(nvm_get_os)"
|
||||
|
||||
|
@ -1577,27 +1575,35 @@ nvm() {
|
|||
|
||||
shift
|
||||
|
||||
local nobinary
|
||||
nobinary=0
|
||||
if [ "_$1" = "_-s" ]; then
|
||||
while [ $# -ne 0 ]
|
||||
do
|
||||
case "$1" in
|
||||
-s)
|
||||
shift # consume "-s"
|
||||
nobinary=1
|
||||
shift
|
||||
if [ "_$1" = "_-j" ]; then
|
||||
shift
|
||||
;;
|
||||
-j)
|
||||
shift # consume "-j"
|
||||
local NVM_CPU_THREAD_VALID
|
||||
NVM_CPU_THREAD_VALID=$(nvm_is_natural_num $1)
|
||||
if [ "$NVM_CPU_THREAD_VALID" = "true" ]; then
|
||||
NVM_MAKE_JOBS=$1
|
||||
echo "Set number of jobs to $MAKE_JOBS for 'make' utility"
|
||||
echo "number of \`make\` jobs: $NVM_MAKE_JOBS"
|
||||
else
|
||||
unset NVM_MAKE_JOBS
|
||||
echo >&2 "$1 is invalid for CPU threads, should be a natural number"
|
||||
fi
|
||||
shift
|
||||
else
|
||||
unset NVM_MAKE_JOBS
|
||||
fi
|
||||
echo >&2 "$1 is invalid for number of \`make\` jobs, must be a natural number"
|
||||
fi
|
||||
shift # consume job count
|
||||
;;
|
||||
*)
|
||||
break # stop parsing args
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
local provided_version
|
||||
provided_version="$1"
|
||||
|
||||
if [ -z "$provided_version" ]; then
|
||||
|
|
|
@ -11,7 +11,7 @@ NVM_TEST_VERSION=v0.10.41
|
|||
# Remove the stuff we're clobbering.
|
||||
[ -e ../../../$NVM_TEST_VERSION ] && rm -R ../../../$NVM_TEST_VERSION
|
||||
|
||||
# Install from source with 1 CPU thread parameter
|
||||
# Install from source with 1 make job
|
||||
nvm install -s -j 1 $NVM_TEST_VERSION || die "'nvm install -s $NVM_TEST_VERSION' failed"
|
||||
|
||||
# Check
|
||||
|
@ -25,8 +25,8 @@ nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION || "'nvm run $NVM_T
|
|||
# Remove the stuff we're clobbering.
|
||||
[ -e ../../../$NVM_TEST_VERSION ] && rm -R ../../../$NVM_TEST_VERSION
|
||||
|
||||
# Install from source with 2 CPU threads parameter
|
||||
nvm install -s -j 2 $NVM_TEST_VERSION || die "'nvm install -s $NVM_TEST_VERSION' failed"
|
||||
# Install from source with 2 make jobs (and swapped arg order)
|
||||
nvm install -j 2 -s $NVM_TEST_VERSION || die "'nvm install -s $NVM_TEST_VERSION' failed"
|
||||
|
||||
# Check
|
||||
[ -d ../../../$NVM_TEST_VERSION ]
|
||||
|
|
Loading…
Reference in New Issue