JS: support -Xskip-metadata-version-check for incompatible ABI libraries
Allow the compiler to read such libraries without any errors, at the risk of crashing with an exception. Also fix a minor bug in the diagnostic message in LibrarySourcesConfig and in the corresponding test in KotlinJpsBuildTest
This commit is contained in:
+11
@@ -0,0 +1,11 @@
|
||||
package a
|
||||
|
||||
open class A {
|
||||
class Nested
|
||||
|
||||
fun method() {}
|
||||
}
|
||||
|
||||
fun foo() {}
|
||||
var bar = 42
|
||||
typealias TA = String
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
error: file '$TMP_DIR$/library.meta.js' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 42.0.0, expected version is 1.0.0
|
||||
COMPILATION_ERROR
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package usage
|
||||
|
||||
import a.*
|
||||
|
||||
fun baz(param: A, nested: A.Nested) {
|
||||
val constructor = A()
|
||||
val nested = A.Nested()
|
||||
val methodCall = param.method()
|
||||
val supertype = object : A() {}
|
||||
|
||||
val x = foo()
|
||||
val y = bar
|
||||
bar = 239
|
||||
val z: TA = ""
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package a
|
||||
|
||||
open class A {
|
||||
class Nested
|
||||
|
||||
fun method() {}
|
||||
}
|
||||
|
||||
fun foo() {}
|
||||
var bar = 42
|
||||
typealias TA = String
|
||||
+1
@@ -0,0 +1 @@
|
||||
OK
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
@file:Suppress("UNUSED_VARIABLE", "UNUSED_PARAMETER")
|
||||
package usage
|
||||
|
||||
import a.*
|
||||
|
||||
fun baz(param: A, nested: A.Nested) {
|
||||
val constructor = A()
|
||||
val nested2 = A.Nested()
|
||||
val methodCall = param.method()
|
||||
val supertype = object : A() {}
|
||||
|
||||
val x = foo()
|
||||
val y = bar
|
||||
bar = 239
|
||||
val z: TA = ""
|
||||
}
|
||||
+25
@@ -25,6 +25,7 @@ import kotlin.Pair;
|
||||
import kotlin.collections.SetsKt;
|
||||
import kotlin.io.FilesKt;
|
||||
import kotlin.jvm.functions.Function2;
|
||||
import kotlin.text.Charsets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
||||
@@ -52,6 +53,7 @@ import org.jetbrains.kotlin.test.*;
|
||||
import org.jetbrains.kotlin.test.util.DescriptorValidator;
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator;
|
||||
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
|
||||
import org.jetbrains.kotlin.utils.JsMetadataVersion;
|
||||
import org.jetbrains.kotlin.utils.StringsKt;
|
||||
import org.jetbrains.org.objectweb.asm.ClassReader;
|
||||
import org.jetbrains.org.objectweb.asm.ClassVisitor;
|
||||
@@ -316,6 +318,21 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
|
||||
KotlinTestUtils.assertEqualsToFile(new File(getTestDataDirectory(), "output.txt"), normalizeOutput(output));
|
||||
}
|
||||
|
||||
private void doTestKotlinLibraryWithWrongMetadataVersionJs(@NotNull String libraryName, @NotNull String... additionalOptions) {
|
||||
compileLibrary(new K2JSCompiler(), libraryName, new File(tmpdir, "library.js"), Collections.<String>emptyList());
|
||||
|
||||
File library = new File(tmpdir, "library.meta.js");
|
||||
FilesKt.writeText(library, FilesKt.readText(library, Charsets.UTF_8).replace(
|
||||
"(" + JsMetadataVersion.INSTANCE.toInteger() + ", ",
|
||||
"(" + new JsMetadataVersion(42, 0, 0).toInteger() + ", "
|
||||
), Charsets.UTF_8);
|
||||
|
||||
Pair<String, ExitCode> output = compileKotlin(
|
||||
new K2JSCompiler(), "source.kt", new File(tmpdir, "usage.js"), Arrays.asList(additionalOptions), library
|
||||
);
|
||||
KotlinTestUtils.assertEqualsToFile(new File(getTestDataDirectory(), "output.txt"), normalizeOutput(output));
|
||||
}
|
||||
|
||||
private void doTestPreReleaseKotlinLibrary(
|
||||
@NotNull CLICompiler<?> compiler,
|
||||
@NotNull String libraryName,
|
||||
@@ -492,6 +509,10 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
|
||||
doTestKotlinLibraryWithWrongMetadataVersion("library", null);
|
||||
}
|
||||
|
||||
public void testWrongMetadataVersionJs() throws Exception {
|
||||
doTestKotlinLibraryWithWrongMetadataVersionJs("library");
|
||||
}
|
||||
|
||||
public void testWrongMetadataVersionBadMetadata() throws Exception {
|
||||
doTestKotlinLibraryWithWrongMetadataVersion(
|
||||
"library",
|
||||
@@ -532,6 +553,10 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
|
||||
doTestKotlinLibraryWithWrongMetadataVersion("library", null, "-Xskip-metadata-version-check");
|
||||
}
|
||||
|
||||
public void testWrongMetadataVersionJsSkipVersionCheck() throws Exception {
|
||||
doTestKotlinLibraryWithWrongMetadataVersionJs("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