Skip to content

Commit

Permalink
improve platform detect
Browse files Browse the repository at this point in the history
  • Loading branch information
gzm55 committed Jan 10, 2023
1 parent ceff591 commit 6e4cad7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
13 changes: 6 additions & 7 deletions dist/src/main/distro/bin/mvnd
Original file line number Diff line number Diff line change
Expand Up @@ -94,32 +94,31 @@ fi

# force execute native image
if [ "${MVND_ENTRY_FALLBACK:-true}" = false ]; then
MVND_CMD=$(echo "$MVND_HOME"/bin/mvnd-native-*)
[ ! -x "$MVND_CMD" ] || exec "$MVND_CMD" "$@"
echo "Cannot run native mvnd '${MVND_CMD-}'!" >&2
exit 1
exec -- "$(echo "$MVND_HOME"/bin/mvnd-native-*)" "$@"
fi

case "$(uname -a)" in
(CYGWIN*|MINGW*) os=windows arch=$(uname -m) ;;
(CYGWIN*|MINGW*) os=windows arch="${PROCESSOR_ARCHITEW6432:-"${PROCESSOR_ARCHITECTURE:-"$(uname -m)"}"}" ;;
(Darwin*x86_64) os=darwin arch=amd64 ;;
(Darwin*arm64) os=darwin arch=aarch64 ;;
(Linux*) os=linux arch=$(uname -m) ;;
(*) os=$(uname) arch=$(uname -m) ;;
esac
[ "${arch-}" != x86_64 ] || arch=amd64
[ "${arch-}" != AMD64 ] || arch=amd64
[ "${arch-}" != arm64 ] || arch=aarch64

# try native image
MVND_CMD="$MVND_HOME/bin/mvnd-native-$os-$arch"
[ "${os-}" != windows ] || MVND_CMD="$MVND_CMD.exe"
if [ -x "$MVND_CMD" ]; then
is_native=true
if [ "$os" = linux ]; then
case "$(ldd "$MVND_CMD")" in
case "$(ldd "$MVND_CMD" 2>&1)" in
(''|*"not found"*) is_native=false ;;
esac
fi
! $is_native || exec "$MVND_CMD" "$@"
! $is_native || exec -- "$MVND_CMD" "$@"
fi

# fallback to pure java version
Expand Down
6 changes: 5 additions & 1 deletion dist/src/main/distro/bin/mvnd.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %*
set ERROR_CODE=0

@REM try execute native image
set "MVND_CMD=%~dp0\mvnd-native-windows-%PROCESSOR_ARCHITECTURE:x64=amd64%.exe"
if not "%PROCESSOR_ARCHITEW6432%"=="" (
set "MVND_CMD=%~dp0\mvnd-native-windows-%PROCESSOR_ARCHITEW6432:x64=amd64%.exe"
) else (
set "MVND_CMD=%~dp0\mvnd-native-windows-%PROCESSOR_ARCHITECTURE:x64=amd64%.exe"
)
if not exist "%MVND_CMD%" goto noNativeImage
"%MVND_CMD%" %*
if ERRORLEVEL 1 goto error
Expand Down

0 comments on commit 6e4cad7

Please sign in to comment.