Merge pull request #854 from misterdjules/fix-node-smartos-support
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Fix support for installing node on SmartOS
authored by Jordan Harband · committed by Jordan Harband · parents 8aebf86, 2d692d9 · Browse files · 14 files·+282 added−8 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
14 files+282 added−8 removed
- tests:+207 added−0 removed
- other:+75 added−8 removed
Provenance
- Commit
f73ee40- Tree
d0f8f46- Author
Jordan Harband <ljharb@gmail.com>- Committer
Jordan Harband <ljharb@gmail.com>- Parent 1
8aebf86- Parent 2
2d692d9
14 files changed+282 added−8 removed
added:test/fast/Unit tests/iojs_version_has_solaris_binary+17 added
1+#!/bin/sh2+3+die () { echo $@ ; exit 1; }4+5+. ../../../nvm.sh6+. ../../common.sh7+8+assert_not_ok iojs_version_has_solaris_binary ""9+assert_not_ok iojs_version_has_solaris_binary "foo"10+assert_not_ok iojs_version_has_solaris_binary "v1.1.0"11+12+assert_ok iojs_version_has_solaris_binary "v3.3.1"13+assert_ok iojs_version_has_solaris_binary "iojs-v3.3.1"14+assert_ok iojs_version_has_solaris_binary "v3.3.2"15+assert_ok iojs_version_has_solaris_binary "iojs-v3.3.2"16+assert_ok iojs_version_has_solaris_binary "v3.4.1"17+assert_ok iojs_version_has_solaris_binary "iojs-v3.4.1"added:test/fast/Unit tests/node_version_has_solaris_binary+33 added
1+#!/bin/sh2+3+die () { echo $@ ; exit 1; }4+5+. ../../../nvm.sh6+. ../../common.sh7+8+# Invalid version numbers fail9+assert_not_ok node_version_has_solaris_binary ""10+assert_not_ok node_version_has_solaris_binary "foo"11+12+# "Invalid" node version numbers fail13+assert_not_ok node_version_has_solaris_binary "v1.0.0"14+assert_not_ok node_version_has_solaris_binary "v3.3.1"15+16+# Valid io.js version numbers that have a Solaris binary fail17+assert_not_ok node_version_has_solaris_binary "iojs-v3.3.1"18+19+# Invvalid io.js version numbers fail20+assert_not_ok node_version_has_solaris_binary "iojs-v0.12.7"21+22+# Valid node version numbers that don't have a Solaris binary fail23+assert_not_ok node_version_has_solaris_binary "v0.8.5"24+25+# Valid node version numbers that have a Solaris binary succeed26+assert_ok node_version_has_solaris_binary "v0.8.6"27+assert_ok node_version_has_solaris_binary "v0.10.0"28+assert_ok node_version_has_solaris_binary "v0.12.7"29+30+# Valid "merged" version numbers fail, because they're not31+# considered node version numbers32+assert_not_ok node_version_has_solaris_binary "v4.0.0"33+assert_not_ok node_version_has_solaris_binary "v4.1.1"added:test/fast/Unit tests/nvm_get_arch+80 added
1+#!/bin/sh2+3+# Save the PATH as it was when the test started to restore it when it4+# finishes5+ORIG_PATH=$PATH6+7+cleanup() {8+ # Restore the PATH as it was when the test started9+ export PATH=ORIG_PATH10+}11+12+die () { cleanup; echo $@ ; exit 1; }13+14+. ../../../nvm.sh15+16+# Directory where mocked binaries used by nvm_get_arch for each OS/arch are17+# located18+MOCKS_DIR=`pwd`/../../mocks19+# Sets the PATH for these tests to include the symlinks to the mocked20+# binaries21+export PATH=.:${PATH}22+23+# Setups mock binaries for a given OS and arch that mimic24+# the output of the real binaries used by nvm_get_arch to guess25+# the architecture of a given system.26+setup_mock_arch() {27+ local OS=$128+ local ARCH=$229+ local OPT=$330+31+ if [ "_$OS" = "_solaris" ] || [ "_$OS" = "_smartos" ]; then32+ ln -sf "${MOCKS_DIR}/isainfo_${ARCH}" ./isainfo33+ if [ "_$OPT" != "_no_pkg_info" ]; then34+ ln -sf "${MOCKS_DIR}/pkg_info_${ARCH}" ./pkg_info35+ fi36+ fi37+38+ ln -sf "${MOCKS_DIR}/uname_${OS}_${ARCH}" ./uname39+}40+41+# Cleans up the setup done by setup_mock_arch.42+cleanup_mock_arch() {43+ local OS=$144+ local ARCH=$245+46+ if [ "_$OS" = "_solaris" ] || [ "_$OS" = "_smartos" ]; then47+ rm -f ./isainfo48+ rm -f ./pkg_info49+ fi50+51+ rm -f ./uname52+}53+54+# Runs nvm_get_arch for architecture $ARCH and OS $OS, and compares the55+# expected output $EXPECTED_OUTPUT with the actual output. Does nothing56+# and exits cleanly if they match, dies otherwise.57+run_test() {58+ local ARCH=$159+ local OS=$260+ local EXPECTED_OUTPUT=$361+ local OPT=$462+63+ setup_mock_arch $OS $ARCH $OPT64+ local OUTPUT="$(nvm_get_arch)"65+ cleanup_mock_arch $OS $ARCH66+ [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] ||67+ die "nvm_get_arch for OS \"$OS\" and arch \"$ARCH\" with OPT \"$OPT\" did68+ not return \"$EXPECTED_OUTPUT\"; got \"$OUTPUT\""69+}70+71+run_test x86 smartos x8672+run_test x86 smartos x86 no_pkg_info73+74+run_test amd64 smartos x6475+run_test amd64 smartos x64 no_pkg_info76+77+run_test x86 osx x8678+run_test amd64 osx x6479+80+cleanupadded:test/fast/Unit tests/nvm_has_solaris_binary+32 added
1+#!/bin/sh2+3+die () { echo $@ ; exit 1; }4+5+. ../../../nvm.sh6+. ../../common.sh7+8+# Invalid version numbers fail9+assert_not_ok nvm_has_solaris_binary ""10+assert_not_ok nvm_has_solaris_binary "foo"11+12+# "Invalid" node version numbers fail13+assert_not_ok nvm_has_solaris_binary "v1.0.0"14+assert_not_ok nvm_has_solaris_binary "v3.3.1"15+16+# Valid io.js version numbers that have a Solaris binary succeed17+assert_ok nvm_has_solaris_binary "iojs-v3.3.1"18+19+# Invvalid io.js version numbers fail20+assert_not_ok nvm_has_solaris_binary "iojs-v0.12.7"21+22+# Valid node version numbers that don't have a Solaris binary fail23+assert_not_ok nvm_has_solaris_binary "v0.8.5"24+25+# Valid node version numbers that have a Solaris binary succeed26+assert_ok nvm_has_solaris_binary "v0.8.6"27+assert_ok nvm_has_solaris_binary "v0.10.0"28+assert_ok nvm_has_solaris_binary "v0.12.7"29+30+# Valid "merged" version numbers succeed31+assert_ok nvm_has_solaris_binary "v4.0.0"32+assert_ok nvm_has_solaris_binary "v4.1.1"added:test/mocks/isainfo_amd64+5 added
1+if [ "_$1" = "_-n" ]; then2+ echo "amd64"3+else4+ echo "amd64 i386"5+fiadded:test/mocks/isainfo_x86+5 added
1+if [ "_$1" = "_-n" ]; then2+ echo "i386"3+else4+ echo "i386"5+fiadded:test/mocks/pkg_info_amd64+1 added
1+echo "x86_64"added:test/mocks/pkg_info_x86+1 added
1+echo "i386"added:test/mocks/uname_osx_amd64+5 added
1+if [ "_$1" = "_-m" ]; then2+ echo "x86_64"3+else4+ echo "Darwin foo.local 13.4.0 Darwin Kernel Version 13.4.0: Sun Aug 17 19:50:11 PDT 2014; root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64"5+ fiadded:test/mocks/uname_osx_x86+5 added
1+if [ "_$1" = "_-m" ]; then2+ echo "i386"3+else4+ echo "Darwin foo.local 13.4.0 Darwin Kernel Version 13.4.0: Sun Aug 17 19:50:11 PDT 2014; root:xnu-2422.115.4~1/RELEASE_I386 i386"5+ fiadded:test/mocks/uname_smartos_amd64+5 added
1+if [ "_$1" = "_-m" ]; then2+ echo "i86pc"3+else4+ echo "SunOS dev 5.11 joyent_20150219T102159Z i86pc i386 i86pc Solaris"5+fiadded:test/mocks/uname_smartos_x86+5 added
1+if [ "_$1" = "_-m" ]; then2+ echo "i86pc"3+else4+ echo "SunOS dev 5.11 joyent_20150219T102159Z i86pc i386 i86pc Solaris"5+fiadded:test/common.sh+13 added
1+assert_ok() {2+ local FUNCTION=$13+ shift4+5+ $($FUNCTION $@) || die '"'"$FUNCTION $@"'" should have succeeded, but failed'6+}7+8+assert_not_ok() {9+ local FUNCTION=$110+ shift11+12+ ! $($FUNCTION $@) || die '"'"$FUNCTION $@"'" should have failed, but succeeded'13+}modified:nvm.sh+75 added-8 removed
907 unmodified lines908 echo "$NVM_OS"909 }910 911 nvm_get_arch() {912- local NVM_UNAME913- NVM_UNAME="$(uname -m)"912+ local HOST_ARCH913+ local NVM_OS914+ local EXIT_CODE915+916+ NVM_OS="$(nvm_get_os)"917+ # If the OS is SunOS, first try to use pkgsrc to guess918+ # the most appropriate arch. If it's not available, use919+ # isainfo to get the instruction set supported by the920+ # kernel.921+ if [ "_$NVM_OS" = "_sunos" ]; then922+ HOST_ARCH=$(pkg_info -Q MACHINE_ARCH pkg_install)923+ EXIT_CODE=$?924+ if [ $EXIT_CODE -ne 0 ]; then925+ HOST_ARCH=$(isainfo -n)926+ fi927+ else928+ HOST_ARCH="$(uname -m)"929+ fi930+931 local NVM_ARCH915- case "$NVM_UNAME" in916- x86_64) NVM_ARCH="x64" ;;932+ case "$HOST_ARCH" in933+ x86_64 | amd64) NVM_ARCH="x64" ;;934 i*86) NVM_ARCH="x86" ;;918- *) NVM_ARCH="$NVM_UNAME" ;;935+ *) NVM_ARCH="$HOST_ARCH" ;;936 esac937 echo "$NVM_ARCH"938 }939 379 unmodified lines1319 fi1320 fi1321 }1322 1323+# Succeeds if $IOJS_VERSION represents an io.js version that has a1324+# Solaris binary, fails otherwise.1325+# Currently, only io.js 3.3.1 has a Solaris binary available, and it's the1326+# latest io.js version available. The expectation is that any potential io.js1327+# version later than v3.3.1 will also have Solaris binaries.1328+iojs_version_has_solaris_binary() {1329+ local IOJS_VERSION=$11330+ local STRIPPED_IOJS_VERSION="$(nvm_strip_iojs_prefix $IOJS_VERSION)"1331+ if [ "_$STRIPPED_IOJS_VERSION" = "$IOJS_VERSION" ]; then1332+ return 11333+ fi1334+1335+ # io.js started shipping Solaris binaries with io.js v3.3.11336+ nvm_version_greater_than_or_equal_to "$STRIPPED_IOJS_VERSION" v3.3.11337+}1338+1339+# Succeeds if $NODE_VERSION represents a node version that has a1340+# Solaris binary, fails otherwise.1341+# Currently, node versions starting from v0.8.6 have a Solaris binary1342+# avaliable.1343+node_version_has_solaris_binary() {1344+ local NODE_VERSION=$11345+ # Error out if $NODE_VERSION is actually an io.js version1346+ local STRIPPED_IOJS_VERSION="$(nvm_strip_iojs_prefix $NODE_VERSION)"1347+ if [ "_$STRIPPED_IOJS_VERSION" != "_$NODE_VERSION" ]; then1348+ return 11349+ fi1350+1351+ # node (unmerged) started shipping Solaris binaries with v0.8.6 and1352+ # node versions v1.0.0 or greater are not considered valid "unmerged" node1353+ # versions.1354+ nvm_version_greater_than_or_equal_to "$NODE_VERSION" v0.8.6 &&1355+ ! nvm_version_greater_than_or_equal_to "$NODE_VERSION" v1.0.01356+}1357+1358+# Succeeds if $VERSION represents a version (node, io.js or merged) that has a1359+# Solaris binary, fails otherwise.1360+nvm_has_solaris_binary() {1361+ local VERSION=$11362+ if nvm_is_merged_node_version "$VERSION"; then1363+ return 0 # All merged node versions have a Solaris binary1364+ elif nvm_is_iojs_version "$VERSION"; then1365+ iojs_version_has_solaris_binary "$VERSION"1366+ else1367+ node_version_has_solaris_binary "$VERSION"1368+ fi1369+}1370+1371 nvm() {1372 if [ $# -lt 1 ]; then1373 nvm help1374 return174 unmodified lines1549 1550 if [ "_$NVM_OS" = "_freebsd" ]; then1551 # node.js and io.js do not have a FreeBSD binary1552 nobinary=11488- elif [ "_$NVM_OS" = "_sunos" ] && ([ "$NVM_IOJS" = true ] || [ "$NVM_NODE_MERGED" = true ]); then1489- # io.js does not have a SunOS binary1490- nobinary=11553+ elif [ "_$NVM_OS" = "_sunos" ]; then1554+ # Not all node/io.js versions have a Solaris binary1555+ if ! nvm_has_solaris_binary "$VERSION"; then1556+ nobinary=11557+ fi1558 fi1559 local NVM_INSTALL_SUCCESS1560 # skip binary install if "nobinary" option specified.1561 if [ $nobinary -ne 1 ] && nvm_binary_available "$VERSION"; then633 unmodified lines