Refactor messages sending
This commit is contained in:
+33
@@ -0,0 +1,33 @@
|
||||
package org.jetbrains.kotlin.compilerRunner
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.jetbrains.kotlin.daemon.common.CompilationResult
|
||||
import org.jetbrains.kotlin.daemon.common.CompilationResultsStorage
|
||||
import org.jetbrains.kotlin.daemon.common.SOCKET_ANY_FREE_PORT
|
||||
import org.jetbrains.kotlin.daemon.report.CompileIterationResult
|
||||
import org.jetbrains.kotlin.gradle.plugin.kotlinDebug
|
||||
import org.jetbrains.kotlin.incremental.pathsAsStringRelativeTo
|
||||
import java.io.Serializable
|
||||
import java.rmi.RemoteException
|
||||
import java.rmi.server.UnicastRemoteObject
|
||||
|
||||
internal class GradleCompilationResultsStorage(project: Project): CompilationResultsStorage, UnicastRemoteObject(SOCKET_ANY_FREE_PORT) {
|
||||
private val log = project.logger
|
||||
private val projectRootFile = project.rootProject.projectDir
|
||||
|
||||
@Throws(RemoteException::class)
|
||||
override fun store(compilationResult: Int, value: Serializable) {
|
||||
if (compilationResult == CompilationResult.IC_COMPILE_ITERATION.code) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val compileIterationResult = value as? CompileIterationResult
|
||||
if (compileIterationResult != null) {
|
||||
val sourceFiles = compileIterationResult.sourceFiles
|
||||
if (sourceFiles.any()) {
|
||||
log.kotlinDebug { "compile iteration: ${sourceFiles.pathsAsStringRelativeTo(projectRootFile)}" }
|
||||
}
|
||||
val exitCode = compileIterationResult.exitCode
|
||||
log.kotlinDebug { "compiler exit code: $exitCode" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
-46
@@ -6,15 +6,12 @@ import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||
import org.jetbrains.kotlin.daemon.common.*
|
||||
import org.jetbrains.kotlin.daemon.incremental.CompileIterationResult
|
||||
import org.jetbrains.kotlin.daemon.incremental.IncrementalCompilationSeverity
|
||||
import org.jetbrains.kotlin.daemon.incremental.toDirtyData
|
||||
import org.jetbrains.kotlin.daemon.incremental.toSimpleDirtyData
|
||||
import org.jetbrains.kotlin.gradle.plugin.kotlinDebug
|
||||
import org.jetbrains.kotlin.gradle.plugin.kotlinWarn
|
||||
import org.jetbrains.kotlin.incremental.DirtyData
|
||||
import org.jetbrains.kotlin.incremental.multiproject.ArtifactDifference
|
||||
import org.jetbrains.kotlin.incremental.pathsAsStringRelativeTo
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
||||
import java.io.File
|
||||
import java.io.Serializable
|
||||
@@ -28,28 +25,34 @@ internal open class GradleCompilerServicesFacadeImpl(
|
||||
) : UnicastRemoteObject(port), CompilerServicesFacadeBase, Remote {
|
||||
protected val log: Logger = project.logger
|
||||
|
||||
override fun report(category: ReportCategory, severity: Int, message: String?, attachment: Serializable?) {
|
||||
when (category) {
|
||||
ReportCategory.COMPILER_MESSAGE -> {
|
||||
val compilerSeverity = CompilerMessageSeverity.values().firstOrNull { it.value == severity }
|
||||
override fun report(category: Int, severity: Int, message: String?, attachment: Serializable?) {
|
||||
val reportCategory = ReportCategory.fromCode(category)
|
||||
|
||||
if (compilerSeverity != null && message != null && attachment is CompilerMessageLocation) {
|
||||
compilerMessageCollector.report(compilerSeverity, message, attachment)
|
||||
when (reportCategory) {
|
||||
ReportCategory.COMPILER_MESSAGE -> {
|
||||
if (message != null && attachment is CompilerMessageAttachment) {
|
||||
compilerMessageCollector.report(attachment.severity, message, attachment.location)
|
||||
}
|
||||
else {
|
||||
reportUnexpectedMessage(category, severity, message, attachment)
|
||||
}
|
||||
}
|
||||
ReportCategory.IC_MESSAGE -> {
|
||||
log.kotlinDebug { "[IC] $message" }
|
||||
}
|
||||
ReportCategory.DAEMON_MESSAGE -> {
|
||||
log.kotlinDebug { "[DAEMON] $message" }
|
||||
}
|
||||
ReportCategory.OUTPUT_MESSAGE -> {
|
||||
compilerMessageCollector.report(CompilerMessageSeverity.OUTPUT, message!!, CompilerMessageLocation.NO_LOCATION)
|
||||
}
|
||||
else -> {
|
||||
reportUnexpectedMessage(category, severity, message, attachment)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected fun reportUnexpectedMessage(category: ReportCategory, severity: Int, message: String?, attachment: Serializable?) {
|
||||
protected fun reportUnexpectedMessage(category: Int, severity: Int, message: String?, attachment: Serializable?) {
|
||||
// todo add assert to tests
|
||||
log.kotlinWarn("Received unexpected message from compiler daemon: category=$category, severity=$severity, message='$message', attachment=$attachment")
|
||||
}
|
||||
@@ -62,42 +65,6 @@ internal class GradleIncrementalCompilerServicesFacadeImpl(
|
||||
) : GradleCompilerServicesFacadeImpl(project, environment.messageCollector, port),
|
||||
IncrementalCompilerServicesFacade {
|
||||
|
||||
private val projectRootFile = project.rootProject.projectDir
|
||||
|
||||
override fun report(category: ReportCategory, severity: Int, message: String?, attachment: Serializable?) {
|
||||
when (category) {
|
||||
ReportCategory.INCREMENTAL_COMPILATION -> {
|
||||
val icSeverity = IncrementalCompilationSeverity.values().firstOrNull { it.value == severity }
|
||||
when (icSeverity) {
|
||||
IncrementalCompilationSeverity.COMPILED_FILES -> {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val compileIterationResult = attachment as? CompileIterationResult
|
||||
if (compileIterationResult == null) {
|
||||
reportUnexpectedMessage(category, severity, message, attachment)
|
||||
}
|
||||
else {
|
||||
val sourceFiles = compileIterationResult.sourceFiles
|
||||
if (sourceFiles.any()) {
|
||||
log.kotlinDebug { "compile iteration: ${sourceFiles.pathsAsStringRelativeTo(projectRootFile)}" }
|
||||
}
|
||||
val exitCode = compileIterationResult.exitCode
|
||||
log.kotlinDebug { "compiler exit code: $exitCode" }
|
||||
}
|
||||
}
|
||||
IncrementalCompilationSeverity.LOGGING -> {
|
||||
log.kotlinDebug { "[IC] $message" }
|
||||
}
|
||||
else -> {
|
||||
reportUnexpectedMessage(category, severity, message, attachment)
|
||||
}
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
super.report(category, severity, message, attachment)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun hasAnnotationsFileUpdater(): Boolean =
|
||||
environment.kaptAnnotationsFileUpdater != null
|
||||
|
||||
|
||||
+29
-39
@@ -24,16 +24,15 @@ import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
import org.jetbrains.kotlin.config.Services
|
||||
import org.jetbrains.kotlin.daemon.client.RemoteOutputStreamServer
|
||||
import org.jetbrains.kotlin.daemon.common.*
|
||||
import org.jetbrains.kotlin.daemon.incremental.IncrementalCompilationSeverity
|
||||
import org.jetbrains.kotlin.daemon.common.CompilationResult
|
||||
import org.jetbrains.kotlin.gradle.plugin.ParentLastURLClassLoader
|
||||
import org.jetbrains.kotlin.gradle.plugin.kotlinDebug
|
||||
import org.jetbrains.kotlin.incremental.*
|
||||
import java.io.*
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
import java.io.PrintStream
|
||||
import kotlin.concurrent.thread
|
||||
|
||||
internal const val KOTLIN_COMPILER_EXECUTION_STRATEGY_PROPERTY = "kotlin.compiler.execution.strategy"
|
||||
@@ -162,14 +161,18 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil
|
||||
K2METADATA_COMPILER -> CompileService.TargetPlatform.METADATA
|
||||
else -> throw IllegalArgumentException("Unknown compiler type $compilerClassName")
|
||||
}
|
||||
|
||||
val verbose = environment.compilerArgs.verbose
|
||||
val compilationOptions = CompilationOptions(
|
||||
reportingFilters = getNonIncrementalReportingFilters(environment.compilerArgs.verbose),
|
||||
compilerMode = CompileService.CompilerMode.NON_INCREMENTAL_COMPILER,
|
||||
targetPlatform = targetPlatform)
|
||||
targetPlatform = targetPlatform,
|
||||
reportCategories = reportCategories(verbose),
|
||||
reportSeverity = reportSeverity(verbose),
|
||||
requestedCompilationResults = emptyArray())
|
||||
val servicesFacade = GradleCompilerServicesFacadeImpl(project, environment.messageCollector)
|
||||
|
||||
val res = withDaemon(environment, retryOnConnectionError = true) { daemon, sessionId ->
|
||||
daemon.compile(sessionId, environment.compilerArgs, compilationOptions, servicesFacade)
|
||||
daemon.compile(sessionId, environment.compilerArgs, compilationOptions, servicesFacade, compilationResultsStorage = null)
|
||||
}
|
||||
|
||||
val exitCode = res?.get()?.let { exitCodeFromProcessExitCode(it) }
|
||||
@@ -183,6 +186,7 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil
|
||||
private fun incrementalCompilationWithDaemon(environment: GradleIncrementalCompilerEnvironment): ExitCode? {
|
||||
val knownChangedFiles = environment.changedFiles as? ChangedFiles.Known
|
||||
|
||||
val verbose = environment.compilerArgs.verbose
|
||||
val compilationOptions = IncrementalCompilationOptions(
|
||||
areFileChangesKnown = knownChangedFiles != null,
|
||||
modifiedFiles = knownChangedFiles?.modified,
|
||||
@@ -190,15 +194,16 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil
|
||||
workingDir = environment.workingDir,
|
||||
customCacheVersion = GRADLE_CACHE_VERSION,
|
||||
customCacheVersionFileName = GRADLE_CACHE_VERSION_FILE_NAME,
|
||||
reportingFilters = getNonIncrementalReportingFilters(environment.compilerArgs.verbose) +
|
||||
getIncrementalReportingFilters(environment.compilerArgs.verbose),
|
||||
reportedCategories = reportCategories(verbose),
|
||||
reportedSeverity = reportSeverity(verbose),
|
||||
requestedCompilationResults = arrayOf(CompilationResult.IC_COMPILE_ITERATION.code),
|
||||
compilerMode = CompileService.CompilerMode.INCREMENTAL_COMPILER,
|
||||
targetPlatform = CompileService.TargetPlatform.JVM
|
||||
)
|
||||
val servicesFacade = GradleIncrementalCompilerServicesFacadeImpl(project, environment)
|
||||
|
||||
val res = withDaemon(environment, retryOnConnectionError = true) { daemon, sessionId ->
|
||||
daemon.compile(sessionId, environment.compilerArgs, compilationOptions, servicesFacade)
|
||||
daemon.compile(sessionId, environment.compilerArgs, compilationOptions, servicesFacade, GradleCompilationResultsStorage(project))
|
||||
}
|
||||
|
||||
val exitCode = res?.get()?.let { exitCodeFromProcessExitCode(it) }
|
||||
@@ -209,36 +214,21 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil
|
||||
return exitCode
|
||||
}
|
||||
|
||||
private fun getNonIncrementalReportingFilters(verbose: Boolean): List<ReportingFilter> {
|
||||
val result = ArrayList<ReportingFilter>()
|
||||
|
||||
val compilerMessagesSeverities = ArrayList<Int>().apply {
|
||||
add(CompilerMessageSeverity.ERROR.value)
|
||||
add(CompilerMessageSeverity.EXCEPTION.value)
|
||||
add(CompilerMessageSeverity.WARNING.value)
|
||||
add(CompilerMessageSeverity.INFO.value)
|
||||
|
||||
if (verbose) {
|
||||
add(CompilerMessageSeverity.OUTPUT.value)
|
||||
add(CompilerMessageSeverity.LOGGING.value)
|
||||
private fun reportCategories(verbose: Boolean): Array<Int> =
|
||||
if (!verbose) {
|
||||
arrayOf(ReportCategory.COMPILER_MESSAGE.code)
|
||||
}
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
result.add(ReportingFilter(ReportCategory.DAEMON_MESSAGE, emptyList()))
|
||||
}
|
||||
|
||||
val compilerMessagesFilter = ReportingFilter(ReportCategory.COMPILER_MESSAGE, compilerMessagesSeverities)
|
||||
result.add(compilerMessagesFilter)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
private fun getIncrementalReportingFilters(verbose: Boolean) =
|
||||
if (verbose) {
|
||||
listOf(ReportingFilter(ReportCategory.INCREMENTAL_COMPILATION, listOf(IncrementalCompilationSeverity.COMPILED_FILES.value, IncrementalCompilationSeverity.LOGGING.value)))
|
||||
else {
|
||||
ReportCategory.values().map { it.code }.toTypedArray()
|
||||
}
|
||||
|
||||
private fun reportSeverity(verbose: Boolean): Int =
|
||||
if (!verbose) {
|
||||
ReportSeverity.INFO.code
|
||||
}
|
||||
else {
|
||||
ReportSeverity.DEBUG.code
|
||||
}
|
||||
else emptyList()
|
||||
|
||||
private fun compileOutOfProcess(
|
||||
argsArray: Array<String>,
|
||||
|
||||
Reference in New Issue
Block a user