Skip to content

Commit

Permalink
Merge pull request #10319 from som-snytt/tweak/argfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
SethTisue committed Mar 28, 2023
2 parents 968e3bc + 4960a7a commit a256d69
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/compiler/scala/tools/nsc/CompilerCommand.scala
Expand Up @@ -126,11 +126,12 @@ class CompilerCommand(arguments: List[String], val settings: Settings) {
def expandArg(arg: String): List[String] = {
import java.nio.file.{Files, Paths}
import scala.jdk.CollectionConverters._
def stripComment(s: String) = s.takeWhile(_ != '#').trim() // arg can be "" but not " "
def stripComment(s: String) = s.takeWhile(_ != '#').trim()
val file = Paths.get(arg.stripPrefix("@"))
if (!Files.exists(file))
throw new java.io.FileNotFoundException(s"argument file $file could not be found")
Files.readAllLines(file).asScala.filter(!_.startsWith("#")).map(stripComment).toList
val lines = Files.readAllLines(file).asScala.map(stripComment).filterNot(_.isEmpty).toList
lines.flatMap(settings.splitParams)
}

// override this if you don't want arguments processed here
Expand Down
4 changes: 3 additions & 1 deletion src/compiler/scala/tools/nsc/Global.scala
Expand Up @@ -1492,7 +1492,9 @@ class Global(var currentSettings: Settings, reporter0: Reporter)

private def printArgs(sources: List[SourceFile]): Unit =
settings.printArgs.valueSetByUser foreach { value =>
val argsFile = (settings.recreateArgs ::: sources.map(_.file.absolute.toString())).mkString("", "\n", "\n")
def quote(s: String) = if (s.charAt(0) != '"' && s.contains(' ')) "\"" + s + "\"" else s
val allArgs = settings.recreateArgs ::: sources.map(_.file.absolute.toString())
val argsFile = allArgs.map(quote).mkString("", "\n", "\n")
value match {
case "-" =>
reporter.echo(argsFile)
Expand Down
3 changes: 2 additions & 1 deletion test/files/run/argfile.scala
Expand Up @@ -23,7 +23,8 @@ object Test extends DirectTest {
}
def code =
sm"""
|@annotation.nowarn
|import annotation.*
|@nowarn
|final class C {
| def f: Int = "42".toInt
|}
Expand Down

0 comments on commit a256d69

Please sign in to comment.