Refactor messages sending
This commit is contained in:
+6
-24
@@ -19,30 +19,12 @@ package org.jetbrains.kotlin.cli.common.messages;
|
|||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
|
||||||
public enum CompilerMessageSeverity {
|
public enum CompilerMessageSeverity {
|
||||||
ERROR(0),
|
ERROR,
|
||||||
EXCEPTION(5),
|
EXCEPTION,
|
||||||
WARNING(10),
|
WARNING,
|
||||||
INFO(15),
|
INFO,
|
||||||
OUTPUT(20),
|
OUTPUT,
|
||||||
LOGGING(25);
|
LOGGING;
|
||||||
|
|
||||||
private final int value;
|
|
||||||
|
|
||||||
CompilerMessageSeverity(int value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
static CompilerMessageSeverity fromValue(int value) {
|
|
||||||
for (CompilerMessageSeverity severity : CompilerMessageSeverity.values()) {
|
|
||||||
if (severity.value == value) return severity;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final EnumSet<CompilerMessageSeverity> ERRORS = EnumSet.of(ERROR, EXCEPTION);
|
public static final EnumSet<CompilerMessageSeverity> ERRORS = EnumSet.of(ERROR, EXCEPTION);
|
||||||
public static final EnumSet<CompilerMessageSeverity> VERBOSE = EnumSet.of(OUTPUT, LOGGING);
|
public static final EnumSet<CompilerMessageSeverity> VERBOSE = EnumSet.of(OUTPUT, LOGGING);
|
||||||
|
|||||||
+7
-3
@@ -22,7 +22,9 @@ import java.io.Serializable
|
|||||||
open class CompilationOptions(
|
open class CompilationOptions(
|
||||||
val compilerMode: CompileService.CompilerMode,
|
val compilerMode: CompileService.CompilerMode,
|
||||||
val targetPlatform: CompileService.TargetPlatform,
|
val targetPlatform: CompileService.TargetPlatform,
|
||||||
val reportingFilters: List<ReportingFilter>
|
val reportCategories: Array<Int>,
|
||||||
|
val reportSeverity: Int,
|
||||||
|
val requestedCompilationResults: Array<Int>
|
||||||
) : Serializable {
|
) : Serializable {
|
||||||
companion object {
|
companion object {
|
||||||
const val serialVersionUID: Long = 0
|
const val serialVersionUID: Long = 0
|
||||||
@@ -38,8 +40,10 @@ class IncrementalCompilationOptions(
|
|||||||
val customCacheVersion: Int,
|
val customCacheVersion: Int,
|
||||||
compilerMode: CompileService.CompilerMode,
|
compilerMode: CompileService.CompilerMode,
|
||||||
targetPlatform: CompileService.TargetPlatform,
|
targetPlatform: CompileService.TargetPlatform,
|
||||||
reportingFilters: List<ReportingFilter>
|
reportedCategories: Array<Int>,
|
||||||
) : CompilationOptions(compilerMode, targetPlatform, reportingFilters) {
|
reportedSeverity: Int,
|
||||||
|
requestedCompilationResults: Array<Int>
|
||||||
|
) : CompilationOptions(compilerMode, targetPlatform, reportedCategories, reportedSeverity, requestedCompilationResults) {
|
||||||
companion object {
|
companion object {
|
||||||
const val serialVersionUID: Long = 0
|
const val serialVersionUID: Long = 0
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-8
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2016 JetBrains s.r.o.
|
* Copyright 2010-2017 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -17,12 +17,14 @@
|
|||||||
package org.jetbrains.kotlin.daemon.common
|
package org.jetbrains.kotlin.daemon.common
|
||||||
|
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
|
import java.rmi.Remote
|
||||||
|
import java.rmi.RemoteException
|
||||||
|
|
||||||
/**
|
interface CompilationResultsStorage : Remote {
|
||||||
* Allows daemon clients to specify report category and severities for that category that should be reported from daemon
|
@Throws(RemoteException::class)
|
||||||
*/
|
fun store(compilationResult: Int, value: Serializable)
|
||||||
data class ReportingFilter(val category: ReportCategory, val severities: List<Int>) : Serializable {
|
}
|
||||||
companion object {
|
|
||||||
const val serialVersionUID: Long = 0
|
enum class CompilationResult(val code: Int) {
|
||||||
}
|
IC_COMPILE_ITERATION(0)
|
||||||
}
|
}
|
||||||
+2
-1
@@ -138,7 +138,8 @@ interface CompileService : Remote {
|
|||||||
sessionId: Int,
|
sessionId: Int,
|
||||||
compilerArguments: CommonCompilerArguments,
|
compilerArguments: CommonCompilerArguments,
|
||||||
compilationOptions: CompilationOptions,
|
compilationOptions: CompilationOptions,
|
||||||
servicesFacade: CompilerServicesFacadeBase
|
servicesFacade: CompilerServicesFacadeBase,
|
||||||
|
compilationResultsStorage: CompilationResultsStorage?
|
||||||
): CallResult<Int>
|
): CallResult<Int>
|
||||||
|
|
||||||
@Throws(RemoteException::class)
|
@Throws(RemoteException::class)
|
||||||
|
|||||||
+36
-21
@@ -16,7 +16,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.daemon.common
|
package org.jetbrains.kotlin.daemon.common
|
||||||
|
|
||||||
import java.io.File
|
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
|
||||||
|
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
import java.rmi.Remote
|
import java.rmi.Remote
|
||||||
import java.rmi.RemoteException
|
import java.rmi.RemoteException
|
||||||
@@ -26,29 +27,43 @@ interface CompilerServicesFacadeBase : Remote {
|
|||||||
* Reports different kind of diagnostic messages from compile daemon to compile daemon clients (jps, gradle, ...)
|
* Reports different kind of diagnostic messages from compile daemon to compile daemon clients (jps, gradle, ...)
|
||||||
*/
|
*/
|
||||||
@Throws(RemoteException::class)
|
@Throws(RemoteException::class)
|
||||||
fun report(category: ReportCategory, severity: Int, message: String?, attachment: Serializable?)
|
fun report(category: Int, severity: Int, message: String?, attachment: Serializable?)
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IncrementalCompilerServicesFacade : CompilerServicesFacadeBase {
|
enum class ReportCategory(val code: Int) {
|
||||||
// AnnotationFileUpdater
|
COMPILER_MESSAGE(0),
|
||||||
@Throws(RemoteException::class)
|
DAEMON_MESSAGE(1),
|
||||||
fun hasAnnotationsFileUpdater(): Boolean
|
IC_MESSAGE(2),
|
||||||
|
OUTPUT_MESSAGE(3);
|
||||||
|
|
||||||
@Throws(RemoteException::class)
|
companion object {
|
||||||
fun updateAnnotations(outdatedClassesJvmNames: Iterable<String>)
|
fun fromCode(code: Int): ReportCategory? =
|
||||||
|
ReportCategory.values().firstOrNull { it.code == code }
|
||||||
|
|
||||||
@Throws(RemoteException::class)
|
}
|
||||||
fun revert()
|
|
||||||
|
|
||||||
// ChangesRegistry
|
|
||||||
@Throws(RemoteException::class)
|
|
||||||
fun registerChanges(timestamp: Long, dirtyData: SimpleDirtyData)
|
|
||||||
|
|
||||||
@Throws(RemoteException::class)
|
|
||||||
fun unknownChanges(timestamp: Long)
|
|
||||||
|
|
||||||
@Throws(RemoteException::class)
|
|
||||||
fun getChanges(artifact: File, sinceTS: Long): Iterable<SimpleDirtyData>?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface JpsCompilerServicesFacade : CompilerServicesFacadeBase, CompilerCallbackServicesFacade
|
enum class ReportSeverity(val code: Int) {
|
||||||
|
ERROR(0),
|
||||||
|
WARNING(1),
|
||||||
|
INFO(2),
|
||||||
|
DEBUG(3);
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun fromCode(code: Int): ReportSeverity? =
|
||||||
|
ReportSeverity.values().firstOrNull { it.code == code }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun CompilerServicesFacadeBase.report(category: ReportCategory, severity: ReportSeverity, message: String? = null, attachment: Serializable? = null) {
|
||||||
|
report(category.code, severity.code, message, attachment)
|
||||||
|
}
|
||||||
|
|
||||||
|
data class CompilerMessageAttachment(
|
||||||
|
val severity: CompilerMessageSeverity,
|
||||||
|
val location: CompilerMessageLocation
|
||||||
|
) : Serializable {
|
||||||
|
companion object {
|
||||||
|
const val serialVersionUID = 0L
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2017 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.daemon.common
|
||||||
|
|
||||||
|
import java.io.File
|
||||||
|
import java.rmi.RemoteException
|
||||||
|
|
||||||
|
interface IncrementalCompilerServicesFacade : CompilerServicesFacadeBase {
|
||||||
|
// AnnotationFileUpdater
|
||||||
|
@Throws(RemoteException::class)
|
||||||
|
fun hasAnnotationsFileUpdater(): Boolean
|
||||||
|
|
||||||
|
@Throws(RemoteException::class)
|
||||||
|
fun updateAnnotations(outdatedClassesJvmNames: Iterable<String>)
|
||||||
|
|
||||||
|
@Throws(RemoteException::class)
|
||||||
|
fun revert()
|
||||||
|
|
||||||
|
// ChangesRegistry
|
||||||
|
@Throws(RemoteException::class)
|
||||||
|
fun registerChanges(timestamp: Long, dirtyData: SimpleDirtyData)
|
||||||
|
|
||||||
|
@Throws(RemoteException::class)
|
||||||
|
fun unknownChanges(timestamp: Long)
|
||||||
|
|
||||||
|
@Throws(RemoteException::class)
|
||||||
|
fun getChanges(artifact: File, sinceTS: Long): Iterable<SimpleDirtyData>?
|
||||||
|
}
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2017 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.daemon.common
|
||||||
|
|
||||||
|
interface JpsCompilerServicesFacade : CompilerServicesFacadeBase, CompilerCallbackServicesFacade
|
||||||
-40
@@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2016 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.daemon.common
|
|
||||||
|
|
||||||
import java.io.Serializable
|
|
||||||
|
|
||||||
enum class ReportCategory : Serializable {
|
|
||||||
/**
|
|
||||||
* Messages from compiler
|
|
||||||
* For related severities see [org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity]
|
|
||||||
*/
|
|
||||||
COMPILER_MESSAGE,
|
|
||||||
/**
|
|
||||||
* Messages from compile daemon
|
|
||||||
* For related severities see [org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity]
|
|
||||||
*/
|
|
||||||
DAEMON_MESSAGE,
|
|
||||||
/**
|
|
||||||
* For related severities see [org.jetbrains.kotlin.daemon.incremental.IncrementalCompilationSeverity]
|
|
||||||
*/
|
|
||||||
INCREMENTAL_COMPILATION;
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
const val serialVersionUID: Long = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -41,15 +41,13 @@ import org.jetbrains.kotlin.config.IncrementalCompilation
|
|||||||
import org.jetbrains.kotlin.config.Services
|
import org.jetbrains.kotlin.config.Services
|
||||||
import org.jetbrains.kotlin.daemon.common.*
|
import org.jetbrains.kotlin.daemon.common.*
|
||||||
import org.jetbrains.kotlin.daemon.incremental.*
|
import org.jetbrains.kotlin.daemon.incremental.*
|
||||||
import org.jetbrains.kotlin.daemon.report.CompileServiceReporter
|
import org.jetbrains.kotlin.daemon.report.*
|
||||||
import org.jetbrains.kotlin.daemon.report.CompileServiceReporterImpl
|
|
||||||
import org.jetbrains.kotlin.daemon.report.CompileServiceReporterStreamAdapter
|
|
||||||
import org.jetbrains.kotlin.daemon.report.CompileServicesFacadeMessageCollector
|
|
||||||
import org.jetbrains.kotlin.incremental.*
|
import org.jetbrains.kotlin.incremental.*
|
||||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents
|
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents
|
||||||
import org.jetbrains.kotlin.progress.CompilationCanceledStatus
|
import org.jetbrains.kotlin.progress.CompilationCanceledStatus
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.check
|
import org.jetbrains.kotlin.utils.addToStdlib.check
|
||||||
import java.io.BufferedOutputStream
|
import java.io.BufferedOutputStream
|
||||||
|
import java.io.ByteArrayOutputStream
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.PrintStream
|
import java.io.PrintStream
|
||||||
import java.rmi.NoSuchObjectException
|
import java.rmi.NoSuchObjectException
|
||||||
@@ -325,10 +323,11 @@ class CompileServiceImpl(
|
|||||||
sessionId: Int,
|
sessionId: Int,
|
||||||
compilerArguments: CommonCompilerArguments,
|
compilerArguments: CommonCompilerArguments,
|
||||||
compilationOptions: CompilationOptions,
|
compilationOptions: CompilationOptions,
|
||||||
servicesFacade: CompilerServicesFacadeBase
|
servicesFacade: CompilerServicesFacadeBase,
|
||||||
|
compilationResultsStorage: CompilationResultsStorage?
|
||||||
): CompileService.CallResult<Int> {
|
): CompileService.CallResult<Int> {
|
||||||
val messageCollector = CompileServicesFacadeMessageCollector(servicesFacade, compilationOptions)
|
val messageCollector = CompileServicesFacadeMessageCollector(servicesFacade, compilationOptions)
|
||||||
val serviceReporter = CompileServiceReporterImpl(servicesFacade, compilationOptions)
|
val daemonReporter = DaemonMessageReporter(servicesFacade, compilationOptions)
|
||||||
val compilerMode = compilationOptions.compilerMode
|
val compilerMode = compilationOptions.compilerMode
|
||||||
val targetPlatform = compilationOptions.targetPlatform
|
val targetPlatform = compilationOptions.targetPlatform
|
||||||
|
|
||||||
@@ -336,13 +335,13 @@ class CompileServiceImpl(
|
|||||||
CompileService.CompilerMode.JPS_COMPILER -> {
|
CompileService.CompilerMode.JPS_COMPILER -> {
|
||||||
val jpsServicesFacade = servicesFacade as JpsCompilerServicesFacade
|
val jpsServicesFacade = servicesFacade as JpsCompilerServicesFacade
|
||||||
|
|
||||||
doCompile(sessionId, serviceReporter, tracer = null) { eventManger, profiler ->
|
doCompile(sessionId, daemonReporter, tracer = null) { eventManger, profiler ->
|
||||||
val services = createCompileServices(jpsServicesFacade, eventManger, profiler)
|
val services = createCompileServices(jpsServicesFacade, eventManger, profiler)
|
||||||
execCompiler(compilationOptions.targetPlatform, services, compilerArguments, messageCollector)
|
execCompiler(compilationOptions.targetPlatform, services, compilerArguments, messageCollector)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CompileService.CompilerMode.NON_INCREMENTAL_COMPILER -> {
|
CompileService.CompilerMode.NON_INCREMENTAL_COMPILER -> {
|
||||||
doCompile(sessionId, serviceReporter, tracer = null) { eventManger, profiler ->
|
doCompile(sessionId, daemonReporter, tracer = null) { eventManger, profiler ->
|
||||||
execCompiler(targetPlatform, Services.EMPTY, compilerArguments, messageCollector)
|
execCompiler(targetPlatform, Services.EMPTY, compilerArguments, messageCollector)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -356,8 +355,9 @@ class CompileServiceImpl(
|
|||||||
val gradleIncrementalServicesFacade = servicesFacade as IncrementalCompilerServicesFacade
|
val gradleIncrementalServicesFacade = servicesFacade as IncrementalCompilerServicesFacade
|
||||||
|
|
||||||
withIC {
|
withIC {
|
||||||
doCompile(sessionId, serviceReporter, tracer = null) { eventManger, profiler ->
|
doCompile(sessionId, daemonReporter, tracer = null) { eventManger, profiler ->
|
||||||
execIncrementalCompiler(k2jvmArgs, gradleIncrementalArgs, gradleIncrementalServicesFacade, messageCollector)
|
execIncrementalCompiler(k2jvmArgs, gradleIncrementalArgs, gradleIncrementalServicesFacade, compilationResultsStorage!!,
|
||||||
|
messageCollector, daemonReporter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -386,23 +386,34 @@ class CompileServiceImpl(
|
|||||||
|
|
||||||
private fun execIncrementalCompiler(
|
private fun execIncrementalCompiler(
|
||||||
k2jvmArgs: K2JVMCompilerArguments,
|
k2jvmArgs: K2JVMCompilerArguments,
|
||||||
incrementalCompilerArgs: IncrementalCompilationOptions,
|
incrementalCompilationOptions: IncrementalCompilationOptions,
|
||||||
servicesFacade: IncrementalCompilerServicesFacade,
|
servicesFacade: IncrementalCompilerServicesFacade,
|
||||||
messageCollector: CompileServicesFacadeMessageCollector
|
compilationResultsStorage: CompilationResultsStorage,
|
||||||
|
compilerMessageCollector: MessageCollector,
|
||||||
|
daemonMessageReporter: DaemonMessageReporter
|
||||||
): ExitCode {
|
): ExitCode {
|
||||||
val reporter = RemoteICReporter(servicesFacade, incrementalCompilerArgs)
|
val reporter = RemoteICReporter(servicesFacade, compilationResultsStorage, incrementalCompilationOptions)
|
||||||
val annotationFileUpdater = if (servicesFacade.hasAnnotationsFileUpdater()) RemoteAnnotationsFileUpdater(servicesFacade) else null
|
val annotationFileUpdater = if (servicesFacade.hasAnnotationsFileUpdater()) RemoteAnnotationsFileUpdater(servicesFacade) else null
|
||||||
|
|
||||||
val moduleFile = k2jvmArgs.module?.let(::File)
|
val moduleFile = k2jvmArgs.module?.let(::File)
|
||||||
assert(moduleFile?.exists() ?: false) { "Module does not exist ${k2jvmArgs.module}" }
|
assert(moduleFile?.exists() ?: false) { "Module does not exist ${k2jvmArgs.module}" }
|
||||||
|
|
||||||
val temporaryMessageCollectorForModuleParsing = FilteringMessageCollector(messageCollector) { it != CompilerMessageSeverity.ERROR }
|
// todo: pass javaSourceRoots and allKotlinFiles using IncrementalCompilationOptions
|
||||||
val parsedModule = ModuleXmlParser.parseModuleScript(k2jvmArgs.module, temporaryMessageCollectorForModuleParsing)
|
val parsedModule = run {
|
||||||
|
val bytesOut = ByteArrayOutputStream()
|
||||||
|
val printStream = PrintStream(bytesOut)
|
||||||
|
val mc = PrintingMessageCollector(printStream, MessageRenderer.PLAIN_FULL_PATHS, false)
|
||||||
|
val parsedModule = ModuleXmlParser.parseModuleScript(k2jvmArgs.module, mc)
|
||||||
|
if (mc.hasErrors()) {
|
||||||
|
daemonMessageReporter.report(ReportSeverity.ERROR, bytesOut.toString("UTF8"))
|
||||||
|
}
|
||||||
|
parsedModule
|
||||||
|
}
|
||||||
val javaSourceRoots = parsedModule.modules.flatMapTo(HashSet()) { it.getJavaSourceRoots().map { File(it.path) } }
|
val javaSourceRoots = parsedModule.modules.flatMapTo(HashSet()) { it.getJavaSourceRoots().map { File(it.path) } }
|
||||||
val allKotlinFiles = parsedModule.modules.flatMap { it.getSourceFiles().map(::File) }
|
val allKotlinFiles = parsedModule.modules.flatMap { it.getSourceFiles().map(::File) }
|
||||||
|
|
||||||
val changedFiles = if (incrementalCompilerArgs.areFileChangesKnown) {
|
val changedFiles = if (incrementalCompilationOptions.areFileChangesKnown) {
|
||||||
ChangedFiles.Known(incrementalCompilerArgs.modifiedFiles!!, incrementalCompilerArgs.deletedFiles!!)
|
ChangedFiles.Known(incrementalCompilationOptions.modifiedFiles!!, incrementalCompilationOptions.deletedFiles!!)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ChangedFiles.Unknown()
|
ChangedFiles.Unknown()
|
||||||
@@ -411,13 +422,13 @@ class CompileServiceImpl(
|
|||||||
val artifactChanges = RemoteArtifactChangesProvider(servicesFacade)
|
val artifactChanges = RemoteArtifactChangesProvider(servicesFacade)
|
||||||
val changesRegistry = RemoteChangesRegostry(servicesFacade)
|
val changesRegistry = RemoteChangesRegostry(servicesFacade)
|
||||||
|
|
||||||
val workingDir = incrementalCompilerArgs.workingDir
|
val workingDir = incrementalCompilationOptions.workingDir
|
||||||
val versions = commonCacheVersions(workingDir) +
|
val versions = commonCacheVersions(workingDir) +
|
||||||
customCacheVersion(incrementalCompilerArgs.customCacheVersion, incrementalCompilerArgs.customCacheVersionFileName, workingDir, forceEnable = true)
|
customCacheVersion(incrementalCompilationOptions.customCacheVersion, incrementalCompilationOptions.customCacheVersionFileName, workingDir, forceEnable = true)
|
||||||
|
|
||||||
return IncrementalJvmCompilerRunner(workingDir, javaSourceRoots, versions, reporter, annotationFileUpdater,
|
return IncrementalJvmCompilerRunner(workingDir, javaSourceRoots, versions, reporter, annotationFileUpdater,
|
||||||
artifactChanges, changesRegistry)
|
artifactChanges, changesRegistry)
|
||||||
.compile(allKotlinFiles, k2jvmArgs, messageCollector, { changedFiles })
|
.compile(allKotlinFiles, k2jvmArgs, compilerMessageCollector, { changedFiles })
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun leaseReplSession(
|
override fun leaseReplSession(
|
||||||
@@ -657,7 +668,7 @@ class CompileServiceImpl(
|
|||||||
val compilerMessagesStream = PrintStream(BufferedOutputStream(RemoteOutputStreamClient(compilerMessagesStreamProxy, rpcProfiler), REMOTE_STREAM_BUFFER_SIZE))
|
val compilerMessagesStream = PrintStream(BufferedOutputStream(RemoteOutputStreamClient(compilerMessagesStreamProxy, rpcProfiler), REMOTE_STREAM_BUFFER_SIZE))
|
||||||
val serviceOutputStream = PrintStream(BufferedOutputStream(RemoteOutputStreamClient(serviceOutputStreamProxy, rpcProfiler), REMOTE_STREAM_BUFFER_SIZE))
|
val serviceOutputStream = PrintStream(BufferedOutputStream(RemoteOutputStreamClient(serviceOutputStreamProxy, rpcProfiler), REMOTE_STREAM_BUFFER_SIZE))
|
||||||
try {
|
try {
|
||||||
val compileServiceReporter = CompileServiceReporterStreamAdapter(serviceOutputStream)
|
val compileServiceReporter = DaemonMessageReporterPrintStreamAdapter(serviceOutputStream)
|
||||||
if (args.none())
|
if (args.none())
|
||||||
throw IllegalArgumentException("Error: empty arguments list.")
|
throw IllegalArgumentException("Error: empty arguments list.")
|
||||||
log.info("Starting compilation with args: " + args.joinToString(" "))
|
log.info("Starting compilation with args: " + args.joinToString(" "))
|
||||||
@@ -676,7 +687,7 @@ class CompileServiceImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun doCompile(sessionId: Int,
|
private fun doCompile(sessionId: Int,
|
||||||
compileServiceReporter: CompileServiceReporter,
|
daemonMessageReporter: DaemonMessageReporter,
|
||||||
tracer: RemoteOperationsTracer?,
|
tracer: RemoteOperationsTracer?,
|
||||||
body: (EventManger, Profiler) -> ExitCode): CompileService.CallResult<Int> =
|
body: (EventManger, Profiler) -> ExitCode): CompileService.CallResult<Int> =
|
||||||
ifAlive {
|
ifAlive {
|
||||||
@@ -685,7 +696,7 @@ class CompileServiceImpl(
|
|||||||
val rpcProfiler = if (daemonOptions.reportPerf) WallAndThreadTotalProfiler() else DummyProfiler()
|
val rpcProfiler = if (daemonOptions.reportPerf) WallAndThreadTotalProfiler() else DummyProfiler()
|
||||||
val eventManger = EventMangerImpl()
|
val eventManger = EventMangerImpl()
|
||||||
try {
|
try {
|
||||||
val exitCode = checkedCompile(compileServiceReporter, rpcProfiler) {
|
val exitCode = checkedCompile(daemonMessageReporter, rpcProfiler) {
|
||||||
body(eventManger, rpcProfiler).code
|
body(eventManger, rpcProfiler).code
|
||||||
}
|
}
|
||||||
CompileService.CallResult.Good(exitCode)
|
CompileService.CallResult.Good(exitCode)
|
||||||
@@ -709,7 +720,7 @@ class CompileServiceImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun<R> checkedCompile(compileServiceReporter: CompileServiceReporter, rpcProfiler: Profiler, body: () -> R): R {
|
private fun<R> checkedCompile(daemonMessageReporter: DaemonMessageReporter, rpcProfiler: Profiler, body: () -> R): R {
|
||||||
try {
|
try {
|
||||||
val profiler = if (daemonOptions.reportPerf) WallAndThreadAndMemoryTotalProfiler(withGC = false) else DummyProfiler()
|
val profiler = if (daemonOptions.reportPerf) WallAndThreadAndMemoryTotalProfiler(withGC = false) else DummyProfiler()
|
||||||
|
|
||||||
@@ -726,14 +737,14 @@ class CompileServiceImpl(
|
|||||||
val rpc = rpcProfiler.getTotalCounters()
|
val rpc = rpcProfiler.getTotalCounters()
|
||||||
|
|
||||||
"PERF: Compile on daemon: ${pc.time.ms()} ms; thread: user ${pc.threadUserTime.ms()} ms, sys ${(pc.threadTime - pc.threadUserTime).ms()} ms; rpc: ${rpc.count} calls, ${rpc.time.ms()} ms, thread ${rpc.threadTime.ms()} ms; memory: ${endMem.kb()} kb (${"%+d".format(pc.memory.kb())} kb)".let {
|
"PERF: Compile on daemon: ${pc.time.ms()} ms; thread: user ${pc.threadUserTime.ms()} ms, sys ${(pc.threadTime - pc.threadUserTime).ms()} ms; rpc: ${rpc.count} calls, ${rpc.time.ms()} ms, thread ${rpc.threadTime.ms()} ms; memory: ${endMem.kb()} kb (${"%+d".format(pc.memory.kb())} kb)".let {
|
||||||
compileServiceReporter.info(it)
|
daemonMessageReporter.report(ReportSeverity.INFO, it)
|
||||||
log.info(it)
|
log.info(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
// this will only be reported if if appropriate (e.g. ByClass) profiler is used
|
// this will only be reported if if appropriate (e.g. ByClass) profiler is used
|
||||||
for ((obj, counters) in rpcProfiler.getCounters()) {
|
for ((obj, counters) in rpcProfiler.getCounters()) {
|
||||||
"PERF: rpc by $obj: ${counters.count} calls, ${counters.time.ms()} ms, thread ${counters.threadTime.ms()} ms".let {
|
"PERF: rpc by $obj: ${counters.count} calls, ${counters.time.ms()} ms, thread ${counters.threadTime.ms()} ms".let {
|
||||||
compileServiceReporter.info(it)
|
daemonMessageReporter.report(ReportSeverity.INFO, it)
|
||||||
log.info(it)
|
log.info(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,60 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2016 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.daemon.incremental
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
|
||||||
import org.jetbrains.kotlin.daemon.report.FilteringReporterBase
|
|
||||||
import org.jetbrains.kotlin.daemon.common.CompilerServicesFacadeBase
|
|
||||||
import org.jetbrains.kotlin.daemon.common.CompilationOptions
|
|
||||||
import org.jetbrains.kotlin.daemon.common.IncrementalCompilationServicesFacade
|
|
||||||
import org.jetbrains.kotlin.daemon.common.ReportCategory
|
|
||||||
import org.jetbrains.kotlin.daemon.incremental.IncrementalCompilationSeverity.COMPILED_FILES
|
|
||||||
import org.jetbrains.kotlin.daemon.incremental.IncrementalCompilationSeverity.LOGGING
|
|
||||||
import org.jetbrains.kotlin.incremental.ICReporter
|
|
||||||
import java.io.File
|
|
||||||
import java.io.Serializable
|
|
||||||
|
|
||||||
internal class RemoteICReporter(
|
|
||||||
servicesFacade: CompilerServicesFacadeBase,
|
|
||||||
additionalCompilerArgs: CompilationOptions
|
|
||||||
) : FilteringReporterBase(servicesFacade, additionalCompilerArgs, ReportCategory.INCREMENTAL_COMPILATION), ICReporter {
|
|
||||||
override fun report(message: () -> String) {
|
|
||||||
if (shouldReport(LOGGING.value)) {
|
|
||||||
report(LOGGING.value, message())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun reportCompileIteration(sourceFiles: Collection<File>, exitCode: ExitCode) {
|
|
||||||
if (shouldReport(COMPILED_FILES.value)) {
|
|
||||||
report(COMPILED_FILES.value, message = null, attachment = CompileIterationResult(sourceFiles, exitCode.toString()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* See [RemoteICReporter]
|
|
||||||
*/
|
|
||||||
enum class IncrementalCompilationSeverity(val value: Int) {
|
|
||||||
COMPILED_FILES(0),
|
|
||||||
LOGGING(10)
|
|
||||||
}
|
|
||||||
|
|
||||||
class CompileIterationResult(val sourceFiles: Iterable<File>, val exitCode: String) : Serializable {
|
|
||||||
companion object {
|
|
||||||
const val serialVersionUID: Long = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2016 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.daemon.report
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
|
||||||
import org.jetbrains.kotlin.daemon.common.CompilationOptions
|
|
||||||
import org.jetbrains.kotlin.daemon.common.CompilerServicesFacadeBase
|
|
||||||
import org.jetbrains.kotlin.daemon.common.ReportCategory
|
|
||||||
import org.jetbrains.kotlin.daemon.report.FilteringReporterBase
|
|
||||||
import java.io.PrintStream
|
|
||||||
|
|
||||||
// For messages of about compile daemon
|
|
||||||
internal interface CompileServiceReporter {
|
|
||||||
fun info(message: String) {
|
|
||||||
report(CompilerMessageSeverity.INFO, message)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun report(severity: CompilerMessageSeverity, message: String)
|
|
||||||
}
|
|
||||||
|
|
||||||
internal class CompileServiceReporterStreamAdapter(private val out: PrintStream) : CompileServiceReporter {
|
|
||||||
override fun report(severity: CompilerMessageSeverity, message: String) {
|
|
||||||
out.print("[Kotlin daemon][$severity] $message")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal class CompileServiceReporterImpl(
|
|
||||||
servicesFacade: CompilerServicesFacadeBase,
|
|
||||||
compilationOptions: CompilationOptions
|
|
||||||
) : FilteringReporterBase(servicesFacade, compilationOptions, ReportCategory.DAEMON_MESSAGE), CompileServiceReporter {
|
|
||||||
|
|
||||||
override fun report(severity: CompilerMessageSeverity, message: String) {
|
|
||||||
report(severity.value, message)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+19
-6
@@ -19,26 +19,39 @@ package org.jetbrains.kotlin.daemon.report
|
|||||||
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.MessageCollector
|
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||||
import org.jetbrains.kotlin.daemon.common.CompilationOptions
|
import org.jetbrains.kotlin.daemon.common.*
|
||||||
import org.jetbrains.kotlin.daemon.common.CompilerServicesFacadeBase
|
|
||||||
import org.jetbrains.kotlin.daemon.common.ReportCategory
|
|
||||||
|
|
||||||
internal class CompileServicesFacadeMessageCollector(
|
internal class CompileServicesFacadeMessageCollector(
|
||||||
private val servicesFacade: CompilerServicesFacadeBase,
|
private val servicesFacade: CompilerServicesFacadeBase,
|
||||||
compilationOptions: CompilationOptions
|
compilationOptions: CompilationOptions
|
||||||
) : MessageCollector {
|
) : MessageCollector {
|
||||||
|
private val mySeverity = compilationOptions.reportSeverity
|
||||||
private var hasErrors = false
|
private var hasErrors = false
|
||||||
private val reportingFilter = compilationOptions.reportingFilters.firstOrNull { it.category == ReportCategory.DAEMON_MESSAGE }
|
|
||||||
|
|
||||||
override fun clear() {
|
override fun clear() {
|
||||||
hasErrors = false
|
hasErrors = false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation) {
|
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation) {
|
||||||
if (reportingFilter != null && severity.value !in reportingFilter.severities) return
|
val reportCategory = when (severity) {
|
||||||
|
CompilerMessageSeverity.OUTPUT -> ReportCategory.OUTPUT_MESSAGE
|
||||||
|
else -> ReportCategory.COMPILER_MESSAGE
|
||||||
|
}
|
||||||
|
|
||||||
|
val reportSeverity = when (severity) {
|
||||||
|
CompilerMessageSeverity.ERROR,
|
||||||
|
CompilerMessageSeverity.EXCEPTION -> ReportSeverity.ERROR
|
||||||
|
CompilerMessageSeverity.WARNING -> ReportSeverity.WARNING
|
||||||
|
CompilerMessageSeverity.INFO -> ReportSeverity.INFO
|
||||||
|
CompilerMessageSeverity.LOGGING -> ReportSeverity.DEBUG
|
||||||
|
CompilerMessageSeverity.OUTPUT -> ReportSeverity.ERROR
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reportSeverity.code <= mySeverity) {
|
||||||
|
servicesFacade.report(reportCategory, reportSeverity, message, CompilerMessageAttachment(severity, location))
|
||||||
|
}
|
||||||
|
|
||||||
hasErrors = hasErrors || severity == CompilerMessageSeverity.ERROR
|
hasErrors = hasErrors || severity == CompilerMessageSeverity.ERROR
|
||||||
servicesFacade.report(ReportCategory.DAEMON_MESSAGE, severity.value, message, location)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hasErrors(): Boolean = hasErrors
|
override fun hasErrors(): Boolean = hasErrors
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.daemon.report
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.daemon.common.*
|
||||||
|
import java.io.PrintStream
|
||||||
|
|
||||||
|
internal interface DaemonMessageReporter {
|
||||||
|
fun report(severity: ReportSeverity, message: String)
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun DaemonMessageReporter(
|
||||||
|
servicesFacade: CompilerServicesFacadeBase,
|
||||||
|
compilationOptions: CompilationOptions
|
||||||
|
): DaemonMessageReporter =
|
||||||
|
if (ReportCategory.DAEMON_MESSAGE.code in compilationOptions.reportCategories) {
|
||||||
|
val mySeverity = ReportSeverity.fromCode(compilationOptions.reportSeverity)!!
|
||||||
|
DaemonMessageReporterImpl(servicesFacade, mySeverity)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
DummyDaemonMessageReporter
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class DaemonMessageReporterPrintStreamAdapter(private val out: PrintStream): DaemonMessageReporter {
|
||||||
|
override fun report(severity: ReportSeverity, message: String) {
|
||||||
|
out.print("[Kotlin compile daemon][$severity] $message")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class DaemonMessageReporterImpl(
|
||||||
|
private val servicesFacade: CompilerServicesFacadeBase,
|
||||||
|
private val mySeverity: ReportSeverity
|
||||||
|
): DaemonMessageReporter {
|
||||||
|
override fun report(severity: ReportSeverity, message: String) {
|
||||||
|
if (severity.code <= mySeverity.code) {
|
||||||
|
servicesFacade.report(ReportCategory.DAEMON_MESSAGE.code, severity.code, message, attachment = null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private object DummyDaemonMessageReporter : DaemonMessageReporter {
|
||||||
|
override fun report(severity: ReportSeverity, message: String) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2016 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.daemon.report
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.daemon.common.CompilationOptions
|
|
||||||
import org.jetbrains.kotlin.daemon.common.CompilerServicesFacadeBase
|
|
||||||
import org.jetbrains.kotlin.daemon.common.ReportCategory
|
|
||||||
import java.io.Serializable
|
|
||||||
|
|
||||||
internal open class FilteringReporterBase(
|
|
||||||
private val servicesFacade: CompilerServicesFacadeBase,
|
|
||||||
additionalCompilerArgs: CompilationOptions,
|
|
||||||
private val reportCategory: ReportCategory
|
|
||||||
) {
|
|
||||||
private val reportingFilter = additionalCompilerArgs.reportingFilters.firstOrNull { it.category == reportCategory }
|
|
||||||
|
|
||||||
protected fun report(severity: Int, message: String?, attachment: Serializable? = null) {
|
|
||||||
if (shouldReport(severity)) {
|
|
||||||
servicesFacade.report(reportCategory, severity, message, attachment)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected fun shouldReport(severity: Int): Boolean =
|
|
||||||
reportingFilter == null || severity in reportingFilter.severities
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2017 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.daemon.report
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||||
|
import org.jetbrains.kotlin.daemon.common.*
|
||||||
|
import org.jetbrains.kotlin.incremental.ICReporter
|
||||||
|
import java.io.File
|
||||||
|
import java.io.Serializable
|
||||||
|
|
||||||
|
internal class RemoteICReporter(
|
||||||
|
private val servicesFacade: CompilerServicesFacadeBase,
|
||||||
|
private val compilationResultsStorage: CompilationResultsStorage,
|
||||||
|
compilationOptions: CompilationOptions
|
||||||
|
) : ICReporter {
|
||||||
|
private val shouldReportMessages = ReportCategory.IC_MESSAGE.code in compilationOptions.reportCategories
|
||||||
|
private val isVerbose = compilationOptions.reportSeverity == ReportSeverity.DEBUG.code
|
||||||
|
private val shouldReportCompileIteration = CompilationResult.IC_COMPILE_ITERATION.code in compilationOptions.requestedCompilationResults
|
||||||
|
|
||||||
|
override fun report(message: () -> String) {
|
||||||
|
if (shouldReportMessages && isVerbose) {
|
||||||
|
servicesFacade.report(ReportCategory.IC_MESSAGE, ReportSeverity.DEBUG, message())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun reportCompileIteration(sourceFiles: Collection<File>, exitCode: ExitCode) {
|
||||||
|
if (shouldReportCompileIteration) {
|
||||||
|
compilationResultsStorage.store(CompilationResult.IC_COMPILE_ITERATION.code, CompileIterationResult(sourceFiles, exitCode.toString()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class CompileIterationResult(
|
||||||
|
@Suppress("unused") // used in Gradle
|
||||||
|
val sourceFiles: Iterable<File>,
|
||||||
|
@Suppress("unused") // used in Gradle
|
||||||
|
val exitCode: String
|
||||||
|
) : Serializable {
|
||||||
|
companion object {
|
||||||
|
const val serialVersionUID: Long = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,5 +20,6 @@
|
|||||||
<orderEntry type="module" module-name="daemon-client" />
|
<orderEntry type="module" module-name="daemon-client" />
|
||||||
<orderEntry type="module" module-name="daemon-common" />
|
<orderEntry type="module" module-name="daemon-common" />
|
||||||
<orderEntry type="library" scope="TEST" name="kotlin-test" level="project" />
|
<orderEntry type="library" scope="TEST" name="kotlin-test" level="project" />
|
||||||
|
<orderEntry type="module" module-name="daemon" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
+23
-12
@@ -19,9 +19,7 @@ package org.jetbrains.kotlin.compilerRunner
|
|||||||
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.daemon.client.CompilerCallbackServicesFacadeServer
|
import org.jetbrains.kotlin.daemon.client.CompilerCallbackServicesFacadeServer
|
||||||
import org.jetbrains.kotlin.daemon.common.JpsCompilerServicesFacade
|
import org.jetbrains.kotlin.daemon.common.*
|
||||||
import org.jetbrains.kotlin.daemon.common.ReportCategory
|
|
||||||
import org.jetbrains.kotlin.daemon.common.SOCKET_ANY_FREE_PORT
|
|
||||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents
|
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents
|
||||||
import org.jetbrains.kotlin.progress.CompilationCanceledStatus
|
import org.jetbrains.kotlin.progress.CompilationCanceledStatus
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
@@ -34,20 +32,26 @@ internal class JpsCompilerServicesFacadeImpl(
|
|||||||
port),
|
port),
|
||||||
JpsCompilerServicesFacade {
|
JpsCompilerServicesFacade {
|
||||||
|
|
||||||
override fun report(category: ReportCategory, severity: Int, message: String?, attachment: Serializable?) {
|
override fun report(category: Int, severity: Int, message: String?, attachment: Serializable?) {
|
||||||
when (category) {
|
val reportCategory = ReportCategory.fromCode(category)
|
||||||
|
|
||||||
|
when (reportCategory) {
|
||||||
|
ReportCategory.OUTPUT_MESSAGE -> {
|
||||||
|
env.messageCollector.report(CompilerMessageSeverity.OUTPUT, message!!, CompilerMessageLocation.NO_LOCATION)
|
||||||
|
}
|
||||||
ReportCategory.COMPILER_MESSAGE -> {
|
ReportCategory.COMPILER_MESSAGE -> {
|
||||||
val compilerMessageSeverity = CompilerMessageSeverity.values().firstOrNull { it.value == severity }
|
val compilerMessageAttachment = attachment as? CompilerMessageAttachment
|
||||||
if (compilerMessageSeverity != null) {
|
if (message != null && compilerMessageAttachment != null) {
|
||||||
val location = attachment as? CompilerMessageLocation ?: CompilerMessageLocation.NO_LOCATION
|
val originalSeverity = compilerMessageAttachment.severity
|
||||||
env.messageCollector.report(compilerMessageSeverity, message!!, location)
|
val originalLocation = compilerMessageAttachment.location
|
||||||
|
env.messageCollector.report(originalSeverity, message, originalLocation)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
reportUnexpected(category, severity, message, attachment)
|
reportUnexpected(category, severity, message, attachment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ReportCategory.DAEMON_MESSAGE,
|
ReportCategory.DAEMON_MESSAGE,
|
||||||
ReportCategory.INCREMENTAL_COMPILATION -> {
|
ReportCategory.IC_MESSAGE -> {
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
env.messageCollector.report(CompilerMessageSeverity.LOGGING, message, CompilerMessageLocation.NO_LOCATION)
|
env.messageCollector.report(CompilerMessageSeverity.LOGGING, message, CompilerMessageLocation.NO_LOCATION)
|
||||||
}
|
}
|
||||||
@@ -61,8 +65,15 @@ internal class JpsCompilerServicesFacadeImpl(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun reportUnexpected(category: ReportCategory, severity: Int, message: String?, attachment: Serializable?) {
|
private fun reportUnexpected(category: Int, severity: Int, message: String?, attachment: Serializable?) {
|
||||||
env.messageCollector.report(CompilerMessageSeverity.LOGGING,
|
val compilerMessageSeverity = when (ReportSeverity.fromCode(severity)) {
|
||||||
|
ReportSeverity.ERROR -> CompilerMessageSeverity.ERROR
|
||||||
|
ReportSeverity.WARNING -> CompilerMessageSeverity.WARNING
|
||||||
|
ReportSeverity.INFO -> CompilerMessageSeverity.INFO
|
||||||
|
else -> CompilerMessageSeverity.LOGGING
|
||||||
|
}
|
||||||
|
|
||||||
|
env.messageCollector.report(compilerMessageSeverity,
|
||||||
"Unexpected message: category=$category; severity=$severity; message='$message'; attachment=$attachment",
|
"Unexpected message: category=$category; severity=$severity; message='$message'; attachment=$attachment",
|
||||||
CompilerMessageLocation.NO_LOCATION)
|
CompilerMessageLocation.NO_LOCATION)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ import org.jetbrains.kotlin.jps.build.KotlinBuilder
|
|||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.PrintStream
|
import java.io.PrintStream
|
||||||
|
import java.io.Serializable
|
||||||
|
import java.rmi.server.UnicastRemoteObject
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
|
class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
|
||||||
@@ -99,39 +101,30 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val res = withDaemon(environment, retryOnConnectionError = true) { daemon, sessionId ->
|
val res = withDaemon(environment, retryOnConnectionError = true) { daemon, sessionId ->
|
||||||
val options = CompilationOptions(CompileService.CompilerMode.JPS_COMPILER,
|
val compilerMode = CompileService.CompilerMode.JPS_COMPILER
|
||||||
targetPlatform,
|
val verbose = compilerArgs.verbose
|
||||||
reportingFilters = getReportingFilters(compilerArgs.verbose))
|
val options = CompilationOptions(compilerMode, targetPlatform, reportCategories(verbose), reportSeverity(verbose), requestedCompilationResults = emptyArray())
|
||||||
daemon.compile(sessionId, compilerArgs, options, JpsCompilerServicesFacadeImpl(environment))
|
daemon.compile(sessionId, compilerArgs, options, JpsCompilerServicesFacadeImpl(environment), null)
|
||||||
}
|
}
|
||||||
|
|
||||||
return res?.get()?.let { exitCodeFromProcessExitCode(it) }
|
return res?.get()?.let { exitCodeFromProcessExitCode(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getReportingFilters(verbose: Boolean): List<ReportingFilter> {
|
private fun reportCategories(verbose: Boolean): Array<Int> =
|
||||||
val result = ArrayList<ReportingFilter>()
|
if (!verbose) {
|
||||||
|
arrayOf(ReportCategory.COMPILER_MESSAGE.code)
|
||||||
val compilerMessagesSeverities = ArrayList<Int>().apply {
|
}
|
||||||
add(CompilerMessageSeverity.ERROR.value)
|
else {
|
||||||
add(CompilerMessageSeverity.EXCEPTION.value)
|
ReportCategory.values().map { it.code }.toTypedArray()
|
||||||
add(CompilerMessageSeverity.WARNING.value)
|
|
||||||
add(CompilerMessageSeverity.INFO.value)
|
|
||||||
add(CompilerMessageSeverity.OUTPUT.value)
|
|
||||||
|
|
||||||
if (verbose) {
|
|
||||||
add(CompilerMessageSeverity.LOGGING.value)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (verbose) {
|
private fun reportSeverity(verbose: Boolean): Int =
|
||||||
result.add(ReportingFilter(ReportCategory.DAEMON_MESSAGE, emptyList()))
|
if (!verbose) {
|
||||||
}
|
ReportSeverity.INFO.code
|
||||||
|
}
|
||||||
val compilerMessagesFilter = ReportingFilter(ReportCategory.COMPILER_MESSAGE, compilerMessagesSeverities)
|
else {
|
||||||
result.add(compilerMessagesFilter)
|
ReportSeverity.DEBUG.code
|
||||||
|
}
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun fallbackCompileStrategy(
|
private fun fallbackCompileStrategy(
|
||||||
argsArray: Array<String>,
|
argsArray: Array<String>,
|
||||||
|
|||||||
+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.CompilerMessageSeverity
|
||||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||||
import org.jetbrains.kotlin.daemon.common.*
|
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.toDirtyData
|
||||||
import org.jetbrains.kotlin.daemon.incremental.toSimpleDirtyData
|
import org.jetbrains.kotlin.daemon.incremental.toSimpleDirtyData
|
||||||
import org.jetbrains.kotlin.gradle.plugin.kotlinDebug
|
import org.jetbrains.kotlin.gradle.plugin.kotlinDebug
|
||||||
import org.jetbrains.kotlin.gradle.plugin.kotlinWarn
|
import org.jetbrains.kotlin.gradle.plugin.kotlinWarn
|
||||||
import org.jetbrains.kotlin.incremental.DirtyData
|
import org.jetbrains.kotlin.incremental.DirtyData
|
||||||
import org.jetbrains.kotlin.incremental.multiproject.ArtifactDifference
|
import org.jetbrains.kotlin.incremental.multiproject.ArtifactDifference
|
||||||
import org.jetbrains.kotlin.incremental.pathsAsStringRelativeTo
|
|
||||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
@@ -28,28 +25,34 @@ internal open class GradleCompilerServicesFacadeImpl(
|
|||||||
) : UnicastRemoteObject(port), CompilerServicesFacadeBase, Remote {
|
) : UnicastRemoteObject(port), CompilerServicesFacadeBase, Remote {
|
||||||
protected val log: Logger = project.logger
|
protected val log: Logger = project.logger
|
||||||
|
|
||||||
override fun report(category: ReportCategory, severity: Int, message: String?, attachment: Serializable?) {
|
override fun report(category: Int, severity: Int, message: String?, attachment: Serializable?) {
|
||||||
when (category) {
|
val reportCategory = ReportCategory.fromCode(category)
|
||||||
ReportCategory.COMPILER_MESSAGE -> {
|
|
||||||
val compilerSeverity = CompilerMessageSeverity.values().firstOrNull { it.value == severity }
|
|
||||||
|
|
||||||
if (compilerSeverity != null && message != null && attachment is CompilerMessageLocation) {
|
when (reportCategory) {
|
||||||
compilerMessageCollector.report(compilerSeverity, message, attachment)
|
ReportCategory.COMPILER_MESSAGE -> {
|
||||||
|
if (message != null && attachment is CompilerMessageAttachment) {
|
||||||
|
compilerMessageCollector.report(attachment.severity, message, attachment.location)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
reportUnexpectedMessage(category, severity, message, attachment)
|
reportUnexpectedMessage(category, severity, message, attachment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ReportCategory.IC_MESSAGE -> {
|
||||||
|
log.kotlinDebug { "[IC] $message" }
|
||||||
|
}
|
||||||
ReportCategory.DAEMON_MESSAGE -> {
|
ReportCategory.DAEMON_MESSAGE -> {
|
||||||
log.kotlinDebug { "[DAEMON] $message" }
|
log.kotlinDebug { "[DAEMON] $message" }
|
||||||
}
|
}
|
||||||
|
ReportCategory.OUTPUT_MESSAGE -> {
|
||||||
|
compilerMessageCollector.report(CompilerMessageSeverity.OUTPUT, message!!, CompilerMessageLocation.NO_LOCATION)
|
||||||
|
}
|
||||||
else -> {
|
else -> {
|
||||||
reportUnexpectedMessage(category, severity, message, attachment)
|
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
|
// todo add assert to tests
|
||||||
log.kotlinWarn("Received unexpected message from compiler daemon: category=$category, severity=$severity, message='$message', attachment=$attachment")
|
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),
|
) : GradleCompilerServicesFacadeImpl(project, environment.messageCollector, port),
|
||||||
IncrementalCompilerServicesFacade {
|
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 =
|
override fun hasAnnotationsFileUpdater(): Boolean =
|
||||||
environment.kaptAnnotationsFileUpdater != null
|
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.K2JSCompilerArguments
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments
|
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.config.Services
|
||||||
import org.jetbrains.kotlin.daemon.client.RemoteOutputStreamServer
|
|
||||||
import org.jetbrains.kotlin.daemon.common.*
|
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.ParentLastURLClassLoader
|
||||||
import org.jetbrains.kotlin.gradle.plugin.kotlinDebug
|
import org.jetbrains.kotlin.gradle.plugin.kotlinDebug
|
||||||
import org.jetbrains.kotlin.incremental.*
|
import org.jetbrains.kotlin.incremental.*
|
||||||
import java.io.*
|
import java.io.ByteArrayOutputStream
|
||||||
|
import java.io.File
|
||||||
|
import java.io.PrintStream
|
||||||
import kotlin.concurrent.thread
|
import kotlin.concurrent.thread
|
||||||
|
|
||||||
internal const val KOTLIN_COMPILER_EXECUTION_STRATEGY_PROPERTY = "kotlin.compiler.execution.strategy"
|
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
|
K2METADATA_COMPILER -> CompileService.TargetPlatform.METADATA
|
||||||
else -> throw IllegalArgumentException("Unknown compiler type $compilerClassName")
|
else -> throw IllegalArgumentException("Unknown compiler type $compilerClassName")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val verbose = environment.compilerArgs.verbose
|
||||||
val compilationOptions = CompilationOptions(
|
val compilationOptions = CompilationOptions(
|
||||||
reportingFilters = getNonIncrementalReportingFilters(environment.compilerArgs.verbose),
|
|
||||||
compilerMode = CompileService.CompilerMode.NON_INCREMENTAL_COMPILER,
|
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 servicesFacade = GradleCompilerServicesFacadeImpl(project, environment.messageCollector)
|
||||||
|
|
||||||
val res = withDaemon(environment, retryOnConnectionError = true) { daemon, sessionId ->
|
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) }
|
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? {
|
private fun incrementalCompilationWithDaemon(environment: GradleIncrementalCompilerEnvironment): ExitCode? {
|
||||||
val knownChangedFiles = environment.changedFiles as? ChangedFiles.Known
|
val knownChangedFiles = environment.changedFiles as? ChangedFiles.Known
|
||||||
|
|
||||||
|
val verbose = environment.compilerArgs.verbose
|
||||||
val compilationOptions = IncrementalCompilationOptions(
|
val compilationOptions = IncrementalCompilationOptions(
|
||||||
areFileChangesKnown = knownChangedFiles != null,
|
areFileChangesKnown = knownChangedFiles != null,
|
||||||
modifiedFiles = knownChangedFiles?.modified,
|
modifiedFiles = knownChangedFiles?.modified,
|
||||||
@@ -190,15 +194,16 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil
|
|||||||
workingDir = environment.workingDir,
|
workingDir = environment.workingDir,
|
||||||
customCacheVersion = GRADLE_CACHE_VERSION,
|
customCacheVersion = GRADLE_CACHE_VERSION,
|
||||||
customCacheVersionFileName = GRADLE_CACHE_VERSION_FILE_NAME,
|
customCacheVersionFileName = GRADLE_CACHE_VERSION_FILE_NAME,
|
||||||
reportingFilters = getNonIncrementalReportingFilters(environment.compilerArgs.verbose) +
|
reportedCategories = reportCategories(verbose),
|
||||||
getIncrementalReportingFilters(environment.compilerArgs.verbose),
|
reportedSeverity = reportSeverity(verbose),
|
||||||
|
requestedCompilationResults = arrayOf(CompilationResult.IC_COMPILE_ITERATION.code),
|
||||||
compilerMode = CompileService.CompilerMode.INCREMENTAL_COMPILER,
|
compilerMode = CompileService.CompilerMode.INCREMENTAL_COMPILER,
|
||||||
targetPlatform = CompileService.TargetPlatform.JVM
|
targetPlatform = CompileService.TargetPlatform.JVM
|
||||||
)
|
)
|
||||||
val servicesFacade = GradleIncrementalCompilerServicesFacadeImpl(project, environment)
|
val servicesFacade = GradleIncrementalCompilerServicesFacadeImpl(project, environment)
|
||||||
|
|
||||||
val res = withDaemon(environment, retryOnConnectionError = true) { daemon, sessionId ->
|
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) }
|
val exitCode = res?.get()?.let { exitCodeFromProcessExitCode(it) }
|
||||||
@@ -209,36 +214,21 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil
|
|||||||
return exitCode
|
return exitCode
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getNonIncrementalReportingFilters(verbose: Boolean): List<ReportingFilter> {
|
private fun reportCategories(verbose: Boolean): Array<Int> =
|
||||||
val result = ArrayList<ReportingFilter>()
|
if (!verbose) {
|
||||||
|
arrayOf(ReportCategory.COMPILER_MESSAGE.code)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
|
ReportCategory.values().map { it.code }.toTypedArray()
|
||||||
if (verbose) {
|
}
|
||||||
result.add(ReportingFilter(ReportCategory.DAEMON_MESSAGE, emptyList()))
|
|
||||||
}
|
private fun reportSeverity(verbose: Boolean): Int =
|
||||||
|
if (!verbose) {
|
||||||
val compilerMessagesFilter = ReportingFilter(ReportCategory.COMPILER_MESSAGE, compilerMessagesSeverities)
|
ReportSeverity.INFO.code
|
||||||
result.add(compilerMessagesFilter)
|
}
|
||||||
|
else {
|
||||||
return result
|
ReportSeverity.DEBUG.code
|
||||||
}
|
|
||||||
|
|
||||||
private fun getIncrementalReportingFilters(verbose: Boolean) =
|
|
||||||
if (verbose) {
|
|
||||||
listOf(ReportingFilter(ReportCategory.INCREMENTAL_COMPILATION, listOf(IncrementalCompilationSeverity.COMPILED_FILES.value, IncrementalCompilationSeverity.LOGGING.value)))
|
|
||||||
}
|
}
|
||||||
else emptyList()
|
|
||||||
|
|
||||||
private fun compileOutOfProcess(
|
private fun compileOutOfProcess(
|
||||||
argsArray: Array<String>,
|
argsArray: Array<String>,
|
||||||
|
|||||||
Reference in New Issue
Block a user