From 67f12853729b40321889fe7e2fb234ac4eb9226f Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Fri, 7 May 2021 16:02:51 +0200 Subject: [PATCH 1/2] Fix #12318: Support options to repl --- dist/bin/common | 2 +- dist/bin/scala | 18 +++++++++--------- dist/bin/scalac | 2 +- project/scripts/bootstrapCmdTests | 7 +++++++ 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/dist/bin/common b/dist/bin/common index db30a383fadb..9909f8a1abec 100755 --- a/dist/bin/common +++ b/dist/bin/common @@ -165,7 +165,7 @@ JLINE_TERMINAL_JNA=$(find_lib "*jline-terminal-jna-3*") 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" diff --git a/dist/bin/scala b/dist/bin/scala index 20fe48b50752..ebc2ac16e683 100755 --- a/dist/bin/scala +++ b/dist/bin/scala @@ -116,8 +116,8 @@ while [[ $# -gt 0 ]]; do verbose=true addScala "-verbose" shift ;; - -run|-repl) - PROG_NAME="$ReplMain" + -run) + setExecuteMode 'run' shift ;; *) @@ -157,7 +157,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' @@ -179,7 +179,7 @@ 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 @@ -210,20 +210,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\"" "${DEBUG-}" "-classpath \"$run_cparg\"" "${java_args[@]}" "${residual_args[@]}" scala_exit_status=$? ;; diff --git a/dist/bin/scalac b/dist/bin/scalac index 9d36cdf11f8b..6463cd4f5ba4 100755 --- a/dist/bin/scalac +++ b/dist/bin/scalac @@ -61,7 +61,7 @@ case "$1" in esac done -classpathArgs +compilerJavaClasspathArgs if [ "$PROG_NAME" == "$ScriptingMain" ]; then setScriptName="-Dscript.path=$target_script" diff --git a/project/scripts/bootstrapCmdTests b/project/scripts/bootstrapCmdTests index 31b8368d5215..a904a5642620 100755 --- a/project/scripts/bootstrapCmdTests +++ b/project/scripts/bootstrapCmdTests @@ -67,3 +67,10 @@ 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 " "$tmp" + +./bin/scala -help > "$tmp" 2>&1 +grep -qe "Usage: scala " "$tmp" From 71c751e5cf2b283d98c5f2622445bd9e24eac9b7 Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Sun, 9 May 2021 22:03:18 +0200 Subject: [PATCH 2/2] Remove -d for debugging to be consistent and align with Scala 2 behavior --- dist/bin/common | 3 --- dist/bin/scala | 6 +----- dist/bin/scalac | 2 -- dist/bin/scaladoc | 2 -- project/scripts/bootstrapCmdTests | 3 +++ 5 files changed, 4 insertions(+), 12 deletions(-) diff --git a/dist/bin/common b/dist/bin/common index 9909f8a1abec..cb0908c97563 100755 --- a/dist/bin/common +++ b/dist/bin/common @@ -161,9 +161,6 @@ 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 compilerJavaClasspathArgs () { # echo "dotty-compiler: $DOTTY_COMP" diff --git a/dist/bin/scala b/dist/bin/scala index ebc2ac16e683..83e7720ef43d 100755 --- a/dist/bin/scala +++ b/dist/bin/scala @@ -98,9 +98,6 @@ while [[ $# -gt 0 ]]; do addScala "$1" shift ;; - -d|-debug) - DEBUG="${DEBUG_STR-}" - shift ;; -version) # defer to scalac, then exit shift @@ -187,7 +184,6 @@ script) # $scripting_string must be last eval "\"$JAVACMD\"" \ ${JAVA_OPTS:-$default_java_opts} \ - "${DEBUG-}" \ "${java_args[@]}" \ "-classpath \"$jvm_cp_args\"" \ -Dscala.usejavacp=true \ @@ -223,7 +219,7 @@ run) 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 \"$run_cparg\"" "${java_args[@]}" "${residual_args[@]}" + eval "\"$JAVACMD\"" "-classpath \"$run_cparg\"" "${java_args[@]}" "${residual_args[@]}" scala_exit_status=$? ;; diff --git a/dist/bin/scalac b/dist/bin/scalac index 6463cd4f5ba4..fa93c41293bd 100755 --- a/dist/bin/scalac +++ b/dist/bin/scalac @@ -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 @@ -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 \ diff --git a/dist/bin/scaladoc b/dist/bin/scaladoc index d83ce5e09595..e92e21d6e49a 100755 --- a/dist/bin/scaladoc +++ b/dist/bin/scaladoc @@ -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 ;; @@ -126,7 +125,6 @@ classpathArgs eval "\"$JAVACMD\"" \ ${JAVA_OPTS:-$default_java_opts} \ - "${DEBUG-}" \ "${java_args[@]}" \ "${jvm_cp_args-}" \ "dotty.tools.scaladoc.Main" \ diff --git a/project/scripts/bootstrapCmdTests b/project/scripts/bootstrapCmdTests index a904a5642620..af1ffef87a33 100755 --- a/project/scripts/bootstrapCmdTests +++ b/project/scripts/bootstrapCmdTests @@ -74,3 +74,6 @@ grep -qe "Usage: scalac " "$tmp" ./bin/scala -help > "$tmp" 2>&1 grep -qe "Usage: scala " "$tmp" + +./bin/scala -d hello.jar tests/run/hello.scala +ls hello.jar