Skip to content

Commit

Permalink
Small improvements to -Xprint-args
Browse files Browse the repository at this point in the history
  - 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._
```
  • Loading branch information
retronym committed Nov 5, 2018
1 parent 5ed8fd0 commit 81e3918
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/compiler/scala/tools/nsc/Global.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,24 @@ class Global(var currentSettings: Settings, reporter0: Reporter)

private def printArgs(sources: List[SourceFile]): Unit = {
if (settings.printArgs.isSetByUser) {
val argsFile = (settings.recreateArgs ::: sources.map(_.file.absolute.toString())).mkString("", "\n", "\n")
val saved = settings.printArgs.value
val argsFile = try {
val singleOuputDir: List[String] = if (settings.d.value == settings.d.default) {
settings.outputDirs.getSingleOutput match {
case Some(file) =>
val jfile = file.file
if (jfile != null && !java.nio.file.Files.isSameFile(jfile.toPath, java.nio.file.Paths.get(settings.d.value))) {
// A build tool must have used `settings.outDirs.setSingleOutput`, bypassing `-d`.
// Render that to the equivalent -d arguments.
"-d" :: jfile.toString :: Nil
} else Nil
case _ => Nil
}
} else Nil
(settings.recreateArgs ::: singleOuputDir ::: sources.map(_.file.absolute.toString())).mkString("", "\n", "\n")
} finally {
settings.printArgs.value = saved
}
settings.printArgs.value match {
case "-" =>
reporter.echo(argsFile)
Expand Down

0 comments on commit 81e3918

Please sign in to comment.