diff --git a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/incremental/compilerUtils.kt b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/incremental/compilerUtils.kt index 0662ebd3ee6..1eae8c7231f 100644 --- a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/incremental/compilerUtils.kt +++ b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/incremental/compilerUtils.kt @@ -34,7 +34,14 @@ fun createTestingCompilerEnvironment( val paths = PathUtil.kotlinPathsForDistDirectory val wrappedMessageCollector = MessageCollectorToOutputItemsCollectorAdapter(messageCollector, outputItemsCollector) - return JpsCompilerEnvironment(paths, services, KotlinBuilder.classesToLoadByParent, wrappedMessageCollector, outputItemsCollector) + return JpsCompilerEnvironment( + paths, + services, + KotlinBuilder.classesToLoadByParent, + wrappedMessageCollector, + outputItemsCollector, + MockProgressReporter + ) } fun runJSCompiler(args: K2JSCompilerArguments, env: JpsCompilerEnvironment): ExitCode? { @@ -46,4 +53,15 @@ fun runJSCompiler(args: K2JSCompilerArguments, env: JpsCompilerEnvironment): Exi val reader = BufferedReader(StringReader(stream.toString())) CompilerOutputParser.parseCompilerMessagesFromReader(env.messageCollector, reader, env.outputItemsCollector) return exitCode as? ExitCode +} + +private object MockProgressReporter : ProgressReporter { + override fun progress(message: String) { + } + + override fun compilationStarted() { + } + + override fun clearProgress() { + } } \ No newline at end of file diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsCompilerEnvironment.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsCompilerEnvironment.kt index bd08f0fb4bd..42ec2da3431 100644 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsCompilerEnvironment.kt +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsCompilerEnvironment.kt @@ -26,7 +26,8 @@ class JpsCompilerEnvironment( services: Services, val classesToLoadByParent: ClassCondition, messageCollector: MessageCollector, - outputItemsCollector: OutputItemsCollectorImpl + outputItemsCollector: OutputItemsCollectorImpl, + val progressReporter: ProgressReporter ) : CompilerEnvironment(services, messageCollector, outputItemsCollector) { override val outputItemsCollector: OutputItemsCollectorImpl get() = super.outputItemsCollector as OutputItemsCollectorImpl diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt index 1e126d35096..ba5552fbb43 100644 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt @@ -174,7 +174,16 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner() { requestedCompilationResults = emptyArray() ) return doWithDaemon(environment) { sessionId, daemon -> - daemon.compile(sessionId, withAdditionalCompilerArgs(compilerArgs), options, JpsCompilerServicesFacadeImpl(environment), null) + environment.withProgressReporter { progress -> + progress.compilationStarted() + daemon.compile( + sessionId, + withAdditionalCompilerArgs(compilerArgs), + options, + JpsCompilerServicesFacadeImpl(environment), + null + ) + } }?.let { exitCodeFromProcessExitCode(it) } } @@ -248,7 +257,10 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner() { if (System.getProperty(GlobalOptions.COMPILE_PARALLEL_OPTION, "false").toBoolean()) System.setProperty(KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY, "true") - val rc = CompilerRunnerUtil.invokeExecMethod(compilerClassName, withAdditionalCompilerArgs(compilerArgs), environment, out) + val rc = environment.withProgressReporter { progress -> + progress.compilationStarted() + CompilerRunnerUtil.invokeExecMethod(compilerClassName, withAdditionalCompilerArgs(compilerArgs), environment, out) + } // exec() returns an ExitCode object, class of which is loaded with a different class loader, // so we take it's contents through reflection @@ -292,6 +304,7 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner() { override fun getDaemonConnection(environment: JpsCompilerEnvironment): CompileServiceSession? = getOrCreateDaemonConnection { + environment.progressReporter.progress("connecting to daemon") val libPath = CompilerRunnerUtil.getLibPath(environment.kotlinPaths, environment.messageCollector) val compilerPath = File(libPath, "kotlin-compiler.jar") val toolsJarPath = CompilerRunnerUtil.jdkToolsJar @@ -300,6 +313,10 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner() { val clientFlagFile = KotlinCompilerClient.getOrCreateClientFlagFile(daemonOptions) val sessionFlagFile = makeAutodeletingFlagFile("compiler-jps-session-", File(daemonOptions.runFilesPathOrDefault)) - newDaemonConnection(compilerId, clientFlagFile, sessionFlagFile, environment, daemonOptions) + + environment.withProgressReporter { progress -> + progress.progress("connecting to daemon") + newDaemonConnection(compilerId, clientFlagFile, sessionFlagFile, environment, daemonOptions) + } } } diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/ProgressReporter.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/ProgressReporter.kt new file mode 100644 index 00000000000..ff8e3f9c615 --- /dev/null +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/ProgressReporter.kt @@ -0,0 +1,38 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.compilerRunner + +import org.jetbrains.jps.ModuleChunk +import org.jetbrains.jps.incremental.CompileContext +import org.jetbrains.jps.incremental.messages.ProgressMessage + +interface ProgressReporter { + fun progress(message: String) + fun compilationStarted() + fun clearProgress() +} + +class ProgressReporterImpl(private val context: CompileContext, private val chunk: ModuleChunk) : ProgressReporter { + override fun progress(message: String) { + context.processMessage(ProgressMessage("Kotlin: $message")) + } + + override fun compilationStarted() { + progress("compiling [${chunk.presentableShortName}]") + } + + override fun clearProgress() { + context.processMessage(ProgressMessage("")) + } + +} + +inline fun JpsCompilerEnvironment.withProgressReporter(fn: (ProgressReporter) -> T): T = + try { + fn(progressReporter) + } finally { + progressReporter.clearProgress() + } \ No newline at end of file diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt index 1cd7fd20eab..2e5efb90006 100644 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt @@ -34,6 +34,7 @@ import org.jetbrains.jps.incremental.ModuleLevelBuilder.ExitCode.* import org.jetbrains.jps.incremental.java.JavaBuilder import org.jetbrains.jps.incremental.messages.BuildMessage import org.jetbrains.jps.incremental.messages.CompilerMessage +import org.jetbrains.jps.incremental.messages.ProgressMessage import org.jetbrains.jps.incremental.storage.BuildDataManager import org.jetbrains.jps.model.JpsProject import org.jetbrains.jps.model.java.JpsJavaClasspathKind @@ -176,7 +177,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) { val incrementalCaches = getIncrementalCaches(chunk, context) val messageCollector = MessageCollectorAdapter(context) - val environment = createCompileEnvironment(incrementalCaches, LookupTracker.DO_NOTHING, context, messageCollector) + val environment = createCompileEnvironment(incrementalCaches, LookupTracker.DO_NOTHING, context, chunk, messageCollector) if (environment == null) return val removedClasses = HashSet() @@ -347,7 +348,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) { val project = projectDescriptor.project val lookupTracker = getLookupTracker(project) val incrementalCaches = getIncrementalCaches(chunk, context) - val environment = createCompileEnvironment(incrementalCaches, lookupTracker, context, messageCollector) ?: return ABORT + val environment = createCompileEnvironment(incrementalCaches, lookupTracker, context, chunk, messageCollector) ?: return ABORT val commonArguments = compilerArgumentsForChunk(chunk).apply { reportOutputFiles = true @@ -405,17 +406,24 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) { context.checkCanceled() - val changesCollector = ChangesCollector() - for ((target, files) in generatedFiles) { - updateIncrementalCache(files, incrementalCaches[target]!!, changesCollector, null) - } - updateLookupStorage(chunk, lookupTracker, dataManager, dirtyFilesHolder, filesToCompile) + environment.withProgressReporter { progress -> + progress.progress("updating IC caches") - if (isChunkRebuilding) { - return OK - } + val changesCollector = ChangesCollector() + for ((target, files) in generatedFiles) { + updateIncrementalCache(files, incrementalCaches[target]!!, changesCollector, null) + } + updateLookupStorage(chunk, lookupTracker, dataManager, dirtyFilesHolder, filesToCompile) - changesCollector.processChangesUsingLookups(filesToCompile.values().toSet(), dataManager, fsOperations, incrementalCaches.values) + if (!isChunkRebuilding) { + changesCollector.processChangesUsingLookups( + filesToCompile.values().toSet(), + dataManager, + fsOperations, + incrementalCaches.values + ) + } + } return OK } @@ -567,6 +575,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) { incrementalCaches: Map, lookupTracker: LookupTracker, context: CompileContext, + chunk: ModuleChunk, messageCollector: MessageCollectorAdapter ): JpsCompilerEnvironment? { val compilerServices = with(Services.Builder()) { @@ -597,7 +606,8 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) { compilerServices, classesToLoadByParent, messageCollector, - OutputItemsCollectorImpl() + OutputItemsCollectorImpl(), + ProgressReporterImpl(context, chunk) ) }