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");
}
}
@@ -230,10 +230,6 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
return NOTHING_DONE
}
messageCollector.report(
INFO, "Kotlin version " + KotlinCompilerVersion.VERSION + " (JRE " + System.getProperty("java.runtime.version") + ")"
)
val targetsWithoutOutputDir = targets.filter { it.outputDir == null }
if (targetsWithoutOutputDir.isNotEmpty()) {
messageCollector.report(ERROR, "Output directory not specified for " + targetsWithoutOutputDir.joinToString())
@@ -251,6 +247,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
val commonArguments = compilerArgumentsForChunk(chunk).apply {
reportOutputFiles = true
version = true // Always report the version to help diagnosing user issues if they submit the compiler output
}
val allCompiledFiles = getAllCompiledFilesContainer(context)
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments
import org.jetbrains.kotlin.com.intellij.openapi.util.io.FileUtil
import org.jetbrains.kotlin.config.KotlinCompilerVersion
import org.jetbrains.kotlin.config.Services
import org.jetbrains.kotlin.daemon.client.CompileServiceSession
import org.jetbrains.kotlin.daemon.common.*
@@ -100,6 +101,12 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil
compilerArgs: CommonCompilerArguments,
environment: GradleCompilerEnvironment
): ExitCode {
if (compilerArgs.version) {
project.logger.lifecycle("Kotlin version " + KotlinCompilerVersion.VERSION +
" (JRE " + System.getProperty("java.runtime.version") + ")")
compilerArgs.version = false
}
val argsArray = ArgumentUtils.convertArgumentsToStringList(compilerArgs).toTypedArray()
with (project.logger) {
kotlinDebug { "Kotlin compiler class: $compilerClassName" }
@@ -1,11 +1,11 @@
[INFO] Kotlin Compiler version @snapshot@
[INFO] Kotlin version @snapshot@ (JRE <jre-version>)
[INFO] Compiling Kotlin sources from [/test-extension/src/main/kotlin]
[INFO] Module name is test-extension
[WARNING] Some JAR files in the classpath have the Kotlin Runtime library bundled into them. This may cause difficult to debug problems if there's a different version of the Kotlin Runtime library in the classpath. Consider removing these libraries from the classpath or use '-Xskip-runtime-version-check' to suppress this warning
[WARNING] /local-repo/org/jetbrains/kotlin/kotlin-compiler/@snapshot@/kotlin-compiler-@snapshot@.jar: (-1, -1) Library has Kotlin runtime bundled into it
[INFO] Kotlin Compiler version @snapshot@
[INFO] Kotlin version @snapshot@ (JRE <jre-version>)
[WARNING] No sources found skipping Kotlin compile
[INFO] Kotlin Compiler version @snapshot@
[INFO] Kotlin version @snapshot@ (JRE <jre-version>)
[INFO] Compiling Kotlin sources from [/use-test-extension/src/main/kotlin]
[INFO] Module name is use-test-extension
[INFO] Applicability test for project use-test-extension
@@ -13,5 +13,5 @@
[INFO] Configuring test plugin with arguments
[INFO] Plugin applied
[INFO] Option value: my-special-value
[INFO] Kotlin Compiler version @snapshot@
[WARNING] No sources found skipping Kotlin compile
[INFO] Kotlin version @snapshot@ (JRE <jre-version>)
[WARNING] No sources found skipping Kotlin compile
@@ -1,5 +1,5 @@
/**
* NOTE: if this script returns false, the build log with more information can be found at tools/kotlin-maven-plugin/target/it/plugins/build.log
* NOTE: if this script returns false, the build log with more information can be found at tools/kotlin-maven-plugin-test/target/it/plugins/build.log
*/
import java.util.regex.Pattern
@@ -38,7 +38,8 @@ State state = buildLogFile.readLines().collect { it.replaceAll("\\u001b[^m]*m",
replaceAll(/[0-9]+\s*ms/, "LLL ms").
trim().
replaceAll(/^\[[A-Z]+\]$/, "").
replace(kotlinVersion, "@snapshot@")
replace(kotlinVersion, "@snapshot@").
replaceAll(/\(JRE .+\)/, "(JRE <jre-version>)")
if (filtered != "") {
acc.lines << filtered
@@ -1,3 +1,3 @@
[INFO] Kotlin Compiler version @snapshot@
[INFO] Kotlin version @snapshot@ (JRE <jre-version>)
[INFO] Compiling Kotlin sources from [/src/main/kotlin]
[INFO] Module name is test-project
@@ -35,7 +35,8 @@ State state = new File(basedir, "build.log").readLines().collect { it.replaceAll
replaceAll(/[0-9]+\s*ms/, "LLL ms").
trim().
replaceAll(/^\[[A-Z]+\]$/, "").
replaceAll(/version [0-9a-z-+\.]+/, "version @snapshot@")
replaceAll(/version [0-9a-z-+\.]+/, "version @snapshot@").
replaceAll(/\(JRE .+\)/, "(JRE <jre-version>)")
if (filtered != "") {
acc.lines << filtered
@@ -198,8 +198,8 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
getLog().info("Kotlin Compiler version " + KotlinCompilerVersion.VERSION);
getLog().info("Kotlin version " + KotlinCompilerVersion.VERSION +
" (JRE " + System.getProperty("java.runtime.version") + ")");
if (!hasKotlinFilesInSources()) {
getLog().warn("No sources found skipping Kotlin compile");