Skip to content

Commit

Permalink
Runner sets residual args instead of append
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt committed Mar 2, 2022
1 parent 5109909 commit 01a4919
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
9 changes: 5 additions & 4 deletions compiler/src/dotty/tools/MainGenericRunner.scala
Expand Up @@ -168,7 +168,7 @@ object MainGenericRunner {
else
val newSettings = if arg.startsWith("-") then settings else settings.withPossibleEntryPaths(arg).withModeShouldBePossibleRun
process(tail, newSettings.withResidualArgs(arg))

end process

def main(args: Array[String]): Unit =
val scalaOpts = envOrNone("SCALA_OPTS").toArray.flatMap(_.split(" ")).filter(_.nonEmpty)
Expand Down Expand Up @@ -199,11 +199,12 @@ object MainGenericRunner {
Option.when(Jar.isJarOrZip(dotty.tools.io.Path(entryPath)))(Jar(entryPath).mainClass).flatten
}.isDefined
}
targetToRun match
val newSettings = targetToRun match
case Some(fqName) =>
run(settings.withTargetToRun(fqName).withResidualArgs(settings.residualArgs.filter { _ != fqName }*).withExecuteMode(ExecuteMode.Run))
settings.withTargetToRun(fqName).copy(residualArgs = settings.residualArgs.filterNot(fqName.==)).withExecuteMode(ExecuteMode.Run)
case None =>
run(settings.withExecuteMode(ExecuteMode.Repl))
settings.withExecuteMode(ExecuteMode.Repl)
run(newSettings)
case ExecuteMode.Run =>
val scalaClasspath = ClasspathFromClassloader(Thread.currentThread().getContextClassLoader).split(classpathSeparator)
val newClasspath = (settings.classPath.flatMap(_.split(classpathSeparator).filter(_.nonEmpty)) ++ removeCompiler(scalaClasspath) :+ ".").map(File(_).toURI.toURL)
Expand Down
2 changes: 2 additions & 0 deletions tests/run-with-compiler/i14541.check
@@ -0,0 +1,2 @@
hello raw world
hello run world
13 changes: 13 additions & 0 deletions tests/run-with-compiler/i14541.scala
@@ -0,0 +1,13 @@

// test argument processing and "execution mode" in runner
object Test:
import dotty.tools.runner.RichClassLoader.*
val classpath = dotty.tools.dotc.util.ClasspathFromClassloader(getClass.getClassLoader)
def main(args: Array[String]): Unit =
getClass.getClassLoader.run("echo", List("hello", "raw", "world"))
// caution: uses "SCALA_OPTS"
dotty.tools.MainGenericRunner.main(Array("--class-path", classpath, "echo", "hello", "run", "world"))

@main def echo(args: String*): Unit = println {
args.mkString(" ")
}

0 comments on commit 01a4919

Please sign in to comment.