Skip to content

Commit 5779bbd

Browse files
committed
Small improvements to -Xprint-args
- Don't print `-Xprint-args ...` itself - Render a programattically added single output directory as -d. Zinc sets the output directory in this way. ``` scala> import scala.tools.nsc._; val g = new Global(new Settings); g.settings.outputDirs.setSingleOutput("/tmp"); g.settings.printArgs.value = "-"; val run = new g.Run(); run.compileSources(g.newSourceFile("") :: Nil) -d /tmp <console> import scala.tools.nsc._ ```
1 parent 5ed8fd0 commit 5779bbd

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/compiler/scala/tools/nsc/Global.scala

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1446,7 +1446,20 @@ class Global(var currentSettings: Settings, reporter0: Reporter)
14461446

14471447
private def printArgs(sources: List[SourceFile]): Unit = {
14481448
if (settings.printArgs.isSetByUser) {
1449-
val argsFile = (settings.recreateArgs ::: sources.map(_.file.absolute.toString())).mkString("", "\n", "\n")
1449+
val singleOuputDir: List[String] = if (settings.d.value == settings.d.default) {
1450+
settings.outputDirs.getSingleOutput match {
1451+
case Some(file) =>
1452+
val jfile = file.file
1453+
if (jfile != null && !java.nio.file.Files.isSameFile(jfile.toPath, java.nio.file.Paths.get(settings.d.value))) {
1454+
// A build tool must have used `settings.outDirs.setSingleOutput`, bypassing `-d`.
1455+
// Render that to the equivalent -d arguments.
1456+
"-d" :: jfile.toString :: Nil
1457+
} else Nil
1458+
case _ => Nil
1459+
}
1460+
} else Nil
1461+
val recreated = settings.userSetSettings.toList.filterNot(_ eq settings.printArgs).flatMap(_.unparse)
1462+
val argsFile = (recreated ::: singleOuputDir ::: sources.map(_.file.absolute.toString())).mkString("", "\n", "\n")
14501463
settings.printArgs.value match {
14511464
case "-" =>
14521465
reporter.echo(argsFile)

0 commit comments

Comments
 (0)