Skip to content
Myr

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

14 files+282 added−8 removed

added:test/fast/Unit tests/iojs_version_has_solaris_binary+17 added
1#!/bin/sh23die () { echo $@ ; exit 1; }45. ../../../nvm.sh6. ../../common.sh78assert_not_ok iojs_version_has_solaris_binary ""9assert_not_ok iojs_version_has_solaris_binary "foo"10assert_not_ok iojs_version_has_solaris_binary "v1.1.0"1112assert_ok iojs_version_has_solaris_binary "v3.3.1"13assert_ok iojs_version_has_solaris_binary "iojs-v3.3.1"14assert_ok iojs_version_has_solaris_binary "v3.3.2"15assert_ok iojs_version_has_solaris_binary "iojs-v3.3.2"16assert_ok iojs_version_has_solaris_binary "v3.4.1"17assert_ok iojs_version_has_solaris_binary "iojs-v3.4.1"
added:test/fast/Unit tests/node_version_has_solaris_binary+33 added
1#!/bin/sh23die () { echo $@ ; exit 1; }45. ../../../nvm.sh6. ../../common.sh78# Invalid version numbers fail9assert_not_ok node_version_has_solaris_binary ""10assert_not_ok node_version_has_solaris_binary "foo"1112# "Invalid" node version numbers fail13assert_not_ok node_version_has_solaris_binary "v1.0.0"14assert_not_ok node_version_has_solaris_binary "v3.3.1"1516# Valid io.js version numbers that have a Solaris binary fail17assert_not_ok node_version_has_solaris_binary "iojs-v3.3.1"1819# Invvalid io.js version numbers fail20assert_not_ok node_version_has_solaris_binary "iojs-v0.12.7"2122# Valid node version numbers that don't have a Solaris binary fail23assert_not_ok node_version_has_solaris_binary "v0.8.5"2425# Valid node version numbers that have a Solaris binary succeed26assert_ok node_version_has_solaris_binary "v0.8.6"27assert_ok node_version_has_solaris_binary "v0.10.0"28assert_ok node_version_has_solaris_binary "v0.12.7"2930# Valid "merged" version numbers fail, because they're not31# considered node version numbers32assert_not_ok node_version_has_solaris_binary "v4.0.0"33assert_not_ok node_version_has_solaris_binary "v4.1.1"
added:test/fast/Unit tests/nvm_get_arch+80 added
1#!/bin/sh23# Save the PATH as it was when the test started to restore it when it4# finishes5ORIG_PATH=$PATH67cleanup() {8 # Restore the PATH as it was when the test started9 export PATH=ORIG_PATH10}1112die () { cleanup; echo $@ ; exit 1; }1314. ../../../nvm.sh1516# Directory where mocked binaries used by nvm_get_arch for each OS/arch are17# located18MOCKS_DIR=`pwd`/../../mocks19# Sets the PATH for these tests to include the symlinks to the mocked20# binaries21export PATH=.:${PATH}2223# 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.26setup_mock_arch() {27 local OS=$128 local ARCH=$229 local OPT=$33031 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 fi3738 ln -sf "${MOCKS_DIR}/uname_${OS}_${ARCH}" ./uname39}4041# Cleans up the setup done by setup_mock_arch.42cleanup_mock_arch() {43 local OS=$144 local ARCH=$24546 if [ "_$OS" = "_solaris" ] || [ "_$OS" = "_smartos" ]; then47 rm -f ./isainfo48 rm -f ./pkg_info49 fi5051 rm -f ./uname52}5354# 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.57run_test() {58 local ARCH=$159 local OS=$260 local EXPECTED_OUTPUT=$361 local OPT=$46263 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}7071run_test x86 smartos x8672run_test x86 smartos x86 no_pkg_info7374run_test amd64 smartos x6475run_test amd64 smartos x64 no_pkg_info7677run_test x86 osx x8678run_test amd64 osx x647980cleanup
added:test/fast/Unit tests/nvm_has_solaris_binary+32 added
1#!/bin/sh23die () { echo $@ ; exit 1; }45. ../../../nvm.sh6. ../../common.sh78# Invalid version numbers fail9assert_not_ok nvm_has_solaris_binary ""10assert_not_ok nvm_has_solaris_binary "foo"1112# "Invalid" node version numbers fail13assert_not_ok nvm_has_solaris_binary "v1.0.0"14assert_not_ok nvm_has_solaris_binary "v3.3.1"1516# Valid io.js version numbers that have a Solaris binary succeed17assert_ok nvm_has_solaris_binary "iojs-v3.3.1"1819# Invvalid io.js version numbers fail20assert_not_ok nvm_has_solaris_binary "iojs-v0.12.7"2122# Valid node version numbers that don't have a Solaris binary fail23assert_not_ok nvm_has_solaris_binary "v0.8.5"2425# Valid node version numbers that have a Solaris binary succeed26assert_ok nvm_has_solaris_binary "v0.8.6"27assert_ok nvm_has_solaris_binary "v0.10.0"28assert_ok nvm_has_solaris_binary "v0.12.7"2930# Valid "merged" version numbers succeed31assert_ok nvm_has_solaris_binary "v4.0.0"32assert_ok nvm_has_solaris_binary "v4.1.1"
added:test/mocks/isainfo_amd64+5 added
1if [ "_$1" = "_-n" ]; then2 echo "amd64"3else4 echo "amd64 i386"5fi
added:test/mocks/isainfo_x86+5 added
1if [ "_$1" = "_-n" ]; then2 echo "i386"3else4 echo "i386"5fi
added:test/mocks/pkg_info_amd64+1 added
1echo "x86_64"
added:test/mocks/pkg_info_x86+1 added
1echo "i386"
added:test/mocks/uname_osx_amd64+5 added
1if [ "_$1" = "_-m" ]; then2 echo "x86_64"3else4 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 fi
added:test/mocks/uname_osx_x86+5 added
1if [ "_$1" = "_-m" ]; then2 echo "i386"3else4 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 fi
added:test/mocks/uname_smartos_amd64+5 added
1if [ "_$1" = "_-m" ]; then2 echo "i86pc"3else4 echo "SunOS dev 5.11 joyent_20150219T102159Z i86pc i386 i86pc Solaris"5fi
added:test/mocks/uname_smartos_x86+5 added
1if [ "_$1" = "_-m" ]; then2 echo "i86pc"3else4 echo "SunOS dev 5.11 joyent_20150219T102159Z i86pc i386 i86pc Solaris"5fi
added:test/common.sh+13 added
1assert_ok() {2 local FUNCTION=$13 shift45 $($FUNCTION $@) || die '"'"$FUNCTION $@"'" should have succeeded, but failed'6}78assert_not_ok() {9 local FUNCTION=$110 shift1112 ! $($FUNCTION $@) || die '"'"$FUNCTION $@"'" should have failed, but succeeded'13}
modified:nvm.sh+75 added-8 removed
907 unmodified lines
908 echo "$NVM_OS"909}910911nvm_get_arch() {912 local NVM_UNAME913 NVM_UNAME="$(uname -m)"912 local HOST_ARCH913 local NVM_OS914 local EXIT_CODE915916 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 fi930931 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 lines
1319 fi1320 fi1321}13221323# 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.1328iojs_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 fi13341335 # 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}13381339# 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.1343node_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 fi13501351 # 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}13571358# Succeeds if $VERSION represents a version (node, io.js or merged) that has a1359# Solaris binary, fails otherwise.1360nvm_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}13701371nvm() {1372 if [ $# -lt 1 ]; then1373 nvm help1374 return
174 unmodified lines
15491550 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"; then
633 unmodified lines