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

insert compiler libraries head of user-specified classpath - fix for 13552 #13562

Merged
merged 10 commits into from
Sep 27, 2021
21 changes: 19 additions & 2 deletions compiler/src/dotty/tools/MainGenericRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import java.util.jar._
import java.util.jar.Attributes.Name
import dotty.tools.io.Jar
import dotty.tools.runner.ScalaClassLoader
import java.nio.file.{Files, Paths, Path}
import scala.collection.JavaConverters._
import dotty.tools.dotc.config.CommandLineParser

enum ExecuteMode:
case Guess
Expand Down Expand Up @@ -123,7 +126,8 @@ object MainGenericRunner {
case (o @ javaOption(striped)) :: tail =>
process(tail, settings.withJavaArgs(striped).withScalaArgs(o))
case (o @ scalaOption(_*)) :: tail =>
process(tail, settings.withScalaArgs(o))
val remainingArgs = (expandArg(o) ++ tail).toList
process(remainingArgs, settings)
case (o @ colorOption(_*)) :: tail =>
process(tail, settings.withScalaArgs(o))
case arg :: tail =>
Expand All @@ -137,6 +141,19 @@ object MainGenericRunner {
val newSettings = if arg.startsWith("-") then settings else settings.withPossibleEntryPaths(arg).withModeShouldBePossibleRun
process(tail, newSettings.withResidualArgs(arg))

// copy of method private to dotty.tools.dotc.config.CliCommand.distill()
// TODO: make it available as a public method and remove this copy?
philwalk marked this conversation as resolved.
Show resolved Hide resolved
def expandArg(arg: String): List[String] =
def stripComment(s: String) = s takeWhile (_ != '#')
val path = Paths.get(arg stripPrefix "@")
if (!Files.exists(path))
System.err.println(s"Argument file ${path.getFileName} could not be found")
Nil
else
val lines = Files.readAllLines(path) // default to UTF-8 encoding
val params = lines.asScala map stripComment mkString " "
CommandLineParser.tokenize(params)

def main(args: Array[String]): Unit =
val scalaOpts = envOrNone("SCALA_OPTS").toArray.flatMap(_.split(" "))
val allArgs = scalaOpts ++ args
Expand Down Expand Up @@ -191,8 +208,8 @@ object MainGenericRunner {
List("-classpath", settings.classPath.mkString(classpathSeparator)).filter(Function.const(settings.classPath.nonEmpty))
++ settings.residualArgs
++ (if settings.save then List("-save") else Nil)
++ List("-script", settings.targetScript)
++ settings.scalaArgs
++ List("-script", settings.targetScript)
++ settings.scriptArgs
scripting.Main.main(properArgs.toArray)
case ExecuteMode.Guess =>
Expand Down