Use "-Xskip-metadata-version-check" to load pre-release classes
This commit is contained in:
+1
-1
@@ -95,7 +95,7 @@ public class K2JVMCompilerArguments extends CommonCompilerArguments {
|
||||
@Argument(value = "Xallow-kotlin-package", description = "Allow compiling code in package 'kotlin'")
|
||||
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;
|
||||
|
||||
@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.incremental.components.SourceRetentionAnnotationHandler
|
||||
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.incremental.components.IncrementalCompilationComponents
|
||||
import org.jetbrains.kotlin.script.KotlinScriptDefinitionFromAnnotatedTemplate
|
||||
@@ -115,8 +116,10 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
return ExitCode.OK
|
||||
}
|
||||
|
||||
if (arguments.skipMetadataVersionCheck) {
|
||||
if (arguments.skipMetadataVersionCheck) {
|
||||
JvmMetadataVersion.skipCheck = true
|
||||
@Suppress("DEPRECATION")
|
||||
DeserializedDescriptorResolver.IS_PRE_RELEASE = true
|
||||
}
|
||||
|
||||
if (arguments.includeRuntime) {
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ where advanced options include:
|
||||
-Xreport-perf Report detailed performance statistics
|
||||
-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 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
|
||||
-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)
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package a
|
||||
|
||||
open class A {
|
||||
class Nested
|
||||
}
|
||||
|
||||
fun foo() {}
|
||||
var bar = 42
|
||||
typealias TA = String
|
||||
+1
@@ -0,0 +1 @@
|
||||
OK
|
||||
+15
@@ -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 = ""
|
||||
}
|
||||
+11
-2
@@ -229,7 +229,7 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
|
||||
}
|
||||
|
||||
@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
|
||||
|
||||
File library;
|
||||
@@ -244,7 +244,7 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
|
||||
Pair<String, ExitCode> output;
|
||||
try {
|
||||
DeserializedDescriptorResolver.Companion.setIS_PRE_RELEASE(false);
|
||||
output = compileKotlin("source.kt", tmpdir, library);
|
||||
output = compileKotlin("source.kt", tmpdir, Arrays.asList(additionalOptions), library);
|
||||
}
|
||||
finally {
|
||||
DeserializedDescriptorResolver.Companion.setIS_PRE_RELEASE(KotlinCompilerVersion.IS_PRE_RELEASE);
|
||||
@@ -368,6 +368,15 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
|
||||
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*/
|
||||
public void testInlineFunWithoutDebugInfo() throws Exception {
|
||||
compileKotlin("sourceInline.kt", tmpdir);
|
||||
|
||||
Reference in New Issue
Block a user