From 9b8eab31633003ed56debb567d990d016182338e Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 25 Jan 2015 12:00:52 -0800 Subject: [PATCH] [New] Add `nvm install -s iojs` support. --- nvm.sh | 73 ++++++++++++++++++- test/installation_iojs/install from source | 19 +++++ ...ll version specified in .nvmrc from source | 24 ++++++ test/installation_iojs/teardown_dir | 1 + 4 files changed, 114 insertions(+), 3 deletions(-) create mode 100755 test/installation_iojs/install from source create mode 100755 test/installation_iojs/install version specified in .nvmrc from source diff --git a/nvm.sh b/nvm.sh index e10084f..f58b234 100644 --- a/nvm.sh +++ b/nvm.sh @@ -1719,6 +1719,73 @@ nvm_get_make_jobs() { fi } +nvm_install_iojs_source() { + local VERSION + VERSION="$(nvm_strip_iojs_prefix "$1")" + local PREFIXED_VERSION + PREFIXED_VERSION="$(nvm_add_iojs_prefix "$VERSION")" + local ADDITIONAL_PARAMETERS + ADDITIONAL_PARAMETERS="$2" + + local NVM_ARCH + NVM_ARCH="$(nvm_get_arch)" + if [ $NVM_ARCH = "armv6l" ] || [ $NVM_ARCH = "armv7l" ]; then + ADDITIONAL_PARAMETERS="--without-snapshot $ADDITIONAL_PARAMETERS" + fi + + if [ -n "$ADDITIONAL_PARAMETERS" ]; then + echo "Additional options while compiling: $ADDITIONAL_PARAMETERS" + fi + + local VERSION_PATH + VERSION_PATH="$(nvm_version_path "$PREFIXED_VERSION")" + local NVM_OS + NVM_OS="$(nvm_get_os)" + + local tarball + tarball='' + local sum + sum='' + local make + make='make' + if [ "_$NVM_OS" = "_freebsd" ]; then + make='gmake' + MAKE_CXX="CXX=c++" + fi + local tmpdir + tmpdir="$NVM_DIR/src" + local tmptarball + tmptarball="$tmpdir/iojs-$VERSION.tar.gz" + + if [ "`nvm_download -L -s -I "$NVM_IOJS_ORG_MIRROR/$VERSION/iojs-$VERSION.tar.gz" -o - 2>&1 | command grep '200 OK'`" != '' ]; then + tarball="$NVM_IOJS_ORG_MIRROR/$VERSION/iojs-$VERSION.tar.gz" + sum="$(nvm_download -L -s $NVM_IOJS_ORG_MIRROR/$VERSION/SHASUMS256.txt -o - | command grep "iojs-$VERSION.tar.gz" | command awk '{print $1}')" + elif [ "`nvm_download -L -s -I "$NVM_IOJS_ORG_MIRROR/iojs-$VERSION.tar.gz" -o - | command grep '200 OK'`" != '' ]; then + tarball="$NVM_IOJS_ORG_MIRROR/iojs-$VERSION.tar.gz" + fi + + if ( + [ -n "$tarball" ] && \ + command mkdir -p "$tmpdir" && \ + nvm_download -L --progress-bar "$tarball" -o "$tmptarball" && \ + echo "WARNING: checksums are currently disabled for io.js" >&2 && \ + # nvm_checksum "$tmptarball" "$sum" && \ + command tar -xzf "$tmptarball" -C "$tmpdir" && \ + cd "$tmpdir/$PREFIXED_VERSION" && \ + ./configure --prefix="$VERSION_PATH" $ADDITIONAL_PARAMETERS && \ + $make -j $MAKE_CXX && \ + command rm -f "$VERSION_PATH" 2>/dev/null && \ + $make -j $MAKE_CXX install + ); then + return 0 + else + echo "nvm: install $PREFIXED_VERSION from source failed!" >&2 + return 105 + fi + + return $? +} + nvm_install_node_source() { local VERSION VERSION="${1}" @@ -2286,9 +2353,9 @@ nvm() { case "true" in "$NVM_IOJS") - # nvm_install_iojs_source "$VERSION" "$NVM_MAKE_JOBS" "$ADDITIONAL_PARAMETERS" - nvm_err 'Installing iojs from source is not currently supported' - return 105 + if nvm_install_iojs_source "$VERSION" "$NVM_MAKE_JOBS" "$ADDITIONAL_PARAMETERS"; then + NVM_INSTALL_SUCCESS=true + fi ;; "$NVM_NODE_MERGED") # nvm_install_merged_node_source "$VERSION" "$NVM_MAKE_JOBS" "$ADDITIONAL_PARAMETERS" diff --git a/test/installation_iojs/install from source b/test/installation_iojs/install from source new file mode 100755 index 0000000..7b44643 --- /dev/null +++ b/test/installation_iojs/install from source @@ -0,0 +1,19 @@ +#!/bin/sh + +die () { echo $@ ; exit 1; } + +. ../../nvm.sh + +NVM_TEST_VERSION="v1.0.0" +NVM_PREFIXED_TEST_VERSION="iojs-$NVM_TEST_VERSION" + +# Remove the stuff we're clobbering. +[ -e ../../versions/io.js/$NVM_TEST_VERSION ] && rm -R ../../versions/io.js/$NVM_TEST_VERSION + +# Install from source +nvm install -s $NVM_PREFIXED_TEST_VERSION || die "'nvm install -s $NVM_PREFIXED_TEST_VERSION' failed" + +# Check +[ -d ../../versions/io.js/$NVM_TEST_VERSION ] +nvm run $NVM_PREFIXED_TEST_VERSION --version | grep $NVM_TEST_VERSION || "'nvm run $NVM_PREFIXED_TEST_VERSION --version | grep $NVM_TEST_VERSION' failed" + diff --git a/test/installation_iojs/install version specified in .nvmrc from source b/test/installation_iojs/install version specified in .nvmrc from source new file mode 100755 index 0000000..d17a6bb --- /dev/null +++ b/test/installation_iojs/install version specified in .nvmrc from source @@ -0,0 +1,24 @@ +#!/bin/sh + +die () { echo $@ ; exit 1; } + +. ../../nvm.sh + +NVM_TEST_VERSION=v1.0.3 +NVM_PREFIXED_TEST_VERSION="iojs-$NVM_TEST_VERSION" +VERSION_PATH="../../versions/io.js/$NVM_TEST_VERSION" + +# Remove the stuff we're clobbering. +[ -e "$VERSION_PATH" ] && rm -R "$VERSION_PATH" + +# Install from binary +echo "$NVM_PREFIXED_TEST_VERSION" > .nvmrc + +nvm install -s || "'nvm install -s' failed" + +# Check +[ -d "$VERSION_PATH" ] || die "$VERSION_PATH did not exist" +nvm run $NVM_PREFIXED_TEST_VERSION --version | grep $NVM_TEST_VERSION \ + || die "'nvm run $NVM_PREFIXED_TEST_VERSION --version | grep $NVM_TEST_VERSION' failed" + + diff --git a/test/installation_iojs/teardown_dir b/test/installation_iojs/teardown_dir index 9f6d025..d45c66a 100755 --- a/test/installation_iojs/teardown_dir +++ b/test/installation_iojs/teardown_dir @@ -3,6 +3,7 @@ . ../../nvm.sh nvm deactivate nvm uninstall iojs-v1.0.0 +nvm uninstall iojs-v1.0.3 if [ -f ".nvmrc" ]; then rm .nvmrc