Update to kotlinx-metadata-jvm 0.6.2
Migrate to the new API in kotlin-reflect build script, remove obsolete workarounds.
This commit is contained in:
committed by
Space Team
parent
5451477eb0
commit
ecc1f9fb0b
@@ -122,7 +122,7 @@ dependencies {
|
||||
implementation("org.jetbrains.kotlin:kotlin-stdlib:${project.bootstrapKotlinVersion}")
|
||||
implementation("org.jetbrains.kotlin:kotlin-reflect:${project.bootstrapKotlinVersion}")
|
||||
implementation("com.google.code.gson:gson:2.8.9") // Workaround for Gradle dependency resolution error
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.6.0")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.6.2")
|
||||
}
|
||||
|
||||
samWithReceiver {
|
||||
@@ -142,4 +142,4 @@ tasks.withType<KotlinCompile>().configureEach {
|
||||
|
||||
allprojects {
|
||||
tasks.register("checkBuild")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7859,6 +7859,12 @@
|
||||
<sha256 value="17e1076131cd07c958a942ff8a087cf865b1ef3de58463e1e5dd6fd7515406b0" origin="Generated by Gradle"/>
|
||||
</artifact>
|
||||
</component>
|
||||
<component group="org.jetbrains.kotlin" name="kotlin-stdlib" version="1.8.20">
|
||||
<artifact name="kotlin-stdlib-1.8.20.jar">
|
||||
<md5 value="2b3d65e24952649bf7534017c64b435e" origin="Generated by Gradle"/>
|
||||
<sha256 value="4395647b1961d9fb730a34e8dbe56c293157bc0759004cca63d9b5ee6653e5c7" origin="Generated by Gradle"/>
|
||||
</artifact>
|
||||
</component>
|
||||
<component group="org.jetbrains.kotlin" name="kotlin-stdlib-common" version="1.3.70">
|
||||
<artifact name="kotlin-stdlib-common-1.3.70.jar">
|
||||
<md5 value="53323436def4746efd414192e1add1bc" origin="Generated by Gradle"/>
|
||||
@@ -7975,6 +7981,12 @@
|
||||
<sha256 value="385031de4c6dd9e990d6a44455d79583572a490a3464d7fe7f10a5ecca3225a8" origin="Generated by Gradle"/>
|
||||
</artifact>
|
||||
</component>
|
||||
<component group="org.jetbrains.kotlin" name="kotlin-stdlib-common" version="1.8.20">
|
||||
<artifact name="kotlin-stdlib-common-1.8.20.jar">
|
||||
<md5 value="af45a8873880f027f47d573e1483a6dc" origin="Generated by Gradle"/>
|
||||
<sha256 value="fa20188abaa8ecf1d0035e93a969b071f10e45a1c8378c314521eade73f75fd5" origin="Generated by Gradle"/>
|
||||
</artifact>
|
||||
</component>
|
||||
<component group="org.jetbrains.kotlin" name="kotlin-stdlib-jdk7" version="1.3.31">
|
||||
<artifact name="kotlin-stdlib-jdk7-1.3.31.jar">
|
||||
<md5 value="2ccfa99735888fb60053f3c7f07243f0" origin="Generated by Gradle"/>
|
||||
@@ -8775,6 +8787,12 @@
|
||||
<sha256 value="a20b73b2b30ba6e08a5ffc990b3db9abd0649e42c79ff5da38d22040a3284068" origin="Generated by Gradle"/>
|
||||
</artifact>
|
||||
</component>
|
||||
<component group="org.jetbrains.kotlinx" name="kotlinx-metadata-jvm" version="0.6.2">
|
||||
<artifact name="kotlinx-metadata-jvm-0.6.2.jar">
|
||||
<md5 value="54753fc5e62ddb7831d3539d2cf7728f" origin="Generated by Gradle"/>
|
||||
<sha256 value="8f5759b435fcbcfdf06c80295013ba953db4ec817b04d7809c61a739a483527b" origin="Generated by Gradle"/>
|
||||
</artifact>
|
||||
</component>
|
||||
<component group="org.jetbrains.kotlinx" name="kotlinx-metadata-klib" version="0.0.1-dev-10">
|
||||
<artifact name="kotlinx-metadata-klib-0.0.1-dev-10.jar">
|
||||
<md5 value="eb72c22727bdbd6abf8649703c82ba68" origin="Generated by Gradle"/>
|
||||
|
||||
@@ -45,7 +45,7 @@ versions.kotlinx-collections-immutable=0.3.1
|
||||
versions.kotlinx-coroutines-core-jvm=1.5.0
|
||||
versions.kotlinx-coroutines-core=1.5.0
|
||||
|
||||
versions.kotlinx-metadata-jvm=0.6.0
|
||||
versions.kotlinx-metadata-jvm=0.6.2
|
||||
versions.kotlinx-metadata-klib=0.0.1-dev-10
|
||||
versions.kotlinx-serialization-json=1.3.3
|
||||
versions.ktor-network=2.0.2
|
||||
|
||||
@@ -2,7 +2,6 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
import com.github.jengelman.gradle.plugins.shadow.transformers.CacheableTransformer
|
||||
import com.github.jengelman.gradle.plugins.shadow.transformers.Transformer
|
||||
import com.github.jengelman.gradle.plugins.shadow.transformers.TransformerContext
|
||||
import kotlinx.metadata.jvm.KmModuleVisitor
|
||||
import kotlinx.metadata.jvm.KotlinModuleMetadata
|
||||
import org.gradle.kotlin.dsl.support.serviceOf
|
||||
import shadow.org.apache.tools.zip.ZipEntry
|
||||
@@ -12,7 +11,7 @@ description = "Kotlin Full Reflection Library"
|
||||
|
||||
buildscript {
|
||||
dependencies {
|
||||
classpath("org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.6.0")
|
||||
classpath("org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.6.2")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +59,7 @@ dependencies {
|
||||
}
|
||||
|
||||
@CacheableTransformer
|
||||
class KotlinModuleShadowTransformer(private val logger: Logger, private val useK2: Boolean) : Transformer {
|
||||
class KotlinModuleShadowTransformer(private val logger: Logger) : Transformer {
|
||||
@Suppress("ArrayInDataClass")
|
||||
private data class Entry(val path: String, val bytes: ByteArray)
|
||||
|
||||
@@ -75,38 +74,24 @@ class KotlinModuleShadowTransformer(private val logger: Logger, private val useK
|
||||
fun relocate(content: String): String =
|
||||
context.relocators.fold(content) { acc, relocator -> relocator.applyToSourceContent(acc) }
|
||||
|
||||
val writer = KotlinModuleMetadata.Writer()
|
||||
logger.info("Transforming ${context.path}")
|
||||
if (useK2) {
|
||||
// TODO: remove this branch after migration to version 1.9
|
||||
val internalData = org.jetbrains.kotlin.metadata.jvm.deserialization.ModuleMapping.loadModuleMapping(
|
||||
context.`is`.readBytes(), javaClass.name, skipMetadataVersionCheck = true, isJvmPackageNameSupported = true
|
||||
) {
|
||||
}
|
||||
val visitor = object : KmModuleVisitor(writer) {
|
||||
override fun visitPackageParts(fqName: String, fileFacades: List<String>, multiFileClassParts: Map<String, String>) {
|
||||
assert(multiFileClassParts.isEmpty()) { multiFileClassParts } // There are no multi-file class parts in core
|
||||
super.visitPackageParts(relocate(fqName), fileFacades.map(::relocate), multiFileClassParts)
|
||||
}
|
||||
}
|
||||
for ((fqName, parts) in internalData.packageFqName2Parts) {
|
||||
val (fileFacades, multiFileClassParts) = parts.parts.partition { parts.getMultifileFacadeName(it) == null }
|
||||
visitor.visitPackageParts(fqName, fileFacades, multiFileClassParts.associateWith { parts.getMultifileFacadeName(it)!! })
|
||||
}
|
||||
visitor.visitEnd()
|
||||
} else {
|
||||
val metadata = KotlinModuleMetadata.read(context.`is`.readBytes())
|
||||
?: error("Not a .kotlin_module file: ${context.path}")
|
||||
// TODO: writer declaration and logger.info call from above should be move here after migration to version 1.9
|
||||
metadata.accept(object : KmModuleVisitor(writer) {
|
||||
override fun visitPackageParts(fqName: String, fileFacades: List<String>, multiFileClassParts: Map<String, String>) {
|
||||
assert(multiFileClassParts.isEmpty()) { multiFileClassParts } // There are no multi-file class parts in core
|
||||
super.visitPackageParts(relocate(fqName), fileFacades.map(::relocate), multiFileClassParts)
|
||||
}
|
||||
})
|
||||
}
|
||||
val metadata = KotlinModuleMetadata.read(context.`is`.readBytes())
|
||||
?: error("Not a .kotlin_module file: ${context.path}")
|
||||
val module = metadata.toKmModule()
|
||||
|
||||
data += Entry(context.path, writer.write().bytes)
|
||||
val packageParts = module.packageParts.toMap()
|
||||
module.packageParts.clear()
|
||||
packageParts.map { (fqName, parts) ->
|
||||
require(parts.multiFileClassParts.isEmpty()) { parts.multiFileClassParts } // There are no multi-file class parts in core
|
||||
|
||||
val fileFacades = parts.fileFacades.toList()
|
||||
parts.fileFacades.clear()
|
||||
fileFacades.mapTo(parts.fileFacades) { relocate(it) }
|
||||
|
||||
relocate(fqName) to parts
|
||||
}.toMap(module.packageParts)
|
||||
|
||||
data += Entry(context.path, KotlinModuleMetadata.write(module).bytes)
|
||||
}
|
||||
|
||||
override fun hasTransformedResource(): Boolean = data.isNotEmpty()
|
||||
@@ -133,7 +118,7 @@ val reflectShadowJar by task<ShadowJar> {
|
||||
|
||||
if (kotlinBuildProperties.relocation) {
|
||||
mergeServiceFiles()
|
||||
transform(KotlinModuleShadowTransformer(logger, project.kotlinBuildProperties.useFir))
|
||||
transform(KotlinModuleShadowTransformer(logger))
|
||||
relocate("org.jetbrains.kotlin", "kotlin.reflect.jvm.internal.impl")
|
||||
relocate("javax.inject", "kotlin.reflect.jvm.internal.impl.javax.inject")
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ configurations {
|
||||
|
||||
dependencies {
|
||||
api("org.jetbrains.kotlinx:binary-compatibility-validator:0.13.0")
|
||||
api("org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.6.0")
|
||||
api("org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.6.2")
|
||||
|
||||
testApi project(':kotlin-test:kotlin-test-junit')
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.jvm.abi
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import junit.framework.TestCase
|
||||
import kotlinx.metadata.jvm.KotlinClassMetadata
|
||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
|
||||
import org.jetbrains.kotlin.codegen.CodegenTestUtil
|
||||
@@ -84,14 +83,6 @@ abstract class BaseJvmAbiTest : TestCase() {
|
||||
|
||||
if (InTextDirectivesUtils.findStringWithPrefixes(directives, "// USE_K2") != null) {
|
||||
useK2 = true
|
||||
|
||||
// Force metadata version 1.9 to circumvent the fact that kotlinx-metadata-jvm 0.6.0 has default metadata version 1.8,
|
||||
// so it can read/write metadata with versions up to and including 1.9, yet K2 has metadata version 2.0+.
|
||||
// This hack can be removed once jvm-abi-gen depends on kotlinx-metadata-jvm that can read/write metadata version 2.0.
|
||||
// Without this hack, CompileAgainstJvmAbiTestGenerated.testInlineClassWithPrivateConstructorK2 currently fails.
|
||||
if (KotlinClassMetadata.COMPATIBLE_METADATA_VERSION.take(2) == listOf(1, 8)) {
|
||||
metadataVersion = "1.9"
|
||||
}
|
||||
}
|
||||
}
|
||||
val exitCode = compiler.exec(messageCollector, Services.EMPTY, args)
|
||||
|
||||
Reference in New Issue
Block a user