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

Make scalac's argument-file processing more like javac's in handling spaces and line breaks #10319

Merged
merged 1 commit into from Mar 28, 2023
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
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