JS: support '-Xskip-metadata-version-check' to allow pre-release libraries
This commit is contained in:
+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 = ""
|
||||
}
|
||||
+22
-8
@@ -316,12 +316,12 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
|
||||
KotlinTestUtils.assertEqualsToFile(new File(getTestDataDirectory(), "output.txt"), normalizeOutput(output));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void doTestPreReleaseKotlinLibrary(
|
||||
@NotNull CLICompiler<?> compiler,
|
||||
@NotNull String libraryName,
|
||||
@NotNull File destination,
|
||||
@NotNull File result,
|
||||
@NotNull File usageDestination,
|
||||
@NotNull String... additionalOptions
|
||||
) throws Exception {
|
||||
// Compiles the library with the "pre-release" flag, then compiles a usage of this library in the release mode
|
||||
@@ -337,7 +337,7 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
|
||||
Pair<String, ExitCode> output;
|
||||
try {
|
||||
System.setProperty(TEST_IS_PRE_RELEASE_SYSTEM_PROPERTY, "false");
|
||||
output = compileKotlin(compiler, "source.kt", tmpdir, Arrays.asList(additionalOptions), result);
|
||||
output = compileKotlin(compiler, "source.kt", usageDestination, Arrays.asList(additionalOptions), result);
|
||||
}
|
||||
finally {
|
||||
System.clearProperty(TEST_IS_PRE_RELEASE_SYSTEM_PROPERTY);
|
||||
@@ -459,19 +459,33 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
|
||||
|
||||
public void testReleaseCompilerAgainstPreReleaseLibrary() throws Exception {
|
||||
File destination = new File(tmpdir, "library.jar");
|
||||
doTestPreReleaseKotlinLibrary(new K2JVMCompiler(), "library", destination, destination);
|
||||
doTestPreReleaseKotlinLibrary(new K2JVMCompiler(), "library", destination, destination, tmpdir);
|
||||
}
|
||||
|
||||
public void testReleaseCompilerAgainstPreReleaseLibraryJs() throws Exception {
|
||||
doTestPreReleaseKotlinLibrary(new K2JSCompiler(), "library",
|
||||
new File(tmpdir, "library.js"),
|
||||
new File(tmpdir, "library.meta.js"));
|
||||
doTestPreReleaseKotlinLibrary(
|
||||
new K2JSCompiler(), "library",
|
||||
new File(tmpdir, "library.js"), new File(tmpdir, "library.meta.js"),
|
||||
new File(tmpdir, "usage.js")
|
||||
);
|
||||
}
|
||||
|
||||
public void testReleaseCompilerAgainstPreReleaseLibrarySkipVersionCheck() throws Exception {
|
||||
File destination = new File(tmpdir, "library.jar");
|
||||
doTestPreReleaseKotlinLibrary(new K2JVMCompiler(), "library", destination, destination,
|
||||
"-Xskip-metadata-version-check");
|
||||
doTestPreReleaseKotlinLibrary(
|
||||
new K2JVMCompiler(), "library",
|
||||
destination, destination, tmpdir,
|
||||
"-Xskip-metadata-version-check"
|
||||
);
|
||||
}
|
||||
|
||||
public void testReleaseCompilerAgainstPreReleaseLibraryJsSkipVersionCheck() throws Exception {
|
||||
doTestPreReleaseKotlinLibrary(
|
||||
new K2JSCompiler(), "library",
|
||||
new File(tmpdir, "library.js"), new File(tmpdir, "library.meta.js"),
|
||||
new File(tmpdir, "usage.js"),
|
||||
"-Xskip-metadata-version-check"
|
||||
);
|
||||
}
|
||||
|
||||
public void testWrongMetadataVersion() throws Exception {
|
||||
|
||||
+11
-6
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.deserialization.AnnotationDeserializer
|
||||
import org.jetbrains.kotlin.serialization.deserialization.DeserializationConfiguration
|
||||
import org.jetbrains.kotlin.serialization.deserialization.DeserializedPackageFragmentImpl
|
||||
import org.jetbrains.kotlin.serialization.deserialization.IncompatibleVersionErrorData
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor
|
||||
@@ -40,8 +41,9 @@ class KotlinJavascriptPackageFragment(
|
||||
storageManager: StorageManager,
|
||||
module: ModuleDescriptor,
|
||||
proto: ProtoBuf.PackageFragment,
|
||||
header: JsProtoBuf.Header
|
||||
) : DeserializedPackageFragmentImpl(fqName, storageManager, module, proto, JsContainerSource(fqName, header)) {
|
||||
header: JsProtoBuf.Header,
|
||||
configuration: DeserializationConfiguration
|
||||
) : DeserializedPackageFragmentImpl(fqName, storageManager, module, proto, JsContainerSource(fqName, header, configuration)) {
|
||||
private val fileMap: Map<Int, FileHolder> by storageManager.createLazyValue {
|
||||
this.proto.getExtension(JsProtoBuf.packageFragmentFiles).fileList.withIndex().associate { (index, file) ->
|
||||
(if (file.hasId()) file.id else index) to FileHolder(file.annotationList)
|
||||
@@ -72,7 +74,11 @@ class KotlinJavascriptPackageFragment(
|
||||
}
|
||||
}
|
||||
|
||||
private class JsContainerSource(private val fqName: FqName, private val header: JsProtoBuf.Header) : DeserializedContainerSource {
|
||||
private class JsContainerSource(
|
||||
private val fqName: FqName,
|
||||
header: JsProtoBuf.Header,
|
||||
configuration: DeserializationConfiguration
|
||||
) : DeserializedContainerSource {
|
||||
// TODO
|
||||
override fun getContainingFile(): SourceFile = SourceFile.NO_SOURCE_FILE
|
||||
|
||||
@@ -81,10 +87,9 @@ class KotlinJavascriptPackageFragment(
|
||||
override val incompatibility: IncompatibleVersionErrorData<*>?
|
||||
get() = null
|
||||
|
||||
override val isPreReleaseInvisible: Boolean
|
||||
get() = (header.flags and 1) != 0 && !KotlinCompilerVersion.isPreRelease()
|
||||
override val isPreReleaseInvisible: Boolean =
|
||||
!configuration.skipMetadataVersionCheck && (header.flags and 1) != 0 && !KotlinCompilerVersion.isPreRelease()
|
||||
|
||||
// TODO: this is not a class
|
||||
override val presentableString: String
|
||||
get() = "Package '$fqName'"
|
||||
}
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ fun createKotlinJavascriptPackageFragmentProvider(
|
||||
): PackageFragmentProvider {
|
||||
val packageFragments = packageFragmentProtos.mapNotNull { proto ->
|
||||
proto.fqName?.let { fqName ->
|
||||
KotlinJavascriptPackageFragment(fqName, storageManager, module, proto, header)
|
||||
KotlinJavascriptPackageFragment(fqName, storageManager, module, proto, header, configuration)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user