Skip to content
Merged
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
7 changes: 4 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
Expand All @@ -17,9 +18,9 @@ subprojects {

pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs = freeCompilerArgs + listOf("-progressive")
compilerOptions {
jvmTarget.set(JvmTarget.JVM_1_8)
freeCompilerArgs.add("-progressive")
}
}
}
Expand Down
14 changes: 11 additions & 3 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,17 @@ dependencies {
}

tasks.withType<KotlinCompile>().configureEach {
// https://github.com/tschuchortdev/kotlin-compile-testing/pull/63
kotlinOptions.freeCompilerArgs += "-Xno-optimized-callable-references"
kotlinOptions.freeCompilerArgs += "-Xskip-runtime-version-check"
val isTest = name.contains("test", ignoreCase = true)
compilerOptions {
freeCompilerArgs.addAll(
// https://github.com/tschuchortdev/kotlin-compile-testing/pull/63
"-Xno-optimized-callable-references",
"-Xskip-runtime-version-check",
)
if (isTest) {
freeCompilerArgs.add("-opt-in=org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi")
}
}
}

tasks.withType<Jar>().configureEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ import org.jetbrains.kotlin.cli.common.arguments.validateArguments
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector
import org.jetbrains.kotlin.cli.js.K2JSCompiler
import org.jetbrains.kotlin.cli.jvm.plugins.ServiceLoaderLite
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import org.jetbrains.kotlin.config.Services
import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.util.ServiceLoaderLite
import java.io.File
import java.io.OutputStream
import java.io.PrintStream
import java.lang.reflect.InvocationTargetException
import java.lang.reflect.ReflectPermission
import java.net.URI
import java.nio.file.Files
import java.nio.file.Paths
Expand All @@ -29,6 +28,7 @@ import java.nio.file.Paths
* functionality. Should not be used outside of this library as it is an
* implementation detail.
*/
@ExperimentalCompilerApi
abstract class AbstractKotlinCompilation<A : CommonCompilerArguments> internal constructor() {
/** Working directory for the compilation */
var workingDir: File by default {
Expand All @@ -49,10 +49,23 @@ abstract class AbstractKotlinCompilation<A : CommonCompilerArguments> internal c
*/
var pluginClasspaths: List<File> = emptyList()

@Deprecated(
"Use componentRegistrars instead",
ReplaceWith("componentRegistrars"),
DeprecationLevel.ERROR
)
var compilerPlugins: List<ComponentRegistrar> = emptyList()

/**
* Compiler plugins that should be added to the compilation
* Legacy [ComponentRegistrar] plugins that should be added to the compilation.
*/
var compilerPlugins: List<ComponentRegistrar> = emptyList()
@Deprecated("Migrate to ComponentPluginRegistrar and use componentPluginRegistrars instead")
var componentRegistrars: List<ComponentRegistrar> = emptyList()

/**
* [CompilerPluginRegistrars][CompilerPluginRegistrar] that should be added to the compilation.
*/
var compilerPluginRegistrars: List<CompilerPluginRegistrar> = emptyList()

/**
* Commandline processors for compiler plugins that should be added to the compilation
Expand Down Expand Up @@ -121,17 +134,6 @@ abstract class AbstractKotlinCompilation<A : CommonCompilerArguments> internal c
// Directory for input source files
protected val sourcesDir get() = workingDir.resolve("sources")

protected inline fun <reified T> CommonCompilerArguments.trySetDeprecatedOption(optionSimpleName: String, value: T) {
try {
this.javaClass.getMethod(JvmAbi.setterName(optionSimpleName), T::class.java).invoke(this, value)
} catch (e: ReflectiveOperationException) {
throw IllegalArgumentException(
"The deprecated option $optionSimpleName is no longer available in the kotlin version you are using",
e
)
}
}

protected fun commonArguments(args: A, configuration: (args: A) -> Unit): A {
args.pluginClasspaths = pluginClasspaths.map(File::getAbsolutePath).toTypedArray()

Expand Down Expand Up @@ -195,7 +197,8 @@ abstract class AbstractKotlinCompilation<A : CommonCompilerArguments> internal c
MainComponentRegistrar.ThreadLocalParameters(
listOf(),
KaptOptions.Builder(),
compilerPlugins,
componentRegistrars,
compilerPluginRegistrars,
supportsK2
)
)
Expand All @@ -216,9 +219,9 @@ abstract class AbstractKotlinCompilation<A : CommonCompilerArguments> internal c
be found by the Kotlin compiler's service loader. We add it only when the user has actually given
us ComponentRegistrar instances to be loaded by the MainComponentRegistrar because the experimental
K2 compiler doesn't support plugins yet. This way, users of K2 can prevent MainComponentRegistrar
from being loaded and crashing K2 by setting both [compilerPlugins] and [commandLineProcessors] to
from being loaded and crashing K2 by setting both [componentRegistrars] and [commandLineProcessors] to
the emptyList. */
if (compilerPlugins.isNotEmpty() || commandLineProcessors.isNotEmpty())
if (componentRegistrars.isNotEmpty() || commandLineProcessors.isNotEmpty())
arrayOf(getResourcesPath())
else emptyArray()
}
Expand Down Expand Up @@ -300,11 +303,11 @@ abstract class AbstractKotlinCompilation<A : CommonCompilerArguments> internal c
internal val internalMessageStreamAccess: PrintStream get() = internalMessageStream
}

@ExperimentalCompilerApi
internal fun convertKotlinExitCode(code: ExitCode) = when(code) {
ExitCode.OK -> KotlinCompilation.ExitCode.OK
ExitCode.OOM_ERROR,
ExitCode.OOM_ERROR -> throw OutOfMemoryError("Kotlin compiler ran out of memory")
ExitCode.INTERNAL_ERROR -> KotlinCompilation.ExitCode.INTERNAL_ERROR
ExitCode.COMPILATION_ERROR -> KotlinCompilation.ExitCode.COMPILATION_ERROR
ExitCode.SCRIPT_EXECUTION_ERROR -> KotlinCompilation.ExitCode.SCRIPT_EXECUTION_ERROR
ExitCode.OOM_ERROR -> throw OutOfMemoryError("Kotlin compiler ran out of memory")
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.jetbrains.kotlin.cli.jvm.config.JvmClasspathRoot
import org.jetbrains.kotlin.com.intellij.mock.MockProject
import org.jetbrains.kotlin.com.intellij.openapi.project.Project
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import org.jetbrains.kotlin.config.CommonConfigurationKeys
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.config.JVMConfigurationKeys
Expand All @@ -49,6 +50,7 @@ import org.jetbrains.kotlin.resolve.jvm.extensions.AnalysisHandlerExtension
import org.jetbrains.kotlin.resolve.jvm.extensions.PartialAnalysisHandlerExtension
import java.io.File

@ExperimentalCompilerApi
internal class KaptComponentRegistrar(
private val processors: List<IncrementalProcessor>,
private val kaptOptions: KaptOptions.Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import org.jetbrains.kotlin.config.JVMAssertionsMode
import org.jetbrains.kotlin.config.JvmDefaultMode
import org.jetbrains.kotlin.config.JvmTarget
Expand All @@ -44,6 +45,7 @@ typealias PluginId = String
typealias OptionName = String
typealias OptionValue = String

@ExperimentalCompilerApi
@Suppress("MemberVisibilityCanBePrivate")
class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
/** Arbitrary arguments to be passed to kapt */
Expand Down Expand Up @@ -92,7 +94,7 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
var noParamAssertions: Boolean = false

/** Generate nullability assertions for non-null Java expressions */
@Deprecated("Removed in latest Kotlin version")
@Deprecated("Removed in Kotlinc, this does nothing now.")
var strictJavaNullabilityAssertions: Boolean? = null

/** Disable optimizations */
Expand All @@ -104,7 +106,7 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
*
* {disable|enable}
*/
@Deprecated("Removed in latest Kotlin version")
@Deprecated("Removed in Kotlinc, this does nothing now.")
var constructorCallNormalizationMode: String? = null

/** Assert calls behaviour {always-enable|always-disable|jvm|legacy} */
Expand All @@ -120,13 +122,14 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
var useTypeTable: Boolean = false

/** Allow Kotlin runtime libraries of incompatible versions in the classpath */
@Deprecated("Removed in latest Kotlin version")
@Deprecated("Removed in Kotlinc, this does nothing now.")
var skipRuntimeVersionCheck: Boolean? = null

/** Path to JSON file to dump Java to Kotlin declaration mappings */
var declarationsOutputPath: File? = null

/** Combine modules for source files and binary dependencies into a single module */
@Deprecated("Removed in Kotlinc, this does nothing now.")
var singleModule: Boolean = false

/** Suppress the \"cannot access built-in declaration\" error (useful with -no-stdlib) */
Expand All @@ -148,7 +151,7 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
var supportCompatqualCheckerFrameworkAnnotations: String? = null

/** Do not throw NPE on explicit 'equals' call for null receiver of platform boxed primitive type */
@Deprecated("Removed in latest Kotlin version")
@Deprecated("Removed in Kotlinc, this does nothing now.")
var noExceptionOnExplicitEqualsForBoxedNull: Boolean? = null

/** Allow to use '@JvmDefault' annotation for JVM default method support.
Expand Down Expand Up @@ -333,17 +336,8 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
args.noParamAssertions = noParamAssertions
args.noReceiverAssertions = noReceiverAssertions

// TODO: Remove after kotlin 1.6.30
if(strictJavaNullabilityAssertions != null)
args.trySetDeprecatedOption("strictJavaNullabilityAssertions", strictJavaNullabilityAssertions)

args.noOptimize = noOptimize

// TODO: Remove after kotlin 1.6.30
if(constructorCallNormalizationMode != null)
args.trySetDeprecatedOption("constructorCallNormalizationMode", constructorCallNormalizationMode)


if(assertionsMode != null)
args.assertionsMode = assertionsMode

Expand All @@ -356,8 +350,6 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
if(declarationsOutputPath != null)
args.declarationsOutputPath = declarationsOutputPath!!.toString()

args.singleModule = singleModule

if(javacArguments.isNotEmpty())
args.javacArguments = javacArguments.toTypedArray()

Expand All @@ -374,16 +366,8 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
if(scriptResolverEnvironment.isNotEmpty())
args.scriptResolverEnvironment = scriptResolverEnvironment.map { (key, value) -> "$key=\"$value\"" }.toTypedArray()

// TODO: Remove after kotlin 1.6.30
if(noExceptionOnExplicitEqualsForBoxedNull != null)
args.trySetDeprecatedOption("noExceptionOnExplicitEqualsForBoxedNull", noExceptionOnExplicitEqualsForBoxedNull)

// TODO: Remove after kotlin 1.6.30
if(skipRuntimeVersionCheck != null)
args.trySetDeprecatedOption("skipRuntimeVersionCheck", skipRuntimeVersionCheck)

args.javaPackagePrefix = javaPackagePrefix
args.suppressMissingBuiltinsError = suppressMissingBuiltinsError
args.javaPackagePrefix = javaPackagePrefix
args.suppressMissingBuiltinsError = suppressMissingBuiltinsError
}

/** Performs the 1st and 2nd compilation step to generate stubs and run annotation processors */
Expand Down Expand Up @@ -426,7 +410,8 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
MainComponentRegistrar.ThreadLocalParameters(
annotationProcessors.map { IncrementalProcessor(it, DeclaredProcType.NON_INCREMENTAL, kaptLogger) },
kaptOptions,
compilerPlugins,
componentRegistrars,
compilerPluginRegistrars,
supportsK2,
)
)
Expand Down Expand Up @@ -705,6 +690,7 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
* this.classpaths += previousResult.outputDirectory
* ```
*/
@ExperimentalCompilerApi
fun KotlinCompilation.addPreviousResultToClasspath(
previousResult: KotlinCompilation.Result
): KotlinCompilation = apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package com.tschuchort.compiletesting

import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
import org.jetbrains.kotlin.cli.js.K2JSCompiler
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import java.io.*

@ExperimentalCompilerApi
@Suppress("MemberVisibilityCanBePrivate")
class KotlinJsCompilation : AbstractKotlinCompilation<K2JSCompilerArguments>() {

Expand All @@ -19,7 +21,7 @@ class KotlinJsCompilation : AbstractKotlinCompilation<K2JSCompilerArguments>() {
var irProduceKlibFile: Boolean = false

/** Generates JS file using IR backend. Also disables pre-IR backend */
var irProduceJs: Boolean = false
var irProduceJs: Boolean = true

/** Perform experimental dead code elimination */
var irDce: Boolean = false
Expand All @@ -28,7 +30,7 @@ class KotlinJsCompilation : AbstractKotlinCompilation<K2JSCompilerArguments>() {
var irDcePrintReachabilityInfo: Boolean = false

/** Disables pre-IR backend */
var irOnly: Boolean = false
var irOnly: Boolean = true

/** Specify a compilation module name for IR backend */
var irModuleName: String? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import com.google.auto.service.AutoService
import org.jetbrains.kotlin.compiler.plugin.AbstractCliOption
import org.jetbrains.kotlin.compiler.plugin.CliOption
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import org.jetbrains.kotlin.config.CompilerConfiguration
import java.util.*

@ExperimentalCompilerApi
@AutoService(CommandLineProcessor::class)
internal class MainCommandLineProcessor : CommandLineProcessor {
override val pluginId: String = Companion.pluginId
Expand Down
Loading