@@ -16,6 +16,9 @@ import java.util.jar._
16
16
import java .util .jar .Attributes .Name
17
17
import dotty .tools .io .Jar
18
18
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
19
22
20
23
enum ExecuteMode :
21
24
case Guess
@@ -123,7 +126,8 @@ object MainGenericRunner {
123
126
case (o @ javaOption(striped)) :: tail =>
124
127
process(tail, settings.withJavaArgs(striped).withScalaArgs(o))
125
128
case (o @ scalaOption(_* )) :: tail =>
126
- process(tail, settings.withScalaArgs(o))
129
+ val remainingArgs = (expandArg(o) ++ tail).toList
130
+ process(remainingArgs, settings)
127
131
case (o @ colorOption(_* )) :: tail =>
128
132
process(tail, settings.withScalaArgs(o))
129
133
case arg :: tail =>
@@ -137,6 +141,19 @@ object MainGenericRunner {
137
141
val newSettings = if arg.startsWith(" -" ) then settings else settings.withPossibleEntryPaths(arg).withModeShouldBePossibleRun
138
142
process(tail, newSettings.withResidualArgs(arg))
139
143
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
+
140
157
def main (args : Array [String ]): Unit =
141
158
val scalaOpts = envOrNone(" SCALA_OPTS" ).toArray.flatMap(_.split(" " ))
142
159
val allArgs = scalaOpts ++ args
0 commit comments