Skip to content

Commit 63090b7

Browse files
committed
step 1: basic script that forwards to prebuilt launcher and overrides default scala-version
1 parent 40050c3 commit 63090b7

File tree

3 files changed

+116
-38
lines changed

3 files changed

+116
-38
lines changed

dist/bin/cli-common

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
SCALA_CLI_LAUNCHER="/Users/jamie/workspace/scala-cli/out/cli/3.3.3/launcher.dest/launcher"
4+
5+
#/*--------------------------------------------------------------------------
6+
# * Credits: This script is based on the script generated by sbt-pack.
7+
# *--------------------------------------------------------------------------*/
8+
9+
# save terminal settings
10+
saved_stty=$(stty -g 2>/dev/null)
11+
# clear on error so we don't later try to restore them
12+
if [[ ! $? ]]; then
13+
saved_stty=""
14+
fi
15+
16+
# restore stty settings (echo in particular)
17+
function restoreSttySettings() {
18+
stty $saved_stty
19+
saved_stty=""
20+
}
21+
22+
scala_exit_status=127
23+
function onExit() {
24+
[[ "$saved_stty" != "" ]] && restoreSttySettings
25+
exit $scala_exit_status
26+
}

dist/bin/scala

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -26,47 +26,27 @@ if [ -z "${PROG_HOME-}" ] ; then
2626
cd "$saveddir"
2727
fi
2828

29-
source "$PROG_HOME/bin/common"
30-
31-
while [[ $# -gt 0 ]]; do
32-
case "$1" in
33-
-D*)
34-
# pass to scala as well: otherwise we lose it sometimes when we
35-
# need it, e.g. communicating with a server compiler.
36-
# respect user-supplied -Dscala.usejavacp
37-
addJava "$1"
38-
addScala "$1"
39-
shift
40-
;;
41-
-J*)
42-
# as with -D, pass to scala even though it will almost
43-
# never be used.
44-
addJava "${1:2}"
45-
addScala "$1"
46-
shift
47-
;;
48-
-classpath*)
49-
if [ "$1" != "${1##* }" ]; then
50-
# -classpath and its value have been supplied in a single string e.g. "-classpath 'lib/*'"
51-
A=$1 ; shift # consume $1 before adding its substrings back
52-
set -- $A "$@" # split $1 on whitespace and put it back
53-
else
54-
addScala "$1"
55-
shift
56-
fi
57-
;;
58-
*)
59-
addScala "$1"
60-
shift
61-
;;
62-
esac
63-
done
29+
source "$PROG_HOME/bin/cli-common"
30+
31+
SCALA_VERSION=""
32+
# iterate through lines in VERSION_SRC
33+
while IFS= read -r line; do
34+
# if line starts with "version:=" then extract the version
35+
if [[ "$line" == version:=* ]]; then
36+
SCALA_VERSION="${line#version:=}"
37+
break
38+
fi
39+
done < "$PROG_HOME/VERSION"
40+
41+
# assert that SCALA_VERSION is not empty
42+
if [ -z "$SCALA_VERSION" ]; then
43+
echo "Failed to extract Scala version from $PROG_HOME/VERSION"
44+
exit 1
45+
fi
6446

6547
# exec here would prevent onExit from being called, leaving terminal in unusable state
66-
compilerJavaClasspathArgs
6748
[ -z "${ConEmuPID-}" -o -n "${cygwin-}" ] && export MSYSTEM= PWD= # workaround for #12405
68-
eval "\"$JAVACMD\"" "${java_args[@]}" "-Dscala.home=\"$PROG_HOME\"" "-classpath \"$jvm_cp_args\"" "dotty.tools.MainGenericRunner" "-classpath \"$jvm_cp_args\"" "${scala_args[@]}"
49+
eval "\"$SCALA_CLI_LAUNCHER\"" "--cli-default-scala-version \"$SCALA_VERSION\"" "$@"
6950
scala_exit_status=$?
7051

71-
7252
onExit

dist/bin/scala_legacy

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env bash
2+
3+
# Try to autodetect real location of the script
4+
if [ -z "${PROG_HOME-}" ] ; then
5+
## resolve links - $0 may be a link to PROG_HOME
6+
PRG="$0"
7+
8+
# need this for relative symlinks
9+
while [ -h "$PRG" ] ; do
10+
ls=`ls -ld "$PRG"`
11+
link=`expr "$ls" : '.*-> \(.*\)$'`
12+
if expr "$link" : '/.*' > /dev/null; then
13+
PRG="$link"
14+
else
15+
PRG="`dirname "$PRG"`/$link"
16+
fi
17+
done
18+
19+
saveddir=`pwd`
20+
21+
PROG_HOME=`dirname "$PRG"`/..
22+
23+
# make it fully qualified
24+
PROG_HOME=`cd "$PROG_HOME" && pwd`
25+
26+
cd "$saveddir"
27+
fi
28+
29+
source "$PROG_HOME/bin/common"
30+
31+
while [[ $# -gt 0 ]]; do
32+
case "$1" in
33+
-D*)
34+
# pass to scala as well: otherwise we lose it sometimes when we
35+
# need it, e.g. communicating with a server compiler.
36+
# respect user-supplied -Dscala.usejavacp
37+
addJava "$1"
38+
addScala "$1"
39+
shift
40+
;;
41+
-J*)
42+
# as with -D, pass to scala even though it will almost
43+
# never be used.
44+
addJava "${1:2}"
45+
addScala "$1"
46+
shift
47+
;;
48+
-classpath*)
49+
if [ "$1" != "${1##* }" ]; then
50+
# -classpath and its value have been supplied in a single string e.g. "-classpath 'lib/*'"
51+
A=$1 ; shift # consume $1 before adding its substrings back
52+
set -- $A "$@" # split $1 on whitespace and put it back
53+
else
54+
addScala "$1"
55+
shift
56+
fi
57+
;;
58+
*)
59+
addScala "$1"
60+
shift
61+
;;
62+
esac
63+
done
64+
65+
# exec here would prevent onExit from being called, leaving terminal in unusable state
66+
compilerJavaClasspathArgs
67+
[ -z "${ConEmuPID-}" -o -n "${cygwin-}" ] && export MSYSTEM= PWD= # workaround for #12405
68+
eval "\"$JAVACMD\"" "${java_args[@]}" "-Dscala.home=\"$PROG_HOME\"" "-classpath \"$jvm_cp_args\"" "dotty.tools.MainGenericRunner" "-classpath \"$jvm_cp_args\"" "${scala_args[@]}"
69+
scala_exit_status=$?
70+
71+
72+
onExit

0 commit comments

Comments
 (0)