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
@@ -119,11 +119,6 @@ public abstract class CommonCompilerArguments implements Serializable {
return new DummyImpl();
}
@NotNull
public String executableScriptFileName() {
return "kotlinc";
}
public static final String WARN = "warn";
public static final String ERROR = "error";
public static final String ENABLE = "enable";
@@ -88,10 +88,4 @@ public class K2JSCompilerArguments extends CommonCompilerArguments {
arguments.moduleKind = K2JsArgumentConstants.MODULE_PLAIN;
return arguments;
}
@Override
@NotNull
public String executableScriptFileName() {
return "kotlinc-js";
}
}
@@ -146,10 +146,4 @@ public class K2JVMCompilerArguments extends CommonCompilerArguments {
arguments.jvmTarget = JvmTarget.DEFAULT.getDescription();
return arguments;
}
@Override
@NotNull
public String executableScriptFileName() {
return "kotlinc-jvm";
}
}
@@ -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>) {
-1
View File
@@ -1 +0,0 @@
-version
-2
View File
@@ -1,2 +0,0 @@
info: Kotlin Compiler version $VERSION$
OK
-1
View File
@@ -1 +0,0 @@
-version
-2
View File
@@ -1,2 +0,0 @@
info: Kotlin Compiler version $VERSION$
OK
@@ -3,7 +3,7 @@ Buildfile: [TestData]/build.xml
build:
[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
[kotlin2js] info: Kotlin Compiler version [KotlinVersion]
[kotlin2js] info: kotlinc-js [KotlinVersion] (JRE [JREVersion])
BUILD SUCCESSFUL
Total time: [time]
@@ -5,7 +5,7 @@ build:
[kotlinc] Compiling [[TestData]/hello.kt] => [[Temp]/hello.jar]
[javac] Compiling 1 source file to [Temp]
[javac] Compiling [[TestData]] => [[Temp]]
[javac] info: Kotlin Compiler version [KotlinVersion]
[javac] info: kotlinc-jvm [KotlinVersion] (JRE [JREVersion])
[javac] Running javac...
BUILD SUCCESSFUL
@@ -3,7 +3,7 @@ Buildfile: [TestData]/build.xml
build:
[kotlinc] Compiling [[TestData]/hello.kt] => [[Temp]/hello.jar]
[kotlinc] info: Kotlin Compiler version [KotlinVersion]
[kotlinc] info: kotlinc-jvm [KotlinVersion] (JRE [JREVersion])
BUILD SUCCESSFUL
Total time: [time]
@@ -0,0 +1,5 @@
ERR:
info: kotlinc-jvm [KotlinVersion] (JRE [JREVersion])
Return code: 0
@@ -81,6 +81,7 @@ public abstract class KotlinIntegrationTestBase extends TestCaseWithTmpdir {
content = normalizePath(content, getCompilerLib(), "[CompilerLib]");
content = normalizePath(content, getKotlinProjectHome(), "[KotlinProjectHome]");
content = content.replaceAll(Pattern.quote(KotlinCompilerVersion.VERSION), "[KotlinVersion]");
content = content.replaceAll("\\(JRE .+\\)", "(JRE [JREVersion])");
content = StringUtil.convertLineSeparators(content);
return content;
}
@@ -362,12 +362,6 @@ public class CliTestGenerated extends AbstractCliTest {
doJvmTest(fileName);
}
@TestMetadata("version.args")
public void testVersion() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/version.args");
doJvmTest(fileName);
}
@TestMetadata("warningJdkWithNoJdk.args")
public void testWarningJdkWithNoJdk() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/warningJdkWithNoJdk.args");
@@ -515,12 +509,6 @@ public class CliTestGenerated extends AbstractCliTest {
doJsTest(fileName);
}
@TestMetadata("version.args")
public void testVersion() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js/version.args");
doJsTest(fileName);
}
@TestMetadata("withFolderAsLib.args")
public void testWithFolderAsLib() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js/withFolderAsLib.args");
@@ -85,5 +85,8 @@ public class CompilerSmokeTest extends CompilerSmokeTestBase {
assertEquals("compilation failed", 0, runCompiler("inlineOnly.compile", "-include-runtime", "inlineOnly.kt", "-d", jar));
run("inlineOnly.run", "-cp", jar, "InlineOnly.InlineOnlyKt");
}
}
public void testPrintVersion() throws Exception {
runCompiler("test.compile", "-version");
}
}