Skip to content
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

Runner sets residual args instead of append #14543

Merged
merged 1 commit into from
Mar 3, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions compiler/src/dotty/tools/MainGenericRunner.scala
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
hello raw world
hello run world
13 changes: 13 additions & 0 deletions tests/run-with-compiler/i14541.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

// test argument processing and "execution mode" in runner
object Test:
nicolasstucki marked this conversation as resolved.
Show resolved Hide resolved
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(" ")
}