From d0fa9bac75af23053e77b9d8680ead1ee75e0e75 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 13 Dec 2016 11:21:29 +0300 Subject: [PATCH] Introduce '-Xskip-runtime-version-check' command line option --- .../common/arguments/K2JVMCompilerArguments.java | 3 +++ .../jvm/JvmRuntimeVersionsConsistencyChecker.kt | 5 ++++- .../org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt | 1 + .../cli/jvm/compiler/KotlinCoreEnvironment.kt | 14 +++++++++----- .../kotlin/config/JVMConfigurationKeys.java | 3 +++ compiler/testData/cli/jvm/extraHelp.out | 1 + 6 files changed, 21 insertions(+), 6 deletions(-) diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.java b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.java index e2d7e6de232..af79f6bf5b1 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.java +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.java @@ -98,6 +98,9 @@ public class K2JVMCompilerArguments extends CommonCompilerArguments { @Argument(value = "Xskip-metadata-version-check", description = "Load classes with bad metadata version anyway (incl. pre-release classes)") public boolean skipMetadataVersionCheck; + @Argument(value = "Xskip-runtime-version-check", description = "Allow Kotlin runtime libraries of incompatible versions in the classpath") + public boolean skipRuntimeVersionCheck; + @Argument(value = "Xdump-declarations-to", description = "Path to JSON file to dump Java to Kotlin declaration mappings") @ValueDescription("") public String declarationsOutputPath; diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/JvmRuntimeVersionsConsistencyChecker.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/JvmRuntimeVersionsConsistencyChecker.kt index 40c761dcaa5..9b3ac73d887 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/JvmRuntimeVersionsConsistencyChecker.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/JvmRuntimeVersionsConsistencyChecker.kt @@ -113,7 +113,10 @@ object JvmRuntimeVersionsConsistencyChecker { if (runtimeJarsInfo.hasAnyJarsToCheck) { val languageVersion = languageVersionSettings?.let { MavenComparableVersion(it.languageVersion) } ?: CURRENT_COMPILER_VERSION - checkCompilerClasspathConsistency(messageCollector, languageVersion, runtimeJarsInfo) + if (checkCompilerClasspathConsistency(messageCollector, languageVersion, runtimeJarsInfo)) { + messageCollector.issue(null, "Some runtime JAR files in the classpath have an incompatible version. " + + "Remove them from the classpath or use '-Xskip-runtime-version-check' to suppress errors") + } } } diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt index ea67161e5e8..7bcd5629afd 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt @@ -329,6 +329,7 @@ class K2JVMCompiler : CLICompiler() { configuration.put(JVMConfigurationKeys.DISABLE_PARAM_ASSERTIONS, arguments.noParamAssertions) configuration.put(JVMConfigurationKeys.DISABLE_OPTIMIZATION, arguments.noOptimize) configuration.put(JVMConfigurationKeys.INHERIT_MULTIFILE_PARTS, arguments.inheritMultifileParts) + configuration.put(JVMConfigurationKeys.SKIP_RUNTIME_VERSION_CHECK, arguments.skipRuntimeVersionCheck) configuration.put(CLIConfigurationKeys.ALLOW_KOTLIN_PACKAGE, arguments.allowKotlinPackage) configuration.put(CLIConfigurationKeys.REPORT_PERF, arguments.reportPerf) configuration.put(JVMConfigurationKeys.USE_SINGLE_MODULE, arguments.singleModule) diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt index 6a1e93886ad..4a9bc8af275 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt @@ -155,11 +155,15 @@ class KotlinCoreEnvironment private constructor( val initialRoots = configuration.getList(JVMConfigurationKeys.CONTENT_ROOTS).classpathRoots() - val messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY) - if (messageCollector != null) { - val languageVersionSettings = configuration.get(CommonConfigurationKeys.LANGUAGE_VERSION_SETTINGS) - val classpathJarRoots = initialRoots.mapNotNull { (file, type) -> if (type == JavaRoot.RootType.BINARY) file else null } - JvmRuntimeVersionsConsistencyChecker.checkCompilerClasspathConsistency(messageCollector, languageVersionSettings, classpathJarRoots) + if (!configuration.getBoolean(JVMConfigurationKeys.SKIP_RUNTIME_VERSION_CHECK)) { + val messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY) + if (messageCollector != null) { + JvmRuntimeVersionsConsistencyChecker.checkCompilerClasspathConsistency( + messageCollector, + configuration.get(CommonConfigurationKeys.LANGUAGE_VERSION_SETTINGS), + initialRoots.mapNotNull { (file, type) -> if (type == JavaRoot.RootType.BINARY) file else null } + ) + } } // REPL and kapt2 update classpath dynamically diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/config/JVMConfigurationKeys.java b/compiler/frontend.java/src/org/jetbrains/kotlin/config/JVMConfigurationKeys.java index 5998cc60474..58eda62f05a 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/config/JVMConfigurationKeys.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/config/JVMConfigurationKeys.java @@ -76,6 +76,9 @@ public class JVMConfigurationKeys { public static final CompilerConfigurationKey CREATE_BUILT_INS_FROM_MODULE_DEPENDENCIES = CompilerConfigurationKey.create("create built-ins from resources found in the module dependencies"); + public static final CompilerConfigurationKey SKIP_RUNTIME_VERSION_CHECK = + CompilerConfigurationKey.create("do not perform checks on runtime versions consistency"); + public static final CompilerConfigurationKey JVM_TARGET = CompilerConfigurationKey.create("JVM bytecode target version"); diff --git a/compiler/testData/cli/jvm/extraHelp.out b/compiler/testData/cli/jvm/extraHelp.out index 13b3314324e..40546f5e2a8 100644 --- a/compiler/testData/cli/jvm/extraHelp.out +++ b/compiler/testData/cli/jvm/extraHelp.out @@ -7,6 +7,7 @@ where advanced options include: -Xmultifile-parts-inherit Compile multifile classes as a hierarchy of parts and facade -Xallow-kotlin-package Allow compiling code in package 'kotlin' -Xskip-metadata-version-check Load classes with bad metadata version anyway (incl. pre-release classes) + -Xskip-runtime-version-check Allow Kotlin runtime libraries of incompatible versions in the classpath -Xdump-declarations-to Path to JSON file to dump Java to Kotlin declaration mappings -Xsingle-module Combine modules for source files and binary dependencies into a single module -Xadd-compiler-builtins Add definitions of built-in declarations to the compilation classpath (useful with -no-stdlib)