mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-04-03 11:34:50 +08:00
[Fix] nvm_get_arch: only apply musl suffix on x64 Alpine
Alpine detection unconditionally set `x64-musl` regardless of actual architecture, which would be incorrect on ARM-based Alpine containers.
Bug introduced in ef7fc2f2c0 / #3212.
Fixes #3616.
This commit is contained in:
5
nvm.sh
5
nvm.sh
@@ -2171,7 +2171,10 @@ nvm_get_arch() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f "/etc/alpine-release" ]; then
|
if [ -f "/etc/alpine-release" ]; then
|
||||||
NVM_ARCH=x64-musl
|
# Alpine Linux uses musl libc; only x64-musl binaries are available
|
||||||
|
case "${NVM_ARCH}" in
|
||||||
|
x64) NVM_ARCH=x64-musl ;;
|
||||||
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
nvm_echo "${NVM_ARCH}"
|
nvm_echo "${NVM_ARCH}"
|
||||||
|
|||||||
48
test/fast/Unit tests/nvm_get_arch alpine
Executable file
48
test/fast/Unit tests/nvm_get_arch alpine
Executable file
@@ -0,0 +1,48 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
ORIG_PATH="${PATH}"
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
rm -f ./uname
|
||||||
|
export PATH="${ORIG_PATH}"
|
||||||
|
}
|
||||||
|
|
||||||
|
die () { cleanup; echo "$@" ; exit 1; }
|
||||||
|
|
||||||
|
: nvm.sh
|
||||||
|
\. ../../../nvm.sh
|
||||||
|
|
||||||
|
MOCKS_DIR="$(pwd)/../../mocks"
|
||||||
|
export PATH=".:${PATH}"
|
||||||
|
|
||||||
|
# On Alpine (where /etc/alpine-release exists), x64 should get -musl suffix
|
||||||
|
# and arm64 should NOT get -musl suffix.
|
||||||
|
# On non-Alpine, neither should get -musl.
|
||||||
|
|
||||||
|
if [ -f "/etc/alpine-release" ]; then
|
||||||
|
# x64 on Alpine should produce x64-musl
|
||||||
|
ln -sf "${MOCKS_DIR}/uname_linux_x86_64" ./uname
|
||||||
|
OUTPUT="$(nvm_get_arch)"
|
||||||
|
rm -f ./uname
|
||||||
|
[ "_${OUTPUT}" = "_x64-musl" ] || die "x64 on Alpine should be x64-musl, got ${OUTPUT}"
|
||||||
|
|
||||||
|
# aarch64 on Alpine should produce arm64, NOT arm64-musl
|
||||||
|
ln -sf "${MOCKS_DIR}/uname_linux_aarch64" ./uname
|
||||||
|
OUTPUT="$(nvm_get_arch)"
|
||||||
|
rm -f ./uname
|
||||||
|
[ "_${OUTPUT}" = "_arm64" ] || die "aarch64 on Alpine should be arm64 (no musl suffix), got ${OUTPUT}"
|
||||||
|
else
|
||||||
|
# x64 on non-Alpine should produce x64 (no musl suffix)
|
||||||
|
ln -sf "${MOCKS_DIR}/uname_linux_x86_64" ./uname
|
||||||
|
OUTPUT="$(nvm_get_arch)"
|
||||||
|
rm -f ./uname
|
||||||
|
[ "_${OUTPUT}" = "_x64" ] || die "x64 on non-Alpine should be x64, got ${OUTPUT}"
|
||||||
|
|
||||||
|
# aarch64 on non-Alpine should produce arm64
|
||||||
|
ln -sf "${MOCKS_DIR}/uname_linux_aarch64" ./uname
|
||||||
|
OUTPUT="$(nvm_get_arch)"
|
||||||
|
rm -f ./uname
|
||||||
|
[ "_${OUTPUT}" = "_arm64" ] || die "aarch64 on non-Alpine should be arm64, got ${OUTPUT}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cleanup
|
||||||
5
test/mocks/uname_linux_aarch64
Executable file
5
test/mocks/uname_linux_aarch64
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
if [ "_$1" = "_-m" ]; then
|
||||||
|
echo "aarch64"
|
||||||
|
else
|
||||||
|
echo "Linux hostname 5.15.0-1 #1 SMP aarch64 aarch64 aarch64 GNU/Linux"
|
||||||
|
fi
|
||||||
5
test/mocks/uname_linux_x86_64
Executable file
5
test/mocks/uname_linux_x86_64
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
if [ "_$1" = "_-m" ]; then
|
||||||
|
echo "x86_64"
|
||||||
|
else
|
||||||
|
echo "Linux hostname 5.15.0-1 #1 SMP x86_64 x86_64 x86_64 GNU/Linux"
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user