Skip to content

Commit a0db9c7

Browse files
committed
use scala-cli jar launcher (TODO: download automatically)
1 parent 03ebfd9 commit a0db9c7

File tree

2 files changed

+132
-3
lines changed

2 files changed

+132
-3
lines changed

dist/bin/cli-common

Lines changed: 130 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/usr/bin/env bash
22

3-
SCALA_CLI_LAUNCHER="/Users/jamie/workspace/scala-cli/out/cli/3.3.3/launcher.dest/launcher"
4-
53
#/*--------------------------------------------------------------------------
64
# * Credits: This script is based on the script generated by sbt-pack.
75
# *--------------------------------------------------------------------------*/
@@ -25,6 +23,136 @@ function onExit() {
2523
exit $scala_exit_status
2624
}
2725

26+
#/*--------------------------------------------------------------------------
27+
# * SECTION FOR JAVA COMMAND
28+
# *--------------------------------------------------------------------------*/
29+
30+
# to reenable echo if we are interrupted before completing.
31+
trap onExit INT TERM EXIT
32+
33+
unset cygwin mingw msys darwin conemu
34+
35+
# COLUMNS is used together with command line option '-pageWidth'.
36+
if command -v tput >/dev/null 2>&1; then
37+
export COLUMNS="$(tput -Tdumb cols)"
38+
fi
39+
40+
case "`uname`" in
41+
CYGWIN*) cygwin=true
42+
;;
43+
MINGW*) mingw=true
44+
;;
45+
MSYS*) msys=true
46+
;;
47+
Darwin*) darwin=true
48+
if [ -z "$JAVA_VERSION" ] ; then
49+
JAVA_VERSION="CurrentJDK"
50+
else
51+
echo "Using Java version: $JAVA_VERSION" 1>&2
52+
fi
53+
if [ -z "$JAVA_HOME" ] ; then
54+
JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/${JAVA_VERSION}/Home
55+
fi
56+
JAVACMD="`which java`"
57+
;;
58+
esac
59+
60+
unset CYGPATHCMD
61+
if [[ ${cygwin-} || ${mingw-} || ${msys-} ]]; then
62+
# ConEmu terminal is incompatible with jna-5.*.jar
63+
[[ (${CONEMUANSI-} || ${ConEmuANSI-}) ]] && conemu=true
64+
# cygpath is used by various windows shells: cygwin, git-sdk, gitbash, msys, etc.
65+
CYGPATHCMD=`which cygpath 2>/dev/null`
66+
case "$TERM" in
67+
rxvt* | xterm* | cygwin*)
68+
stty -icanon min 1 -echo
69+
JAVA_OPTS="$JAVA_OPTS -Djline.terminal=unix"
70+
;;
71+
esac
72+
fi
73+
74+
# Resolve JAVA_HOME from javac command path
75+
if [ -z "$JAVA_HOME" ]; then
76+
javaExecutable="`which javac`"
77+
if [ -n "$javaExecutable" -a -f "$javaExecutable" -a ! "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
78+
# readlink(1) is not available as standard on Solaris 10.
79+
readLink=`which readlink`
80+
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
81+
javaExecutable="`readlink -f \"$javaExecutable\"`"
82+
javaHome="`dirname \"$javaExecutable\"`"
83+
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
84+
JAVA_HOME="$javaHome"
85+
export JAVA_HOME
86+
fi
87+
fi
88+
fi
89+
90+
if [ -z "${JAVACMD-}" ] ; then
91+
if [ -n "${JAVA_HOME-}" ] ; then
92+
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
93+
# IBM's JDK on AIX uses strange locations for the executables
94+
JAVACMD="$JAVA_HOME/jre/sh/java"
95+
else
96+
JAVACMD="$JAVA_HOME/bin/java"
97+
fi
98+
else
99+
JAVACMD="`which java`"
100+
fi
101+
fi
102+
103+
if [ ! -x "$JAVACMD" ] ; then
104+
echo "Error: JAVA_HOME is not defined correctly."
105+
echo " We cannot execute $JAVACMD"
106+
exit 1
107+
fi
108+
109+
if [ -z "$JAVA_HOME" ] ; then
110+
echo "Warning: JAVA_HOME environment variable is not set."
111+
fi
112+
113+
CLASSPATH_SUFFIX=""
114+
# Path separator used in EXTRA_CLASSPATH
115+
PSEP=":"
116+
117+
# translate paths to Windows-mixed format before running java
118+
if [ -n "${CYGPATHCMD-}" ]; then
119+
[ -n "${PROG_HOME-}" ] &&
120+
PROG_HOME=`"$CYGPATHCMD" -am "$PROG_HOME"`
121+
[ -n "$JAVA_HOME" ] &&
122+
JAVA_HOME=`"$CYGPATHCMD" -am "$JAVA_HOME"`
123+
CLASSPATH_SUFFIX=";"
124+
PSEP=";"
125+
elif [[ ${mingw-} || ${msys-} ]]; then
126+
# For Mingw / Msys, convert paths from UNIX format before anything is touched
127+
[ -n "$PROG_HOME" ] &&
128+
PROG_HOME="`(cd "$PROG_HOME"; pwd -W | sed 's|/|\\\\|g')`"
129+
[ -n "$JAVA_HOME" ] &&
130+
JAVA_HOME="`(cd "$JAVA_HOME"; pwd -W | sed 's|/|\\\\|g')`"
131+
CLASSPATH_SUFFIX=";"
132+
PSEP=";"
133+
fi
134+
135+
#/*--------------------------------------------------
136+
# * The code below is for Dotty
137+
# *-------------------------------------------------*/
138+
139+
find_lib () {
140+
for lib in "$PROG_HOME"/lib/$1 ; do
141+
if [[ -f "$lib" ]]; then
142+
if [ -n "$CYGPATHCMD" ]; then
143+
"$CYGPATHCMD" -am "$lib"
144+
elif [[ $mingw || $msys ]]; then
145+
echo "$lib" | sed 's|/|\\\\|g'
146+
else
147+
echo "$lib"
148+
fi
149+
return
150+
fi
151+
done
152+
}
153+
154+
SCALA_CLI_JAR=$(find_lib "*scala-cli*")
155+
28156
declare -a scala_args
29157

30158
addScala () {

dist/bin/scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ done
5454

5555
# exec here would prevent onExit from being called, leaving terminal in unusable state
5656
[ -z "${ConEmuPID-}" -o -n "${cygwin-}" ] && export MSYSTEM= PWD= # workaround for #12405
57-
eval "\"$SCALA_CLI_LAUNCHER\"" \
57+
eval "\"$JAVACMD\"" \
58+
"-jar \"$SCALA_CLI_JAR\"" \
5859
"--cli-default-scala-version \"$SCALA_VERSION\"" \
5960
"-r \"$MVN_REPOSITORY\"" \
6061
"${scala_args[@]}"

0 commit comments

Comments
 (0)