From ea3c5c0107474dc17dd94bc6a693f431ceae5bde Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 17 Jul 2018 20:08:26 +0200 Subject: [PATCH] Use -Xmetadata-version in tests instead of custom preprocessing Test data for the wrongMetadataVersion test has changed because now not only the .class files have the "future" version, but also the .kotlin_module file, which prevents the current compiler from being able to read what parts does a package in the library consist of. This is related to the TODO in ModuleMapping.kt:89 --- .../wrongMetadataVersion/output.txt | 14 ++++------ .../CompileKotlinAgainstCustomBinariesTest.kt | 28 ++++++------------- 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/wrongMetadataVersion/output.txt b/compiler/testData/compileKotlinAgainstCustomBinaries/wrongMetadataVersion/output.txt index 11740f7aba7..cfbf7449d2a 100644 --- a/compiler/testData/compileKotlinAgainstCustomBinaries/wrongMetadataVersion/output.txt +++ b/compiler/testData/compileKotlinAgainstCustomBinaries/wrongMetadataVersion/output.txt @@ -31,20 +31,16 @@ compiler/testData/compileKotlinAgainstCustomBinaries/wrongMetadataVersion/source The class is loaded from $TMP_DIR$/library-after.jar!/a/A.class val supertype = object : A() {} ^ -compiler/testData/compileKotlinAgainstCustomBinaries/wrongMetadataVersion/source.kt:11:13: error: class 'a.AKt' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 42.0.0, expected version is $ABI_VERSION$. -The class is loaded from $TMP_DIR$/library-after.jar!/a/AKt.class +compiler/testData/compileKotlinAgainstCustomBinaries/wrongMetadataVersion/source.kt:11:13: error: unresolved reference: foo val x = foo() ^ -compiler/testData/compileKotlinAgainstCustomBinaries/wrongMetadataVersion/source.kt:12:13: error: class 'a.AKt' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 42.0.0, expected version is $ABI_VERSION$. -The class is loaded from $TMP_DIR$/library-after.jar!/a/AKt.class +compiler/testData/compileKotlinAgainstCustomBinaries/wrongMetadataVersion/source.kt:12:13: error: unresolved reference: bar val y = bar ^ -compiler/testData/compileKotlinAgainstCustomBinaries/wrongMetadataVersion/source.kt:13:5: error: class 'a.AKt' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 42.0.0, expected version is $ABI_VERSION$. -The class is loaded from $TMP_DIR$/library-after.jar!/a/AKt.class +compiler/testData/compileKotlinAgainstCustomBinaries/wrongMetadataVersion/source.kt:13:5: error: unresolved reference: bar bar = 239 ^ -compiler/testData/compileKotlinAgainstCustomBinaries/wrongMetadataVersion/source.kt:14:12: error: class 'a.AKt' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 42.0.0, expected version is $ABI_VERSION$. -The class is loaded from $TMP_DIR$/library-after.jar!/a/AKt.class +compiler/testData/compileKotlinAgainstCustomBinaries/wrongMetadataVersion/source.kt:14:12: error: unresolved reference: TA val z: TA = "" ^ -COMPILATION_ERROR \ No newline at end of file +COMPILATION_ERROR diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.kt b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.kt index ca1bba6c636..4431213f94b 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.kt @@ -25,7 +25,6 @@ import org.jetbrains.kotlin.config.LanguageVersion import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.PackageViewDescriptor import org.jetbrains.kotlin.load.java.JvmAnnotationNames -import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmMetadataVersion import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.DescriptorUtils.isObject import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil @@ -34,7 +33,6 @@ import org.jetbrains.kotlin.test.KotlinTestUtils import org.jetbrains.kotlin.test.MockLibraryUtil import org.jetbrains.kotlin.test.TestJdkKind import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile -import org.jetbrains.kotlin.utils.JsMetadataVersion import org.jetbrains.org.objectweb.asm.* import org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode import org.jetbrains.org.objectweb.asm.tree.MethodInsnNode @@ -85,31 +83,23 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration } private fun doTestKotlinLibraryWithWrongMetadataVersion( - libraryName: String, - additionalTransformation: ((fieldName: String, value: Any?) -> Any?)?, - vararg additionalOptions: String + libraryName: String, + additionalTransformation: ((fieldName: String, value: Any?) -> Any?)?, + vararg additionalOptions: String ) { - val version = JvmMetadataVersion(42, 0, 0).toArray() val library = transformJar( - compileLibrary(libraryName), - { _, bytes -> - WrongBytecodeVersionTest.transformMetadataInClassFile(bytes) { fieldName, value -> - additionalTransformation?.invoke(fieldName, value) ?: - version.takeIf { JvmAnnotationNames.METADATA_VERSION_FIELD_NAME == fieldName } - } + compileLibrary(libraryName, additionalOptions = listOf("-Xmetadata-version=42.0.0")), + { _, bytes -> + WrongBytecodeVersionTest.transformMetadataInClassFile(bytes) { fieldName, value -> + additionalTransformation?.invoke(fieldName, value) } + } ) compileKotlin("source.kt", tmpdir, listOf(library), K2JVMCompiler(), additionalOptions.toList()) } private fun doTestKotlinLibraryWithWrongMetadataVersionJs(libraryName: String, vararg additionalOptions: String) { - val library = compileJsLibrary(libraryName) - - library.writeText(library.readText(Charsets.UTF_8).replace( - "(" + JsMetadataVersion.INSTANCE.toInteger() + ", ", - "(" + JsMetadataVersion(42, 0, 0).toInteger() + ", " - ), Charsets.UTF_8) - + val library = compileJsLibrary(libraryName, additionalOptions = listOf("-Xmetadata-version=42.0.0")) compileKotlin("source.kt", File(tmpdir, "usage.js"), listOf(library), K2JSCompiler(), additionalOptions.toList()) }