Refactoring parts related to passing services to compiler in daemon, adding uniform support for cancellation check and lookup tracking
Original commit: 4b1601974f
This commit is contained in:
@@ -27,25 +27,23 @@ import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
|
|||||||
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
||||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
|
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
|
||||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||||
|
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.ERROR
|
||||||
|
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.INFO
|
||||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollectorUtil
|
import org.jetbrains.kotlin.cli.common.messages.MessageCollectorUtil
|
||||||
import org.jetbrains.kotlin.config.CompilerSettings
|
import org.jetbrains.kotlin.config.CompilerSettings
|
||||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache
|
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents
|
||||||
import org.jetbrains.kotlin.modules.TargetId
|
import org.jetbrains.kotlin.progress.CompilationCanceledStatus
|
||||||
import org.jetbrains.kotlin.rmi.*
|
import org.jetbrains.kotlin.rmi.CompilerId
|
||||||
import org.jetbrains.kotlin.rmi.kotlinr.DaemonReportCategory
|
import org.jetbrains.kotlin.rmi.configureDaemonJVMOptions
|
||||||
import org.jetbrains.kotlin.rmi.kotlinr.DaemonReportMessage
|
import org.jetbrains.kotlin.rmi.configureDaemonOptions
|
||||||
import org.jetbrains.kotlin.rmi.kotlinr.DaemonReportingTargets
|
import org.jetbrains.kotlin.rmi.isDaemonEnabled
|
||||||
import org.jetbrains.kotlin.rmi.kotlinr.KotlinCompilerClient
|
import org.jetbrains.kotlin.rmi.kotlinr.*
|
||||||
import org.jetbrains.kotlin.utils.*
|
import org.jetbrains.kotlin.utils.rethrow
|
||||||
|
|
||||||
import java.io.*
|
import java.io.*
|
||||||
import java.lang.reflect.Field
|
import java.lang.reflect.Field
|
||||||
import java.lang.reflect.Modifier
|
import java.lang.reflect.Modifier
|
||||||
import java.util.ArrayList
|
import java.util.*
|
||||||
|
|
||||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.ERROR
|
|
||||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.INFO
|
|
||||||
|
|
||||||
public object KotlinCompilerRunner {
|
public object KotlinCompilerRunner {
|
||||||
private val K2JVM_COMPILER = "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler"
|
private val K2JVM_COMPILER = "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler"
|
||||||
@@ -58,14 +56,12 @@ public object KotlinCompilerRunner {
|
|||||||
compilerSettings: CompilerSettings,
|
compilerSettings: CompilerSettings,
|
||||||
messageCollector: MessageCollector,
|
messageCollector: MessageCollector,
|
||||||
environment: CompilerEnvironment,
|
environment: CompilerEnvironment,
|
||||||
incrementalCaches: Map<TargetId, IncrementalCache>?,
|
|
||||||
moduleFile: File,
|
moduleFile: File,
|
||||||
collector: OutputItemsCollector) {
|
collector: OutputItemsCollector) {
|
||||||
val arguments = mergeBeans(commonArguments, k2jvmArguments)
|
val arguments = mergeBeans(commonArguments, k2jvmArguments)
|
||||||
setupK2JvmArguments(moduleFile, arguments)
|
setupK2JvmArguments(moduleFile, arguments)
|
||||||
|
|
||||||
runCompiler(K2JVM_COMPILER, arguments, compilerSettings.additionalArguments, messageCollector, collector, environment,
|
runCompiler(K2JVM_COMPILER, arguments, compilerSettings.additionalArguments, messageCollector, collector, environment)
|
||||||
incrementalCaches)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun runK2JsCompiler(
|
public fun runK2JsCompiler(
|
||||||
@@ -74,7 +70,6 @@ public object KotlinCompilerRunner {
|
|||||||
compilerSettings: CompilerSettings,
|
compilerSettings: CompilerSettings,
|
||||||
messageCollector: MessageCollector,
|
messageCollector: MessageCollector,
|
||||||
environment: CompilerEnvironment,
|
environment: CompilerEnvironment,
|
||||||
incrementalCaches: Map<TargetId, IncrementalCache>?,
|
|
||||||
collector: OutputItemsCollector,
|
collector: OutputItemsCollector,
|
||||||
sourceFiles: Collection<File>,
|
sourceFiles: Collection<File>,
|
||||||
libraryFiles: List<String>,
|
libraryFiles: List<String>,
|
||||||
@@ -82,8 +77,7 @@ public object KotlinCompilerRunner {
|
|||||||
val arguments = mergeBeans(commonArguments, k2jsArguments)
|
val arguments = mergeBeans(commonArguments, k2jsArguments)
|
||||||
setupK2JsArguments(outputFile, sourceFiles, libraryFiles, arguments)
|
setupK2JsArguments(outputFile, sourceFiles, libraryFiles, arguments)
|
||||||
|
|
||||||
runCompiler(K2JS_COMPILER, arguments, compilerSettings.additionalArguments, messageCollector, collector, environment,
|
runCompiler(K2JS_COMPILER, arguments, compilerSettings.additionalArguments, messageCollector, collector, environment)
|
||||||
incrementalCaches)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun processCompilerOutput(
|
private fun processCompilerOutput(
|
||||||
@@ -109,8 +103,7 @@ public object KotlinCompilerRunner {
|
|||||||
additionalArguments: String,
|
additionalArguments: String,
|
||||||
messageCollector: MessageCollector,
|
messageCollector: MessageCollector,
|
||||||
collector: OutputItemsCollector,
|
collector: OutputItemsCollector,
|
||||||
environment: CompilerEnvironment,
|
environment: CompilerEnvironment) {
|
||||||
incrementalCaches: Map<TargetId, IncrementalCache>?) {
|
|
||||||
try {
|
try {
|
||||||
messageCollector.report(INFO, "Using kotlin-home = " + environment.kotlinPaths.homePath, CompilerMessageLocation.NO_LOCATION)
|
messageCollector.report(INFO, "Using kotlin-home = " + environment.kotlinPaths.homePath, CompilerMessageLocation.NO_LOCATION)
|
||||||
|
|
||||||
@@ -119,7 +112,7 @@ public object KotlinCompilerRunner {
|
|||||||
|
|
||||||
val argsArray = argumentsList.toTypedArray()
|
val argsArray = argumentsList.toTypedArray()
|
||||||
|
|
||||||
if (!tryCompileWithDaemon(messageCollector, collector, environment, incrementalCaches, argsArray)) {
|
if (!tryCompileWithDaemon(messageCollector, collector, environment, argsArray)) {
|
||||||
// otherwise fallback to in-process
|
// otherwise fallback to in-process
|
||||||
|
|
||||||
val stream = ByteArrayOutputStream()
|
val stream = ByteArrayOutputStream()
|
||||||
@@ -139,14 +132,12 @@ public object KotlinCompilerRunner {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun tryCompileWithDaemon(
|
private fun tryCompileWithDaemon(messageCollector: MessageCollector,
|
||||||
messageCollector: MessageCollector,
|
collector: OutputItemsCollector,
|
||||||
collector: OutputItemsCollector,
|
environment: CompilerEnvironment,
|
||||||
environment: CompilerEnvironment,
|
argsArray: Array<String>): Boolean {
|
||||||
incrementalCaches: Map<TargetId, IncrementalCache>?,
|
|
||||||
argsArray: Array<String>): Boolean {
|
|
||||||
|
|
||||||
if (incrementalCaches != null && isDaemonEnabled()) {
|
if (isDaemonEnabled()) {
|
||||||
val libPath = CompilerRunnerUtil.getLibPath(environment.kotlinPaths, messageCollector)
|
val libPath = CompilerRunnerUtil.getLibPath(environment.kotlinPaths, messageCollector)
|
||||||
// TODO: it may be a good idea to cache the compilerId, since making it means calculating digest over jar(s) and if \\
|
// TODO: it may be a good idea to cache the compilerId, since making it means calculating digest over jar(s) and if \\
|
||||||
// the lifetime of JPS process is small anyway, we can neglect the probability of changed compiler
|
// the lifetime of JPS process is small anyway, we can neglect the probability of changed compiler
|
||||||
@@ -173,7 +164,11 @@ public object KotlinCompilerRunner {
|
|||||||
val compilerOut = ByteArrayOutputStream()
|
val compilerOut = ByteArrayOutputStream()
|
||||||
val daemonOut = ByteArrayOutputStream()
|
val daemonOut = ByteArrayOutputStream()
|
||||||
|
|
||||||
val res = KotlinCompilerClient.incrementalCompile(daemon, argsArray, incrementalCaches, compilerOut, daemonOut)
|
val services = CompilationServices(
|
||||||
|
incrementalCompilationComponents = environment.services.get(IncrementalCompilationComponents::class.java),
|
||||||
|
compilationCanceledStatus = environment.services.get(CompilationCanceledStatus::class.java))
|
||||||
|
|
||||||
|
val res = KotlinCompilerClient.incrementalCompile(daemon, argsArray, services, compilerOut, daemonOut)
|
||||||
|
|
||||||
processCompilerOutput(messageCollector, collector, compilerOut, res.toString())
|
processCompilerOutput(messageCollector, collector, compilerOut, res.toString())
|
||||||
BufferedReader(StringReader(daemonOut.toString())).forEachLine {
|
BufferedReader(StringReader(daemonOut.toString())).forEachLine {
|
||||||
|
|||||||
@@ -318,10 +318,7 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return compileToJvm(allCompiledFiles, chunk, commonArguments, context, dirtyFilesHolder, environment,
|
return compileToJvm(allCompiledFiles, chunk, commonArguments, context, dirtyFilesHolder, environment, filesToCompile, messageCollector)
|
||||||
incrementalCaches.mapKeysTo(HashMap<TargetId, IncrementalCache>(incrementalCaches.size()),
|
|
||||||
{ TargetId(it.getKey()) }),
|
|
||||||
filesToCompile, messageCollector)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createCompileEnvironment(
|
private fun createCompileEnvironment(
|
||||||
@@ -519,7 +516,7 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
|
|||||||
val compilerSettings = JpsKotlinCompilerSettings.getCompilerSettings(project)
|
val compilerSettings = JpsKotlinCompilerSettings.getCompilerSettings(project)
|
||||||
val k2JsArguments = JpsKotlinCompilerSettings.getK2JsCompilerArguments(project)
|
val k2JsArguments = JpsKotlinCompilerSettings.getK2JsCompilerArguments(project)
|
||||||
|
|
||||||
KotlinCompilerRunner.runK2JsCompiler(commonArguments, k2JsArguments, compilerSettings, messageCollector, environment, incrementalCaches, outputItemCollector, sourceFiles, libraryFiles, outputFile)
|
KotlinCompilerRunner.runK2JsCompiler(commonArguments, k2JsArguments, compilerSettings, messageCollector, environment, outputItemCollector, sourceFiles, libraryFiles, outputFile)
|
||||||
return outputItemCollector
|
return outputItemCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -542,7 +539,6 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
|
|||||||
context: CompileContext,
|
context: CompileContext,
|
||||||
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>,
|
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>,
|
||||||
environment: CompilerEnvironment,
|
environment: CompilerEnvironment,
|
||||||
incrementalCaches: MutableMap<TargetId, IncrementalCache>?,
|
|
||||||
filesToCompile: MultiMap<ModuleBuildTarget, File>, messageCollector: MessageCollectorAdapter
|
filesToCompile: MultiMap<ModuleBuildTarget, File>, messageCollector: MessageCollectorAdapter
|
||||||
): OutputItemsCollectorImpl? {
|
): OutputItemsCollectorImpl? {
|
||||||
val outputItemCollector = OutputItemsCollectorImpl()
|
val outputItemCollector = OutputItemsCollectorImpl()
|
||||||
@@ -586,7 +582,7 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
|
|||||||
+ (if (totalRemovedFiles == 0) "" else " ($totalRemovedFiles removed files)")
|
+ (if (totalRemovedFiles == 0) "" else " ($totalRemovedFiles removed files)")
|
||||||
+ " in " + filesToCompile.keySet().map { it.getPresentableName() }.join())
|
+ " in " + filesToCompile.keySet().map { it.getPresentableName() }.join())
|
||||||
|
|
||||||
KotlinCompilerRunner.runK2JvmCompiler(commonArguments, k2JvmArguments, compilerSettings, messageCollector, environment, incrementalCaches, moduleFile, outputItemCollector)
|
KotlinCompilerRunner.runK2JvmCompiler(commonArguments, k2JvmArguments, compilerSettings, messageCollector, environment, moduleFile, outputItemCollector)
|
||||||
moduleFile.delete()
|
moduleFile.delete()
|
||||||
|
|
||||||
return outputItemCollector
|
return outputItemCollector
|
||||||
|
|||||||
Reference in New Issue
Block a user