Skip to content

Fix #12318: Support options to repl #12370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions dist/bin/common
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,8 @@ JLINE_TERMINAL=$(find_lib "*jline-terminal-3*")
JLINE_TERMINAL_JNA=$(find_lib "*jline-terminal-jna-3*")
[[ ${conemu-} ]] || JNA=$(find_lib "*jna-5*")

# debug

DEBUG_STR=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005

classpathArgs () {
compilerJavaClasspathArgs () {
# echo "dotty-compiler: $DOTTY_COMP"
# echo "dotty-interface: $DOTTY_INTF"
# echo "dotty-library: $DOTTY_LIB"
Expand Down
22 changes: 9 additions & 13 deletions dist/bin/scala
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ while [[ $# -gt 0 ]]; do
addScala "$1"
shift
;;
-d|-debug)
DEBUG="${DEBUG_STR-}"
shift ;;
-version)
# defer to scalac, then exit
shift
Expand All @@ -116,8 +113,8 @@ while [[ $# -gt 0 ]]; do
verbose=true
addScala "-verbose"
shift ;;
-run|-repl)
PROG_NAME="$ReplMain"
-run)
setExecuteMode 'run'
shift ;;

*)
Expand Down Expand Up @@ -157,7 +154,7 @@ done
#[ -n "${dump_args}" ] && dumpArgs ; exit 2
if [ -z "${execute_mode-}" ]; then
# no script was specified, set run or repl mode
if [[ $options_indicator -eq 0 && "${residual_args[@]-}" == "" ]]; then
if [[ $options_indicator -eq 0 ]]; then
setExecuteMode 'repl'
else
setExecuteMode 'run'
Expand All @@ -179,15 +176,14 @@ script)
else
[[ $save_compiled == true ]] && rm -f $target_jar
PROG_NAME=$ScriptingMain
classpathArgs # initialize jvm_cp_args with toolchain classpath
compilerJavaClasspathArgs # initialize jvm_cp_args with toolchain classpath
scripting_string="-script $target_script ${script_args[@]}"
# use eval instead of exec, to insure that onExit is subsequently called

# $script_cp_arg must be the first argument to $ScriptingMain
# $scripting_string must be last
eval "\"$JAVACMD\"" \
${JAVA_OPTS:-$default_java_opts} \
"${DEBUG-}" \
"${java_args[@]}" \
"-classpath \"$jvm_cp_args\"" \
-Dscala.usejavacp=true \
Expand All @@ -210,20 +206,20 @@ repl)
;;

run)
repl_cparg="$DOTTY_LIB$PSEP$SCALA_LIB"
run_cparg="$DOTTY_LIB$PSEP$SCALA_LIB"
if [ -z "$CLASS_PATH" ]; then
repl_cparg+="$PSEP."
run_cparg+="$PSEP."
else
repl_cparg+="$PSEP$CLASS_PATH"
run_cparg+="$PSEP$CLASS_PATH"
fi
if [ "$class_path_count" -gt 1 ]; then
echo "warning: multiple classpaths are found, scala only use the last one."
fi
if [ $with_compiler == true ]; then
repl_cparg+="$PSEP$DOTTY_COMP$PSEP$TASTY_CORE$PSEP$DOTTY_INTF$PSEP$SCALA_ASM$PSEP$DOTTY_STAGING$PSEP$DOTTY_TASTY_INSPECTOR"
run_cparg+="$PSEP$DOTTY_COMP$PSEP$TASTY_CORE$PSEP$DOTTY_INTF$PSEP$SCALA_ASM$PSEP$DOTTY_STAGING$PSEP$DOTTY_TASTY_INSPECTOR"
fi
# exec here would prevent onExit from being called, leaving terminal in unusable state
eval "\"$JAVACMD\"" "${DEBUG-}" "-classpath \"$repl_cparg\"" "${java_args[@]}" "${residual_args[@]}"
eval "\"$JAVACMD\"" "-classpath \"$run_cparg\"" "${java_args[@]}" "${residual_args[@]}"
scala_exit_status=$?
;;

Expand Down
4 changes: 1 addition & 3 deletions dist/bin/scalac
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ while [[ $# -gt 0 ]]; do
case "$1" in
--) shift; for arg; do addResidual "$arg"; done; set -- ;;
-v|-verbose) verbose=true && addScala "-verbose" && shift ;;
-debug) DEBUG="$DEBUG_STR" && shift ;;
-q|-quiet) quiet=true && shift ;;

# Optimize for short-running applications, see https://github.com/lampepfl/dotty/issues/222
Expand All @@ -61,7 +60,7 @@ case "$1" in
esac
done

classpathArgs
compilerJavaClasspathArgs

if [ "$PROG_NAME" == "$ScriptingMain" ]; then
setScriptName="-Dscript.path=$target_script"
Expand All @@ -72,7 +71,6 @@ fi
[ -n "$script_trace" ] && set -x
eval "\"$JAVACMD\"" \
${JAVA_OPTS:-$default_java_opts} \
"${DEBUG-}" \
"${java_args[@]}" \
"-classpath \"$jvm_cp_args\"" \
-Dscala.usejavacp=true \
Expand Down
2 changes: 0 additions & 2 deletions dist/bin/scaladoc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ while [[ $# -gt 0 ]]; do
case "$1" in
--) shift; for arg; do addResidual "$arg"; done; set -- ;;
-v|-verbose) verbose=true && addScala "-verbose" && shift ;;
-debug) DEBUG="$DEBUG_STR" && shift ;;
-q|-quiet) quiet=true && shift ;;

-colors) colors=true && shift ;;
Expand All @@ -126,7 +125,6 @@ classpathArgs

eval "\"$JAVACMD\"" \
${JAVA_OPTS:-$default_java_opts} \
"${DEBUG-}" \
"${java_args[@]}" \
"${jvm_cp_args-}" \
"dotty.tools.scaladoc.Main" \
Expand Down
10 changes: 10 additions & 0 deletions project/scripts/bootstrapCmdTests
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,13 @@ clear_out "$OUT"

# check options specified in files
./bin/scalac @project/scripts/options "$SOURCE"

# test command line options
./bin/scalac -help > "$tmp" 2>&1
grep -qe "Usage: scalac <options> <source files>" "$tmp"

./bin/scala -help > "$tmp" 2>&1
grep -qe "Usage: scala <options> <source files>" "$tmp"

./bin/scala -d hello.jar tests/run/hello.scala
ls hello.jar