From 1a9ba3a2cd555bd73b92148326e1a62d18ccb1f6 Mon Sep 17 00:00:00 2001 From: noti0na1 Date: Mon, 24 Feb 2025 19:37:29 +0100 Subject: [PATCH 1/5] Add REPL flag to quit after evaluating init script --- bin/replQ | 6 + .../tools/dotc/config/ScalaSettings.scala | 1 + .../src/dotty/tools/repl/ReplDriver.scala | 4 +- .../tools/scripting/BashExitCodeTests.scala | 5 +- .../dotty/tools/scripting/ScriptTestEnv.scala | 5 +- dist/bin/repl | 88 ++++++++++++++ dist/bin/repl.bat | 110 ++++++++++++++++++ 7 files changed, 215 insertions(+), 4 deletions(-) create mode 100755 bin/replQ create mode 100755 dist/bin/repl create mode 100644 dist/bin/repl.bat diff --git a/bin/replQ b/bin/replQ new file mode 100755 index 000000000000..5d0b84c4a229 --- /dev/null +++ b/bin/replQ @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >& /dev/null && pwd)/.." +. $ROOT/bin/commonQ + +java -Dscala.usejavacp=true -cp $cp dotty.tools.repl.Main -usejavacp "$@" diff --git a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala index 986e3f3b9c26..83c9d803dc99 100644 --- a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -128,6 +128,7 @@ trait CommonScalaSettings: val usejavacp: Setting[Boolean] = BooleanSetting(RootSetting, "usejavacp", "Utilize the java.class.path in classpath resolution.", aliases = List("--use-java-class-path")) val scalajs: Setting[Boolean] = BooleanSetting(RootSetting, "scalajs", "Compile in Scala.js mode (requires scalajs-library.jar on the classpath).", aliases = List("--scalajs")) val replInitScript: Setting[String] = StringSetting(RootSetting, "repl-init-script", "code", "The code will be run on REPL startup.", "", aliases = List("--repl-init-script")) + val replEvalOnly: Setting[Boolean] = BooleanSetting(RootSetting, "repl-eval", "Quit REPL after evaluating the init script.", aliases = List("--repl-eval")) end CommonScalaSettings /** -P "plugin" settings. Various tools might support plugins. */ diff --git a/compiler/src/dotty/tools/repl/ReplDriver.scala b/compiler/src/dotty/tools/repl/ReplDriver.scala index 0f2921fd736c..c284a9c00560 100644 --- a/compiler/src/dotty/tools/repl/ReplDriver.scala +++ b/compiler/src/dotty/tools/repl/ReplDriver.scala @@ -153,7 +153,9 @@ class ReplDriver(settings: Array[String], * * Possible reason for unsuccessful run are raised flags in CLI like --help or --version */ - final def tryRunning = if shouldStart then runUntilQuit() + final def tryRunning = if shouldStart then + if rootCtx.settings.replEvalOnly.value(using rootCtx) then initialState + else runUntilQuit() /** Run REPL with `state` until `:quit` command found * diff --git a/compiler/test/dotty/tools/scripting/BashExitCodeTests.scala b/compiler/test/dotty/tools/scripting/BashExitCodeTests.scala index 857f5ef378e7..412e03b13c61 100644 --- a/compiler/test/dotty/tools/scripting/BashExitCodeTests.scala +++ b/compiler/test/dotty/tools/scripting/BashExitCodeTests.scala @@ -32,10 +32,11 @@ class BashExitCodeTests: s"expected $expectedExitCode but got $exitCode${pp("out", stdout)}${pp("err", stderr)}" }, expectedExitCode, exitCode) - // Helpers for running scala, scalac, and scalac without the output directory ("raw") + // Helpers for running scala, scalac, scalac, and repl without the output directory ("raw") def scala(args: String*) = verifyExit(scalaPath, ("--power" +: args :+ "--offline" :+ "--server=false")*) def scalacRaw(args: String*) = verifyExit(scalacPath, args*) def scalac(args: String*) = scalacRaw(("-d" +: tmpDir +: args)*) + def repl(args: String*) = verifyExit(replPath, args*) /** The path to the test file for this class. */ def f(body: String, suffix: String = ".scala"): String = @@ -72,6 +73,8 @@ class BashExitCodeTests: @Test def xPluginList = scala("-Xplugin-list")(0) @Test def vPhases = scala("-Vphases")(0) + @Test def replEval = repl("--repl-eval", "--repl-init-script", "\'println(\"Hello from init script!\"); val i = 2 * 2\'")(0) + /** A utility for running two commands in a row, like you do in bash. */ extension (inline u1: Unit) inline def & (inline u2: Unit): Unit = { u1; u2 } end BashExitCodeTests diff --git a/compiler/test/dotty/tools/scripting/ScriptTestEnv.scala b/compiler/test/dotty/tools/scripting/ScriptTestEnv.scala index 771c3ba14af0..c565354cdc1f 100644 --- a/compiler/test/dotty/tools/scripting/ScriptTestEnv.scala +++ b/compiler/test/dotty/tools/scripting/ScriptTestEnv.scala @@ -292,10 +292,11 @@ object ScriptTestEnv { lazy val cwd: Path = Paths.get(".").toAbsolutePath.normalize - lazy val (scalacPath: String, scalaPath: String) = { + lazy val (scalacPath: String, scalaPath: String, replPath: String) = { val scalac = s"$workingDirectory/$packBinDir/scalac".toPath.normalize val scala = s"$workingDirectory/$packBinDir/scala".toPath.normalize - (scalac.norm, scala.norm) + val repl = s"$workingDirectory/$packBinDir/repl".toPath.normalize + (scalac.norm, scala.norm, repl.norm) } diff --git a/dist/bin/repl b/dist/bin/repl new file mode 100755 index 000000000000..e8f0f1bae93f --- /dev/null +++ b/dist/bin/repl @@ -0,0 +1,88 @@ +#!/usr/bin/env bash + +#set -o nounset ; set -o errexit + +# Try to autodetect real location of the script +if [ -z "${PROG_HOME-}" ] ; then + ## resolve links - $0 may be a link to PROG_HOME + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + PROG_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + PROG_HOME=`cd "$PROG_HOME" && pwd` + + cd "$saveddir" +fi + +source "$PROG_HOME/libexec/common" +default_java_opts="-Xmx768m -Xms768m" +withCompiler=true + +CompilerMain=dotty.tools.dotc.Main +DecompilerMain=dotty.tools.dotc.decompiler.Main +ReplMain=dotty.tools.repl.Main +ScriptingMain=dotty.tools.scripting.Main +JVM_CP_ARGS="$PROG_HOME/lib/scaladoc.jar" + +PROG_NAME=$CompilerMain + +addJava () { + java_args+=("'$1'") +} +addScala () { + scala_args+=("'$1'") +} +addResidual () { + residual_args+=("'$1'") +} +addScrip() { + script_args+=("'$1'") +} + +#for A in "$@" ; do echo "A[$A]" ; done ; exit 2 + +while [[ $# -gt 0 ]]; do +case "$1" in + --) shift; for arg; do addResidual "$arg"; done; set -- ;; + -v|-verbose) verbose=true && addScala "-verbose" && shift ;; + -q|-quiet) quiet=true && shift ;; + + -colors) colors=true && shift ;; + -no-colors) unset colors && shift ;; + # break out -D and -J options and add them to java_args so + # they reach the JVM in time to do some good. The -D options + # will be available as system properties. + -D*) addJava "$1" && shift ;; + -J*) addJava "${1:2}" && shift ;; + *) addResidual "$1" + shift + ;; + esac +done + +eval "\"$JAVACMD\"" \ + ${JAVA_OPTS:-$default_java_opts} \ + "${java_args[@]}" \ + -classpath "${JVM_CP_ARGS}" \ + -Dscala.expandjavacp=true \ + -Dscala.usejavacp=true \ + "dotty.tools.repl.Main" \ + "${scala_args[@]}" \ + "${residual_args[@]}" \ + "${scripting_string-}" +scala_exit_status=$? +onExit diff --git a/dist/bin/repl.bat b/dist/bin/repl.bat new file mode 100644 index 000000000000..5d710850c5ff --- /dev/null +++ b/dist/bin/repl.bat @@ -0,0 +1,110 @@ +@echo off +setlocal enabledelayedexpansion + +@rem ######################################################################### +@rem ## Environment setup + +set _EXITCODE=0 + +for %%f in ("%~dp0.") do ( + set "_PROG_HOME=%%~dpf" + @rem get rid of the trailing slash + set "_PROG_HOME=!_PROG_HOME:~0,-1!" +) +call "%_PROG_HOME%\libexec\common.bat" +if not %_EXITCODE%==0 goto end + +set _DEFAULT_JAVA_OPTS=-Xmx768m -Xms768m + +call :args %* + +@rem ######################################################################### +@rem ## Main + +if defined JAVA_OPTS ( set _JAVA_OPTS=%JAVA_OPTS% +) else ( set _JAVA_OPTS=%_DEFAULT_JAVA_OPTS% +) + +@rem we need to escape % in the java command path, for some reason this doesnt work in common.bat +set "_JAVACMD=!_JAVACMD:%%=%%%%!" + +call "%_JAVACMD%" %_JAVA_OPTS% %_JAVA_DEBUG% %_JAVA_ARGS% ^ +-classpath "%_LIB_DIR%\scaladoc.jar" ^ +-Dscala.expandjavacp=true ^ +-Dscala.usejavacp=true ^ +dotty.tools.repl.Main %_SCALA_ARGS% %_RESIDUAL_ARGS% +if not %ERRORLEVEL%==0 ( + @rem echo Error: Scaladoc execution failed 1>&2 + set _EXITCODE=1 + goto end +) +goto end + +@rem ######################################################################### +@rem ## Subroutines + +:args +set _JAVA_DEBUG= +set _HELP= +set _VERBOSE= +set _QUIET= +set _COLORS= +set _SCALA_ARGS= +set _JAVA_ARGS= +set _RESIDUAL_ARGS= + +:args_loop +if "%~1"=="" goto args_done +set "__ARG=%~1" +if "%__ARG%"=="--" ( + @rem for arg; do addResidual "$arg"; done; set -- ;; +) else if "%__ARG%"=="-h" ( + set _HELP=true + call :addScala "-help" +) else if "%__ARG%"=="-help" ( + set _HELP=true + call :addScala "-help" +) else if "%__ARG%"=="-v" ( + set _VERBOSE=true + call :addScala "-verbose" +) else if "%__ARG%"=="-verbose" ( + set _VERBOSE=true + call :addScala "-verbose" +) else if "%__ARG%"=="-debug" ( set "_JAVA_DEBUG=%_DEBUG_STR%" +) else if "%__ARG%"=="-q" ( set _QUIET=true +) else if "%__ARG%"=="-quiet" ( set _QUIET=true +) else if "%__ARG%"=="-colors" ( set _COLORS=true +) else if "%__ARG%"=="-no-colors" ( set _COLORS= +) else if "%__ARG:~0,2%"=="-D" ( call :addJava "%__ARG%" +) else if "%__ARG:~0,2%"=="-J" ( call :addJava "%__ARG:~2%" +) else ( + if defined _IN_SCRIPTING_ARGS ( call :addScripting "%__ARG%" + ) else ( call :addResidual "%__ARG%" + ) +) +shift +goto args_loop +:args_done +goto :eof + +@rem output parameter: _SCALA_ARGS +:addScala +set _SCALA_ARGS=%_SCALA_ARGS% %~1 +goto :eof + +@rem output parameter: _JAVA_ARGS +:addJava +set _JAVA_ARGS=%_JAVA_ARGS% %~1 +goto :eof + +@rem output parameter: _RESIDUAL_ARGS +:addResidual +set _RESIDUAL_ARGS=%_RESIDUAL_ARGS% %~1 +goto :eof + +@rem ######################################################################### +@rem ## Cleanups + +:end +exit /b %_EXITCODE% +endlocal From 28c877f74b919348f6d715ff01570aee8ee89822 Mon Sep 17 00:00:00 2001 From: noti0na1 Date: Wed, 26 Feb 2025 13:49:42 +0100 Subject: [PATCH 2/5] Remove repl bin; rename flag --- .../tools/dotc/config/ScalaSettings.scala | 2 +- .../tools/scripting/BashExitCodeTests.scala | 4 +- .../dotty/tools/scripting/ScriptTestEnv.scala | 5 +- dist/bin/repl | 88 -------------- dist/bin/repl.bat | 110 ------------------ 5 files changed, 5 insertions(+), 204 deletions(-) delete mode 100755 dist/bin/repl delete mode 100644 dist/bin/repl.bat diff --git a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala index 83c9d803dc99..bdbd0e8665b8 100644 --- a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -128,7 +128,7 @@ trait CommonScalaSettings: val usejavacp: Setting[Boolean] = BooleanSetting(RootSetting, "usejavacp", "Utilize the java.class.path in classpath resolution.", aliases = List("--use-java-class-path")) val scalajs: Setting[Boolean] = BooleanSetting(RootSetting, "scalajs", "Compile in Scala.js mode (requires scalajs-library.jar on the classpath).", aliases = List("--scalajs")) val replInitScript: Setting[String] = StringSetting(RootSetting, "repl-init-script", "code", "The code will be run on REPL startup.", "", aliases = List("--repl-init-script")) - val replEvalOnly: Setting[Boolean] = BooleanSetting(RootSetting, "repl-eval", "Quit REPL after evaluating the init script.", aliases = List("--repl-eval")) + val replEvalOnly: Setting[Boolean] = BooleanSetting(RootSetting, "repl-quit-after-init", "Quit REPL after evaluating the init script.", aliases = List("--repl-quit-after-init")) end CommonScalaSettings /** -P "plugin" settings. Various tools might support plugins. */ diff --git a/compiler/test/dotty/tools/scripting/BashExitCodeTests.scala b/compiler/test/dotty/tools/scripting/BashExitCodeTests.scala index 412e03b13c61..1aaa1c418db8 100644 --- a/compiler/test/dotty/tools/scripting/BashExitCodeTests.scala +++ b/compiler/test/dotty/tools/scripting/BashExitCodeTests.scala @@ -36,7 +36,7 @@ class BashExitCodeTests: def scala(args: String*) = verifyExit(scalaPath, ("--power" +: args :+ "--offline" :+ "--server=false")*) def scalacRaw(args: String*) = verifyExit(scalacPath, args*) def scalac(args: String*) = scalacRaw(("-d" +: tmpDir +: args)*) - def repl(args: String*) = verifyExit(replPath, args*) + def repl(args: String*) = verifyExit(scalaPath, "--power", "repl", "--offline", "--", args*) /** The path to the test file for this class. */ def f(body: String, suffix: String = ".scala"): String = @@ -73,7 +73,7 @@ class BashExitCodeTests: @Test def xPluginList = scala("-Xplugin-list")(0) @Test def vPhases = scala("-Vphases")(0) - @Test def replEval = repl("--repl-eval", "--repl-init-script", "\'println(\"Hello from init script!\"); val i = 2 * 2\'")(0) + @Test def replEval = repl("--repl-quit-after-init", "--repl-init-script", "\'println(\"Hello from init script!\"); val i = 2 * 2\'")(0) /** A utility for running two commands in a row, like you do in bash. */ extension (inline u1: Unit) inline def & (inline u2: Unit): Unit = { u1; u2 } diff --git a/compiler/test/dotty/tools/scripting/ScriptTestEnv.scala b/compiler/test/dotty/tools/scripting/ScriptTestEnv.scala index c565354cdc1f..771c3ba14af0 100644 --- a/compiler/test/dotty/tools/scripting/ScriptTestEnv.scala +++ b/compiler/test/dotty/tools/scripting/ScriptTestEnv.scala @@ -292,11 +292,10 @@ object ScriptTestEnv { lazy val cwd: Path = Paths.get(".").toAbsolutePath.normalize - lazy val (scalacPath: String, scalaPath: String, replPath: String) = { + lazy val (scalacPath: String, scalaPath: String) = { val scalac = s"$workingDirectory/$packBinDir/scalac".toPath.normalize val scala = s"$workingDirectory/$packBinDir/scala".toPath.normalize - val repl = s"$workingDirectory/$packBinDir/repl".toPath.normalize - (scalac.norm, scala.norm, repl.norm) + (scalac.norm, scala.norm) } diff --git a/dist/bin/repl b/dist/bin/repl deleted file mode 100755 index e8f0f1bae93f..000000000000 --- a/dist/bin/repl +++ /dev/null @@ -1,88 +0,0 @@ -#!/usr/bin/env bash - -#set -o nounset ; set -o errexit - -# Try to autodetect real location of the script -if [ -z "${PROG_HOME-}" ] ; then - ## resolve links - $0 may be a link to PROG_HOME - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - PROG_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - PROG_HOME=`cd "$PROG_HOME" && pwd` - - cd "$saveddir" -fi - -source "$PROG_HOME/libexec/common" -default_java_opts="-Xmx768m -Xms768m" -withCompiler=true - -CompilerMain=dotty.tools.dotc.Main -DecompilerMain=dotty.tools.dotc.decompiler.Main -ReplMain=dotty.tools.repl.Main -ScriptingMain=dotty.tools.scripting.Main -JVM_CP_ARGS="$PROG_HOME/lib/scaladoc.jar" - -PROG_NAME=$CompilerMain - -addJava () { - java_args+=("'$1'") -} -addScala () { - scala_args+=("'$1'") -} -addResidual () { - residual_args+=("'$1'") -} -addScrip() { - script_args+=("'$1'") -} - -#for A in "$@" ; do echo "A[$A]" ; done ; exit 2 - -while [[ $# -gt 0 ]]; do -case "$1" in - --) shift; for arg; do addResidual "$arg"; done; set -- ;; - -v|-verbose) verbose=true && addScala "-verbose" && shift ;; - -q|-quiet) quiet=true && shift ;; - - -colors) colors=true && shift ;; - -no-colors) unset colors && shift ;; - # break out -D and -J options and add them to java_args so - # they reach the JVM in time to do some good. The -D options - # will be available as system properties. - -D*) addJava "$1" && shift ;; - -J*) addJava "${1:2}" && shift ;; - *) addResidual "$1" - shift - ;; - esac -done - -eval "\"$JAVACMD\"" \ - ${JAVA_OPTS:-$default_java_opts} \ - "${java_args[@]}" \ - -classpath "${JVM_CP_ARGS}" \ - -Dscala.expandjavacp=true \ - -Dscala.usejavacp=true \ - "dotty.tools.repl.Main" \ - "${scala_args[@]}" \ - "${residual_args[@]}" \ - "${scripting_string-}" -scala_exit_status=$? -onExit diff --git a/dist/bin/repl.bat b/dist/bin/repl.bat deleted file mode 100644 index 5d710850c5ff..000000000000 --- a/dist/bin/repl.bat +++ /dev/null @@ -1,110 +0,0 @@ -@echo off -setlocal enabledelayedexpansion - -@rem ######################################################################### -@rem ## Environment setup - -set _EXITCODE=0 - -for %%f in ("%~dp0.") do ( - set "_PROG_HOME=%%~dpf" - @rem get rid of the trailing slash - set "_PROG_HOME=!_PROG_HOME:~0,-1!" -) -call "%_PROG_HOME%\libexec\common.bat" -if not %_EXITCODE%==0 goto end - -set _DEFAULT_JAVA_OPTS=-Xmx768m -Xms768m - -call :args %* - -@rem ######################################################################### -@rem ## Main - -if defined JAVA_OPTS ( set _JAVA_OPTS=%JAVA_OPTS% -) else ( set _JAVA_OPTS=%_DEFAULT_JAVA_OPTS% -) - -@rem we need to escape % in the java command path, for some reason this doesnt work in common.bat -set "_JAVACMD=!_JAVACMD:%%=%%%%!" - -call "%_JAVACMD%" %_JAVA_OPTS% %_JAVA_DEBUG% %_JAVA_ARGS% ^ --classpath "%_LIB_DIR%\scaladoc.jar" ^ --Dscala.expandjavacp=true ^ --Dscala.usejavacp=true ^ -dotty.tools.repl.Main %_SCALA_ARGS% %_RESIDUAL_ARGS% -if not %ERRORLEVEL%==0 ( - @rem echo Error: Scaladoc execution failed 1>&2 - set _EXITCODE=1 - goto end -) -goto end - -@rem ######################################################################### -@rem ## Subroutines - -:args -set _JAVA_DEBUG= -set _HELP= -set _VERBOSE= -set _QUIET= -set _COLORS= -set _SCALA_ARGS= -set _JAVA_ARGS= -set _RESIDUAL_ARGS= - -:args_loop -if "%~1"=="" goto args_done -set "__ARG=%~1" -if "%__ARG%"=="--" ( - @rem for arg; do addResidual "$arg"; done; set -- ;; -) else if "%__ARG%"=="-h" ( - set _HELP=true - call :addScala "-help" -) else if "%__ARG%"=="-help" ( - set _HELP=true - call :addScala "-help" -) else if "%__ARG%"=="-v" ( - set _VERBOSE=true - call :addScala "-verbose" -) else if "%__ARG%"=="-verbose" ( - set _VERBOSE=true - call :addScala "-verbose" -) else if "%__ARG%"=="-debug" ( set "_JAVA_DEBUG=%_DEBUG_STR%" -) else if "%__ARG%"=="-q" ( set _QUIET=true -) else if "%__ARG%"=="-quiet" ( set _QUIET=true -) else if "%__ARG%"=="-colors" ( set _COLORS=true -) else if "%__ARG%"=="-no-colors" ( set _COLORS= -) else if "%__ARG:~0,2%"=="-D" ( call :addJava "%__ARG%" -) else if "%__ARG:~0,2%"=="-J" ( call :addJava "%__ARG:~2%" -) else ( - if defined _IN_SCRIPTING_ARGS ( call :addScripting "%__ARG%" - ) else ( call :addResidual "%__ARG%" - ) -) -shift -goto args_loop -:args_done -goto :eof - -@rem output parameter: _SCALA_ARGS -:addScala -set _SCALA_ARGS=%_SCALA_ARGS% %~1 -goto :eof - -@rem output parameter: _JAVA_ARGS -:addJava -set _JAVA_ARGS=%_JAVA_ARGS% %~1 -goto :eof - -@rem output parameter: _RESIDUAL_ARGS -:addResidual -set _RESIDUAL_ARGS=%_RESIDUAL_ARGS% %~1 -goto :eof - -@rem ######################################################################### -@rem ## Cleanups - -:end -exit /b %_EXITCODE% -endlocal From e8b1d1e163921d289f9f4a101ddfa9d76a853d5b Mon Sep 17 00:00:00 2001 From: noti0na1 Date: Wed, 26 Feb 2025 14:09:01 +0100 Subject: [PATCH 3/5] Fix arguments --- compiler/test/dotty/tools/scripting/BashExitCodeTests.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/test/dotty/tools/scripting/BashExitCodeTests.scala b/compiler/test/dotty/tools/scripting/BashExitCodeTests.scala index 1aaa1c418db8..2835206d27ae 100644 --- a/compiler/test/dotty/tools/scripting/BashExitCodeTests.scala +++ b/compiler/test/dotty/tools/scripting/BashExitCodeTests.scala @@ -36,7 +36,7 @@ class BashExitCodeTests: def scala(args: String*) = verifyExit(scalaPath, ("--power" +: args :+ "--offline" :+ "--server=false")*) def scalacRaw(args: String*) = verifyExit(scalacPath, args*) def scalac(args: String*) = scalacRaw(("-d" +: tmpDir +: args)*) - def repl(args: String*) = verifyExit(scalaPath, "--power", "repl", "--offline", "--", args*) + def repl(args: String*) = verifyExit(scalaPath, ("--power" +: "repl" +: "--offline" +: "--" +: args)*) /** The path to the test file for this class. */ def f(body: String, suffix: String = ".scala"): String = From 7c4a701bd4a83398110423c4367f686bdee0da9f Mon Sep 17 00:00:00 2001 From: noti0na1 Date: Thu, 27 Feb 2025 13:24:44 +0100 Subject: [PATCH 4/5] Rename setting name --- compiler/src/dotty/tools/dotc/config/ScalaSettings.scala | 2 +- compiler/src/dotty/tools/repl/ReplDriver.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala index bdbd0e8665b8..64fe63332c18 100644 --- a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -128,7 +128,7 @@ trait CommonScalaSettings: val usejavacp: Setting[Boolean] = BooleanSetting(RootSetting, "usejavacp", "Utilize the java.class.path in classpath resolution.", aliases = List("--use-java-class-path")) val scalajs: Setting[Boolean] = BooleanSetting(RootSetting, "scalajs", "Compile in Scala.js mode (requires scalajs-library.jar on the classpath).", aliases = List("--scalajs")) val replInitScript: Setting[String] = StringSetting(RootSetting, "repl-init-script", "code", "The code will be run on REPL startup.", "", aliases = List("--repl-init-script")) - val replEvalOnly: Setting[Boolean] = BooleanSetting(RootSetting, "repl-quit-after-init", "Quit REPL after evaluating the init script.", aliases = List("--repl-quit-after-init")) + val replQuitAfterInit: Setting[Boolean] = BooleanSetting(RootSetting, "repl-quit-after-init", "Quit REPL after evaluating the init script.", aliases = List("--repl-quit-after-init")) end CommonScalaSettings /** -P "plugin" settings. Various tools might support plugins. */ diff --git a/compiler/src/dotty/tools/repl/ReplDriver.scala b/compiler/src/dotty/tools/repl/ReplDriver.scala index c284a9c00560..b00cf3d19188 100644 --- a/compiler/src/dotty/tools/repl/ReplDriver.scala +++ b/compiler/src/dotty/tools/repl/ReplDriver.scala @@ -154,7 +154,7 @@ class ReplDriver(settings: Array[String], * Possible reason for unsuccessful run are raised flags in CLI like --help or --version */ final def tryRunning = if shouldStart then - if rootCtx.settings.replEvalOnly.value(using rootCtx) then initialState + if rootCtx.settings.replQuitAfterInit.value(using rootCtx) then initialState else runUntilQuit() /** Run REPL with `state` until `:quit` command found From fbd34ec3379e4f86f74f740be389e7720f1e0e87 Mon Sep 17 00:00:00 2001 From: noti0na1 Date: Fri, 28 Feb 2025 13:40:29 +0100 Subject: [PATCH 5/5] Update compiler/test/dotty/tools/scripting/BashExitCodeTests.scala Co-authored-by: Hamza Remmal --- compiler/test/dotty/tools/scripting/BashExitCodeTests.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/test/dotty/tools/scripting/BashExitCodeTests.scala b/compiler/test/dotty/tools/scripting/BashExitCodeTests.scala index 2835206d27ae..b4244c5e5cff 100644 --- a/compiler/test/dotty/tools/scripting/BashExitCodeTests.scala +++ b/compiler/test/dotty/tools/scripting/BashExitCodeTests.scala @@ -32,7 +32,7 @@ class BashExitCodeTests: s"expected $expectedExitCode but got $exitCode${pp("out", stdout)}${pp("err", stderr)}" }, expectedExitCode, exitCode) - // Helpers for running scala, scalac, scalac, and repl without the output directory ("raw") + // Helpers for running scala, scalac and repl without the output directory ("raw") def scala(args: String*) = verifyExit(scalaPath, ("--power" +: args :+ "--offline" :+ "--server=false")*) def scalacRaw(args: String*) = verifyExit(scalacPath, args*) def scalac(args: String*) = scalacRaw(("-d" +: tmpDir +: args)*)