From 4960a7a6ea30da4f01e972c005227e9777ea561f Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Sun, 19 Feb 2023 00:24:51 -0800 Subject: [PATCH] Re-revert untokenized argfile, write quoted args --- src/compiler/scala/tools/nsc/CompilerCommand.scala | 5 +++-- src/compiler/scala/tools/nsc/Global.scala | 4 +++- test/files/run/argfile.scala | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/compiler/scala/tools/nsc/CompilerCommand.scala b/src/compiler/scala/tools/nsc/CompilerCommand.scala index dc606d5a15a0..9e2405ee6e66 100644 --- a/src/compiler/scala/tools/nsc/CompilerCommand.scala +++ b/src/compiler/scala/tools/nsc/CompilerCommand.scala @@ -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 diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala index c3b369df35e4..89da5fe0ac59 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -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) diff --git a/test/files/run/argfile.scala b/test/files/run/argfile.scala index 6fffbac7e9bc..5fdb17fc988e 100644 --- a/test/files/run/argfile.scala +++ b/test/files/run/argfile.scala @@ -23,7 +23,8 @@ object Test extends DirectTest { } def code = sm""" - |@annotation.nowarn + |import annotation.* + |@nowarn |final class C { | def f: Int = "42".toInt |}