Skip to content

Support Kotlin 1.9.10 #394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Kotlin-Compile-Testing is compatible with all _local_ compiler versions. It does
However, if your project or any of its dependencies depend directly on compiler artifacts such as `kotlin-compiler-embeddable` or `kotlin-annotation-processing-embeddable` then they have to be the same version as the one used by Kotlin-Compile-Testing or there will be a transitive dependency conflict.


- Current `kotlin-compiler-embeddable` version: `1.8.0`
- Current `kotlin-compiler-embeddable` version: `1.9.10`

Because the internal APIs of the Kotlin compiler often change between versions, we can only support one `kotlin-compiler-embeddable` version at a time.

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
buildscript {
ext.kotlin_version = '1.8.0'
ext.embedded_kotlin_version = '1.8.0'
ext.kotlin_version = '1.9.10'
ext.embedded_kotlin_version = '1.9.10'

repositories {
mavenCentral()
Expand Down
14 changes: 14 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType

plugins {
id "com.github.gmazzo.buildconfig" version "3.1.0"
Expand All @@ -15,6 +16,18 @@ buildConfig {
}
}

configurations.all {
resolutionStrategy.dependencySubstitution {
substitute(module("org.jetbrains.kotlin:kotlin-dom-api-compat"))
.using variant(module("org.jetbrains.kotlin:kotlin-dom-api-compat:$embedded_kotlin_version")) {
attributes {
attribute(KotlinPlatformType.attribute, KotlinPlatformType.js)
attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage, "kotlin-runtime"))
}
}
}
}

dependencies {
compileOnly "com.google.auto.service:auto-service:1.0.1"
kapt "com.google.auto.service:auto-service:1.0.1"
Expand All @@ -32,6 +45,7 @@ dependencies {

// Include Kotlin/JS standard library in test classpath for auto loading
testRuntimeOnly "org.jetbrains.kotlin:kotlin-stdlib-js"
testRuntimeOnly "org.jetbrains.kotlin:kotlin-dom-api-compat"

// The Kotlin compiler should be near the end of the list because its .jar file includes
// an obsolete version of Guava
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ abstract class AbstractKotlinCompilation<A : CommonCompilerArguments> internal c
/** Working directory for the compilation */
var workingDir: File by default {
val path = Files.createTempDirectory("Kotlin-Compilation")
log("Created temporary working directory at ${path.toAbsolutePath()}")
return@default path.toFile()
val canonicalFile = path.toFile().canonicalFile
log("Created temporary working directory at ${canonicalFile.canonicalPath}")
return@default canonicalFile
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ internal object HostEnvironment {
findInClasspath(kotlinDependencyRegex("kotlin-stdlib-js"))
}

val kotlinDomApiCompatKlib: File? by lazy {
findInClasspath(kotlinDependencyRegex("kotlin-dom-api-compat"))
}

val kotlinReflectJar: File? by lazy {
findInClasspath(kotlinDependencyRegex("kotlin-reflect"))
}
Expand All @@ -40,7 +44,7 @@ internal object HostEnvironment {
}

private fun kotlinDependencyRegex(prefix: String): Regex {
return Regex("$prefix(-[0-9]+\\.[0-9]+(\\.[0-9]+)?)([-0-9a-zA-Z]+)?\\.jar")
return Regex("$prefix(-[0-9]+\\.[0-9]+(\\.[0-9]+)?)([-0-9a-zA-Z]+)?(\\.jar|\\.klib)")
}

/** Tries to find a file matching the given [regex] in the host process' classpath */
Expand All @@ -60,7 +64,11 @@ internal object HostEnvironment {

val classpaths = classGraph.classpathFiles
val modules = classGraph.modules.mapNotNull { it.locationFile }
val klibs = System.getProperty("java.class.path")
.split(File.pathSeparator)
.filter { it.endsWith(".klib") }
.map(::File)

return (classpaths + modules).distinctBy(File::getAbsolutePath)
return (classpaths + modules + klibs).distinctBy(File::getAbsolutePath)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
var javaParameters: Boolean = false

/** Use the IR backend */
@Deprecated("Since Kotlin 1.9.20 this option is no longer supported by the compiler. It has no effect.")
var useIR: Boolean = false

/** Use the old JVM backend */
Expand Down Expand Up @@ -304,7 +305,6 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {

args.jvmTarget = jvmTarget
args.javaParameters = javaParameters
args.useIR = useIR
args.useOldBackend = useOldBackend

if(javaModulePath != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.tschuchort.compiletesting
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
import org.jetbrains.kotlin.cli.js.K2JSCompiler
import java.io.*
import java.nio.file.Paths
import kotlin.io.path.nameWithoutExtension

@Suppress("MemberVisibilityCanBePrivate")
class KotlinJsCompilation : AbstractKotlinCompilation<K2JSCompilerArguments>() {
Expand Down Expand Up @@ -45,6 +47,15 @@ class KotlinJsCompilation : AbstractKotlinCompilation<K2JSCompilerArguments>() {
HostEnvironment.kotlinStdLibJsJar
}

/**
* Path to the kotlin-dom-api-compat.klib
* If none is given, it will be searched for in the host
* process' classpaths
*/
var kotlinStdLibDomApi: File? by default {
HostEnvironment.kotlinDomApiCompatKlib
}

/**
* Generate TypeScript declarations .d.ts file alongside JS file. Available in IR backend only
*/
Expand Down Expand Up @@ -79,9 +90,10 @@ class KotlinJsCompilation : AbstractKotlinCompilation<K2JSCompilerArguments>() {
args.noStdlib = true

args.moduleKind = "commonjs"
args.outputFile = File(outputDir, outputFileName).absolutePath
args.outputDir = outputDir.absolutePath // -ir-output-dir
args.moduleName = Paths.get(outputFileName).nameWithoutExtension // -ir-output-name
args.sourceMapBaseDirs = jsClasspath().joinToString(separator = File.pathSeparator)
args.libraries = listOfNotNull(kotlinStdLibJsJar).joinToString(separator = ":")
args.libraries = listOfNotNull(kotlinStdLibJsJar, kotlinStdLibDomApi).joinToString(separator = File.pathSeparator)

args.irProduceKlibDir = irProduceKlibDir
args.irProduceKlibFile = irProduceKlibFile
Expand All @@ -91,7 +103,7 @@ class KotlinJsCompilation : AbstractKotlinCompilation<K2JSCompilerArguments>() {
args.irOnly = irOnly
args.irModuleName = irModuleName
args.generateDts = generateDts
args.useDeprecatedLegacyCompiler = useDeprecatedLegacyCompiler
args.forceDeprecatedLegacyCompilerUsage = useDeprecatedLegacyCompiler
}

/** Runs the compilation task */
Expand Down
2 changes: 1 addition & 1 deletion ksp/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.ksp_version = '1.8.0-1.0.8'
ext.ksp_version = '1.9.10-1.0.13'
}

dependencies {
Expand Down
12 changes: 11 additions & 1 deletion ksp/src/main/kotlin/com/tschuchort/compiletesting/Ksp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import org.jetbrains.kotlin.com.intellij.mock.MockProject
import org.jetbrains.kotlin.com.intellij.psi.PsiTreeChangeAdapter
import org.jetbrains.kotlin.com.intellij.psi.PsiTreeChangeListener
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
import org.jetbrains.kotlin.config.ApiVersion
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.config.LanguageVersion
import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl
import org.jetbrains.kotlin.resolve.jvm.extensions.AnalysisHandlerExtension
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
import java.io.File
Expand Down Expand Up @@ -169,6 +172,9 @@ private class KspCompileTestingComponentRegistrar(
this.allWarningsAsErrors = this@KspCompileTestingComponentRegistrar.allWarningsAsErrors
this.withCompilation = this@KspCompileTestingComponentRegistrar.withCompilation

this.languageVersionSettings =
LanguageVersionSettingsImpl(LanguageVersion.KOTLIN_1_9, ApiVersion.KOTLIN_1_9)

this.cachesDir = compilation.kspCachesDir.also {
it.deleteRecursively()
it.mkdirs()
Expand Down Expand Up @@ -216,7 +222,11 @@ private class KspCompileTestingComponentRegistrar(
val registrar = KspTestExtension(options, providers, messageCollectorBasedKSPLogger)
AnalysisHandlerExtension.registerExtension(project, registrar)
// Dummy extension point; Required by dropPsiCaches().
CoreApplicationEnvironment.registerExtensionPoint(project.extensionArea, PsiTreeChangeListener.EP.name, PsiTreeChangeAdapter::class.java)
CoreApplicationEnvironment.registerExtensionPoint(
project.extensionArea,
PsiTreeChangeListener.EP.name,
PsiTreeChangeAdapter::class.java
)
}
}

Expand Down