diff --git a/README.md b/README.md index c2fa8318..1e0c657c 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/build.gradle b/build.gradle index d1699357..5442f979 100644 --- a/build.gradle +++ b/build.gradle @@ -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() diff --git a/core/build.gradle b/core/build.gradle index b62554f5..2553239d 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -1,3 +1,4 @@ +import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType plugins { id "com.github.gmazzo.buildconfig" version "3.1.0" @@ -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" @@ -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 diff --git a/core/src/main/kotlin/com/tschuchort/compiletesting/AbstractKotlinCompilation.kt b/core/src/main/kotlin/com/tschuchort/compiletesting/AbstractKotlinCompilation.kt index 76628080..c416d0f6 100644 --- a/core/src/main/kotlin/com/tschuchort/compiletesting/AbstractKotlinCompilation.kt +++ b/core/src/main/kotlin/com/tschuchort/compiletesting/AbstractKotlinCompilation.kt @@ -36,8 +36,9 @@ abstract class AbstractKotlinCompilation 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 } /** diff --git a/core/src/main/kotlin/com/tschuchort/compiletesting/HostEnvironment.kt b/core/src/main/kotlin/com/tschuchort/compiletesting/HostEnvironment.kt index 428553f7..be6046f4 100644 --- a/core/src/main/kotlin/com/tschuchort/compiletesting/HostEnvironment.kt +++ b/core/src/main/kotlin/com/tschuchort/compiletesting/HostEnvironment.kt @@ -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")) } @@ -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 */ @@ -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) } } diff --git a/core/src/main/kotlin/com/tschuchort/compiletesting/KotlinCompilation.kt b/core/src/main/kotlin/com/tschuchort/compiletesting/KotlinCompilation.kt index eecc8c40..93612d1b 100644 --- a/core/src/main/kotlin/com/tschuchort/compiletesting/KotlinCompilation.kt +++ b/core/src/main/kotlin/com/tschuchort/compiletesting/KotlinCompilation.kt @@ -71,6 +71,7 @@ class KotlinCompilation : AbstractKotlinCompilation() { 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 */ @@ -304,7 +305,6 @@ class KotlinCompilation : AbstractKotlinCompilation() { args.jvmTarget = jvmTarget args.javaParameters = javaParameters - args.useIR = useIR args.useOldBackend = useOldBackend if(javaModulePath != null) diff --git a/core/src/main/kotlin/com/tschuchort/compiletesting/KotlinJsCompilation.kt b/core/src/main/kotlin/com/tschuchort/compiletesting/KotlinJsCompilation.kt index b79dd312..a916ec64 100644 --- a/core/src/main/kotlin/com/tschuchort/compiletesting/KotlinJsCompilation.kt +++ b/core/src/main/kotlin/com/tschuchort/compiletesting/KotlinJsCompilation.kt @@ -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() { @@ -45,6 +47,15 @@ class KotlinJsCompilation : AbstractKotlinCompilation() { 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 */ @@ -79,9 +90,10 @@ class KotlinJsCompilation : AbstractKotlinCompilation() { 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 @@ -91,7 +103,7 @@ class KotlinJsCompilation : AbstractKotlinCompilation() { args.irOnly = irOnly args.irModuleName = irModuleName args.generateDts = generateDts - args.useDeprecatedLegacyCompiler = useDeprecatedLegacyCompiler + args.forceDeprecatedLegacyCompilerUsage = useDeprecatedLegacyCompiler } /** Runs the compilation task */ diff --git a/ksp/build.gradle b/ksp/build.gradle index 49fd1a3e..0528bf9a 100644 --- a/ksp/build.gradle +++ b/ksp/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.ksp_version = '1.8.0-1.0.8' + ext.ksp_version = '1.9.10-1.0.13' } dependencies { diff --git a/ksp/src/main/kotlin/com/tschuchort/compiletesting/Ksp.kt b/ksp/src/main/kotlin/com/tschuchort/compiletesting/Ksp.kt index a628917d..dce66094 100644 --- a/ksp/src/main/kotlin/com/tschuchort/compiletesting/Ksp.kt +++ b/ksp/src/main/kotlin/com/tschuchort/compiletesting/Ksp.kt @@ -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 @@ -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() @@ -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 + ) } }