Skip to content

Commit

Permalink
Arg files are one arg per line
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt committed Sep 27, 2022
1 parent 616866c commit 8560921
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/compiler/scala/tools/nsc/CompilerCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ 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(_ != '#')
val file = Paths.get(arg stripPrefix "@")
def stripComment(s: String) = s.takeWhile(_ != '#').trim() // arg can be "" but not " "
val file = Paths.get(arg.stripPrefix("@"))
if (!Files.exists(file))
throw new java.io.FileNotFoundException(s"argument file $file could not be found")
settings.splitParams(Files.readAllLines(file).asScala.map(stripComment).mkString(" "))
Files.readAllLines(file).asScala.filter(!_.startsWith("#")).map(stripComment).toList
}

// override this if you don't want arguments processed here
Expand Down
1 change: 1 addition & 0 deletions test/files/run/argfile.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Compiler arguments written to: argfile-run.obj/print-args.txt
39 changes: 39 additions & 0 deletions test/files/run/argfile.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

import java.nio.file.Files

import scala.jdk.CollectionConverters._
import scala.reflect.internal.util._
import scala.tools.nsc.{CompilerCommand, Settings}
import scala.tools.partest.DirectTest
import scala.util.chaining._

object Test extends DirectTest {
var count = 0
lazy val argfile = testOutput.jfile.toPath().resolve("print-args.txt")
lazy val goodarg = testOutput.jfile.toPath().resolve("print-args2.txt")
override def extraSettings =
if (count == 0) s"""${super.extraSettings} -Xsource:3 -Vprint-args $argfile "-Wconf:cat=unused-nowarn&msg=does not suppress&site=C:s""""
else s"@$goodarg"

// Use CompilerCommand for expanding the args file.
override def newSettings(args: List[String]) = (new Settings).tap { s =>
val cc = new CompilerCommand(args, s)
assert(cc.ok)
assert(cc.files.isEmpty)
}
def code =
sm"""
|@annotation.nowarn
|final class C {
| def f: Int = "42".toInt
|}
"""
def show() = {
assert(compile())
// drop "-Vprint-args .../print-args.txt newSource1.scala"
val args = Files.readAllLines(argfile).asScala.toList.dropRight(3)
Files.write(goodarg, args.asJava)
count += 1
assert(compile())
}
}

0 comments on commit 8560921

Please sign in to comment.