Skip to content

Commit 73bb88d

Browse files
committed
insert compiler libraries head of user-specified classpath
1 parent 3a6a949 commit 73bb88d

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

compiler/src/dotty/tools/MainGenericRunner.scala

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import java.util.jar._
1616
import java.util.jar.Attributes.Name
1717
import dotty.tools.io.Jar
1818
import dotty.tools.runner.ScalaClassLoader
19+
import java.nio.file.{Files, Paths, Path}
20+
import scala.collection.JavaConverters._
21+
import dotty.tools.dotc.config.CommandLineParser
1922

2023
enum ExecuteMode:
2124
case Guess
@@ -123,7 +126,8 @@ object MainGenericRunner {
123126
case (o @ javaOption(striped)) :: tail =>
124127
process(tail, settings.withJavaArgs(striped).withScalaArgs(o))
125128
case (o @ scalaOption(_*)) :: tail =>
126-
process(tail, settings.withScalaArgs(o))
129+
val remainingArgs = (expandArg(o) ++ tail).toList
130+
process(remainingArgs, settings)
127131
case (o @ colorOption(_*)) :: tail =>
128132
process(tail, settings.withScalaArgs(o))
129133
case arg :: tail =>
@@ -137,6 +141,19 @@ object MainGenericRunner {
137141
val newSettings = if arg.startsWith("-") then settings else settings.withPossibleEntryPaths(arg).withModeShouldBePossibleRun
138142
process(tail, newSettings.withResidualArgs(arg))
139143

144+
// copy of method private to dotty.tools.dotc.config.CliCommand.distill()
145+
// TODO: make it available as a public method and remove this copy?
146+
def expandArg(arg: String): List[String] =
147+
def stripComment(s: String) = s takeWhile (_ != '#')
148+
val path = Paths.get(arg stripPrefix "@")
149+
if (!Files.exists(path))
150+
System.err.println(s"Argument file ${path.getFileName} could not be found")
151+
Nil
152+
else
153+
val lines = Files.readAllLines(path) // default to UTF-8 encoding
154+
val params = lines.asScala map stripComment mkString " "
155+
CommandLineParser.tokenize(params)
156+
140157
def main(args: Array[String]): Unit =
141158
val scalaOpts = envOrNone("SCALA_OPTS").toArray.flatMap(_.split(" "))
142159
val allArgs = scalaOpts ++ args

0 commit comments

Comments
 (0)