Use "-Xskip-metadata-version-check" to load pre-release classes

This commit is contained in:
Alexander Udalov
2016-12-06 19:54:36 +03:00
parent 7de0cfde16
commit d204fa91cc
7 changed files with 42 additions and 5 deletions
@@ -95,7 +95,7 @@ public class K2JVMCompilerArguments extends CommonCompilerArguments {
@Argument(value = "Xallow-kotlin-package", description = "Allow compiling code in package 'kotlin'") @Argument(value = "Xallow-kotlin-package", description = "Allow compiling code in package 'kotlin'")
public boolean allowKotlinPackage; public boolean allowKotlinPackage;
@Argument(value = "Xskip-metadata-version-check", description = "Try loading binary incompatible classes, may cause crashes") @Argument(value = "Xskip-metadata-version-check", description = "Load classes with bad metadata version anyway (incl. pre-release classes)")
public boolean skipMetadataVersionCheck; public boolean skipMetadataVersionCheck;
@Argument(value = "Xdump-declarations-to", description = "Path to JSON file to dump Java to Kotlin declaration mappings") @Argument(value = "Xdump-declarations-to", description = "Path to JSON file to dump Java to Kotlin declaration mappings")
@@ -39,6 +39,7 @@ import org.jetbrains.kotlin.compiler.plugin.cliPluginUsageString
import org.jetbrains.kotlin.config.* import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.incremental.components.SourceRetentionAnnotationHandler import org.jetbrains.kotlin.incremental.components.SourceRetentionAnnotationHandler
import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.load.kotlin.DeserializedDescriptorResolver
import org.jetbrains.kotlin.load.kotlin.JvmMetadataVersion import org.jetbrains.kotlin.load.kotlin.JvmMetadataVersion
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents
import org.jetbrains.kotlin.script.KotlinScriptDefinitionFromAnnotatedTemplate import org.jetbrains.kotlin.script.KotlinScriptDefinitionFromAnnotatedTemplate
@@ -115,8 +116,10 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
return ExitCode.OK return ExitCode.OK
} }
if (arguments.skipMetadataVersionCheck) { if (arguments.skipMetadataVersionCheck) {
JvmMetadataVersion.skipCheck = true JvmMetadataVersion.skipCheck = true
@Suppress("DEPRECATION")
DeserializedDescriptorResolver.IS_PRE_RELEASE = true
} }
if (arguments.includeRuntime) { if (arguments.includeRuntime) {
+1 -1
View File
@@ -6,7 +6,7 @@ where advanced options include:
-Xreport-perf Report detailed performance statistics -Xreport-perf Report detailed performance statistics
-Xmultifile-parts-inherit Compile multifile classes as a hierarchy of parts and facade -Xmultifile-parts-inherit Compile multifile classes as a hierarchy of parts and facade
-Xallow-kotlin-package Allow compiling code in package 'kotlin' -Xallow-kotlin-package Allow compiling code in package 'kotlin'
-Xskip-metadata-version-check Try loading binary incompatible classes, may cause crashes -Xskip-metadata-version-check Load classes with bad metadata version anyway (incl. pre-release classes)
-Xdump-declarations-to <path> Path to JSON file to dump Java to Kotlin declaration mappings -Xdump-declarations-to <path> 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 -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) -Xadd-compiler-builtins Add definitions of built-in declarations to the compilation classpath (useful with -no-stdlib)
@@ -0,0 +1,9 @@
package a
open class A {
class Nested
}
fun foo() {}
var bar = 42
typealias TA = String
@@ -0,0 +1,15 @@
@file:Suppress("UNUSED_VARIABLE")
package usage
import a.*
fun baz(param: A) {
val constructor = A()
val methodCall = param.hashCode()
val supertype = object : A() {}
val x = foo()
val y = bar
bar = 239
val z: TA = ""
}
@@ -229,7 +229,7 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private void doTestPreReleaseKotlinLibrary(@NotNull String libraryName) throws Exception { private void doTestPreReleaseKotlinLibrary(@NotNull String libraryName, @NotNull String... additionalOptions) throws Exception {
// Compiles the library with the "pre-release" flag, then compiles a usage of this library in the release mode // Compiles the library with the "pre-release" flag, then compiles a usage of this library in the release mode
File library; File library;
@@ -244,7 +244,7 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
Pair<String, ExitCode> output; Pair<String, ExitCode> output;
try { try {
DeserializedDescriptorResolver.Companion.setIS_PRE_RELEASE(false); DeserializedDescriptorResolver.Companion.setIS_PRE_RELEASE(false);
output = compileKotlin("source.kt", tmpdir, library); output = compileKotlin("source.kt", tmpdir, Arrays.asList(additionalOptions), library);
} }
finally { finally {
DeserializedDescriptorResolver.Companion.setIS_PRE_RELEASE(KotlinCompilerVersion.IS_PRE_RELEASE); DeserializedDescriptorResolver.Companion.setIS_PRE_RELEASE(KotlinCompilerVersion.IS_PRE_RELEASE);
@@ -368,6 +368,15 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
doTestPreReleaseKotlinLibrary("library"); doTestPreReleaseKotlinLibrary("library");
} }
/*
// This test should pass but is commented out because the compiler flag is implemented via mutation of the public field,
// which may cause subsequent tests to behave unexpectedly
// TODO: refactor and uncomment
public void testReleaseCompilerAgainstPreReleaseLibrarySkipVersionCheck() throws Exception {
doTestPreReleaseKotlinLibrary("library", "-Xskip-metadata-version-check");
}
*/
/*test source mapping generation when source info is absent*/ /*test source mapping generation when source info is absent*/
public void testInlineFunWithoutDebugInfo() throws Exception { public void testInlineFunWithoutDebugInfo() throws Exception {
compileKotlin("sourceInline.kt", tmpdir); compileKotlin("sourceInline.kt", tmpdir);