Skip to content

Fix scala runner exit codes #15604

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 9 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/MainGenericRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import dotty.tools.io.Jar
import dotty.tools.runner.ScalaClassLoader
import java.nio.file.Paths
import dotty.tools.dotc.config.CommandLineParser
import dotty.tools.scripting.StringDriver
import dotty.tools.scripting.{StringDriver, StringDriverException, ScriptingException}

enum ExecuteMode:
case Guess
Expand Down Expand Up @@ -247,8 +247,7 @@ object MainGenericRunner {
++ settings.scalaArgs
++ List("-script", settings.targetScript)
++ settings.scriptArgs
scripting.Main.main(properArgs.toArray)
None
scripting.Main.process(properArgs.toArray)

case ExecuteMode.Expression =>
val cp = settings.classPath match {
Expand All @@ -269,8 +268,9 @@ object MainGenericRunner {
run(settings.withExecuteMode(ExecuteMode.Repl))

run(settings) match
case e @ Some(ex) => errorFn("", e)
case _ => true
case Some(ex: (StringDriverException | ScriptingException)) => errorFn(ex.getMessage)
case e @ Some(ex) => errorFn("", e)
case _ => true

def errorFn(str: String, e: Option[Throwable] = None): Boolean =
if (str.nonEmpty) Console.err.println(str)
Expand Down
9 changes: 6 additions & 3 deletions compiler/src/dotty/tools/scripting/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ object Main:
(compilerArgs, file, scriptArgs, saveJar, invokeFlag)
end distinguishArgs

def main(args: Array[String]): Unit =
def process(args: Array[String]): Option[Throwable] =
val (compilerArgs, scriptFile, scriptArgs, saveJar, invokeFlag) = distinguishArgs(args)
val driver = ScriptingDriver(compilerArgs, scriptFile, scriptArgs)
driver.compileAndRun { (outDir:Path, classpathEntries:Seq[Path], mainClass: String) =>
Expand All @@ -43,10 +43,13 @@ object Main:
// write a standalone jar to the script parent directory
writeJarfile(outDir, scriptFile, scriptArgs, classpathEntries, mainClass)
invokeFlag
}.map {
}

def main(args: Array[String]): Unit =
process(args).map {
case ScriptingException(msg) => println(msg)
case ex => ex.printStackTrace
}.foreach(_ => System.exit(1))
}.foreach(_ => System.exit(1))

private def writeJarfile(outDir: Path, scriptFile: File, scriptArgs:Array[String],
classpathEntries:Seq[Path], mainClassName: String): Unit =
Expand Down
88 changes: 88 additions & 0 deletions scoverage.coverage
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Coverage data, format version: 3.0
# Statement data:
# - id
# - source path
# - package name
# - class name
# - class type (Class, Object or Trait)
# - full class name
# - method name
# - start offset
# - end offset
# - line number
# - symbol name
# - tree name
# - is branch
# - invocations count
# - is ignored
# - description (can be multi-line)
# ' ' sign
# ------------------------------------------
0
../dotty/src/main/scala/Macro.scala
example
Test$
Object
example.Test$
x
212
217
13
x
DefDef
false
0
false


1
src/main/scala/Main.scala
example
Test$
Object
example.Test$
foo
52
59
5
foo
DefDef
false
0
false
def foo

2
src/main/scala/Main.scala
example
Test$
Object
example.Test$
hello
99
112
8
println
Apply
false
0
false
println("JD")

3
src/main/scala/Main.scala
example
Test$
Object
example.Test$
hello
75
90
7
hello
DefDef
false
0
false
@main def hello