Change how kotlinc and tools display their version

- Display the Kotlin version in kotlin-gradle-plugin. This is needed
  because if "-version" is specified in compiler arguments, the "info"
  level of the message printed by the compiler in CLICompiler prevents
  it from being displayed by default (unless "--debug" is passed to
  Gradle).
- Display the version of JRE the compiler is running on. This will be
  helpful to diagnose Java 9 related issues in the future.
- In CLI, also display the executable name (kotlinc-jvm or kotlinc-js)
This commit is contained in:
Alexander Udalov
2017-04-06 18:29:48 +03:00
parent bb01ca038a
commit fcf44af294
26 changed files with 63 additions and 67 deletions
@@ -115,7 +115,7 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
}
if (arguments.help || arguments.extraHelp) {
Usage.print(errStream, arguments);
Usage.print(errStream, this, arguments);
return OK;
}
@@ -350,11 +350,19 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
);
private void printVersionIfNeeded(@NotNull MessageCollector messageCollector, @NotNull A arguments) {
if (!arguments.version) return;
messageCollector.report(INFO, "Kotlin Compiler version " + KotlinCompilerVersion.VERSION, null);
if (arguments.version) {
messageCollector.report(
CompilerMessageSeverity.INFO,
executableScriptFileName() + " " + KotlinCompilerVersion.VERSION +
" (JRE " + System.getProperty("java.runtime.version") + ")",
null
);
}
}
@NotNull
public abstract String executableScriptFileName();
/**
* Useful main for derived command line tools
*/
@@ -29,8 +29,10 @@ class Usage {
// The magic number 29 corresponds to the similar padding width in javac and scalac command line compilers
private static final int OPTION_NAME_PADDING_WIDTH = 29;
public static void print(@NotNull PrintStream target, @NotNull CommonCompilerArguments arguments) {
target.println("Usage: " + arguments.executableScriptFileName() + " <options> <source files>");
public static <A extends CommonCompilerArguments> void print(
@NotNull PrintStream target, @NotNull CLICompiler<A> compiler, @NotNull A arguments
) {
target.println("Usage: " + compiler.executableScriptFileName() + " <options> <source files>");
target.println("where " + (arguments.extraHelp ? "advanced" : "possible") + " options include:");
for (Class<?> clazz = arguments.getClass(); clazz != null; clazz = clazz.getSuperclass()) {
for (Field field : clazz.getDeclaredFields()) {
@@ -298,4 +298,10 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
return MainCallParameters.mainWithoutArguments();
}
}
@NotNull
@Override
public String executableScriptFileName() {
return "kotlinc-js";
}
}
@@ -252,17 +252,14 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
}
}
/**
* Allow derived classes to add additional command line arguments
*/
override fun createArguments(): K2JVMCompilerArguments {
val result = K2JVMCompilerArguments()
override fun createArguments(): K2JVMCompilerArguments = K2JVMCompilerArguments().apply {
if (System.getenv("KOTLIN_REPORT_PERF") != null) {
result.reportPerf = true
reportPerf = true
}
return result
}
override fun executableScriptFileName(): String = "kotlinc-jvm"
companion object {
private var initStartNanos = System.nanoTime()
// allows to track GC time for each run when repeated compilation is used
@@ -89,6 +89,9 @@ class K2MetadataCompiler : CLICompiler<K2MetadataCompilerArguments>() {
return ExitCode.OK
}
// TODO: update this once a launcher script for K2MetadataCompiler is available
override fun executableScriptFileName(): String = "kotlinc"
companion object {
@JvmStatic
fun main(args: Array<String>) {