Skip to content

Commit d8bb552

Browse files
committed
Rework -Xprint-args to continue compiler and allow file output
1 parent deb10d4 commit d8bb552

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

src/compiler/scala/tools/nsc/CompilerCommand.scala

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,8 @@ class CompilerCommand(arguments: List[String], val settings: Settings) {
107107
if (debug) "\n" + global.phaseFlagDescriptions else ""
108108
)
109109
else if (genPhaseGraph.isSetByUser) {
110-
val components = global.phaseNames // global.phaseDescriptors // one initializes
110+
val components = global.phaseNames // global.phaseDescriptors // one initializes
111111
s"Phase graph of ${components.size} components output to ${genPhaseGraph.value}*.dot."
112-
} else if (printArgs.value) {
113-
s"""
114-
|${recreateArgs.mkString("\n")}
115-
|${files.mkString("\n")}
116-
""".stripMargin
117112
}
118113
else allSettings.filter(_.isHelping).map(_.help).mkString("\n\n")
119114
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,11 +1438,25 @@ class Global(var currentSettings: Settings, reporter0: LegacyReporter)
14381438
/** Caching member symbols that are def-s in Definitions because they might change from Run to Run. */
14391439
val runDefinitions: definitions.RunDefinitions = new definitions.RunDefinitions
14401440

1441+
private def printArgs(sources: List[SourceFile]): Unit = {
1442+
val argsFile = (settings.recreateArgs ::: sources.map(_.file.absolute.toString())).mkString("", "\n", "\n")
1443+
settings.printArgs.value match {
1444+
case "-" =>
1445+
reporter.echo(argsFile)
1446+
case pathString =>
1447+
import java.nio.file._
1448+
val path = Paths.get(pathString)
1449+
Files.write(path, argsFile.getBytes(Charset.forName("UTF-8")))
1450+
reporter.echo("Compiler arguments written to: " + path)
1451+
}
1452+
}
1453+
14411454
/** Compile list of source files,
14421455
* unless there is a problem already,
14431456
* such as a plugin was passed a bad option.
14441457
*/
14451458
def compileSources(sources: List[SourceFile]): Unit = if (!reporter.hasErrors) {
1459+
printArgs(sources)
14461460

14471461
def checkDeprecations() = {
14481462
warnDeprecatedAndConflictingSettings()

src/compiler/scala/tools/nsc/settings/ScalaSettings.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ trait ScalaSettings extends AbsScalaSettings
4343
protected def futureSettings = List[BooleanSetting]()
4444

4545
/** If any of these settings is enabled, the compiler should print a message and exit. */
46-
def infoSettings = List[Setting](version, help, Xhelp, Yhelp, showPlugins, showPhases, genPhaseGraph, printArgs)
46+
def infoSettings = List[Setting](version, help, Xhelp, Yhelp, showPlugins, showPhases, genPhaseGraph)
4747

4848
/** Is an info setting set? Any -option:help? */
4949
def isInfo = infoSettings.exists(_.isSetByUser) || allSettings.exists(_.isHelping)
@@ -143,7 +143,7 @@ trait ScalaSettings extends AbsScalaSettings
143143
val Xprint = PhasesSetting ("-Xprint", "Print out program after")
144144
val Xprintpos = BooleanSetting ("-Xprint-pos", "Print tree positions, as offsets.")
145145
val printtypes = BooleanSetting ("-Xprint-types", "Print tree types (debugging option).")
146-
val printArgs = BooleanSetting ("-Xprint-args", "Print all compiler arguments and exit.")
146+
val printArgs = StringSetting ("-Xprint-args", "<file>", "Print all compiler arguments to <file>. Use - to echo to the reporter.", "-")
147147
val prompt = BooleanSetting ("-Xprompt", "Display a prompt after each error (debugging option).")
148148
val resident = BooleanSetting ("-Xresident", "Compiler stays resident: read source filenames from standard input.")
149149
val script = StringSetting ("-Xscript", "object", "Treat the source file as a script and wrap it in a main method.", "")

0 commit comments

Comments
 (0)