diff --git a/build-common/src/org/jetbrains/kotlin/incremental/ICReporter.kt b/build-common/src/org/jetbrains/kotlin/incremental/ICReporter.kt index 4e7a344035c..9d726347966 100644 --- a/build-common/src/org/jetbrains/kotlin/incremental/ICReporter.kt +++ b/build-common/src/org/jetbrains/kotlin/incremental/ICReporter.kt @@ -1,17 +1,6 @@ /* - * 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. + * Copyright 2010-2019 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.incremental @@ -23,25 +12,8 @@ interface ICReporter { fun report(message: () -> String) fun reportVerbose(message: () -> String) - fun reportCompileIteration(incremental: Boolean, sourceFiles: Collection, exitCode: ExitCode) {} - - fun reportMarkDirtyClass(affectedFiles: Iterable, classFqName: String) { - reportMarkDirty(affectedFiles, "dirty class $classFqName") - } - - fun reportMarkDirtyMember(affectedFiles: Iterable, scope: String, name: String) { - reportMarkDirty(affectedFiles, "dirty member $scope#$name") - } - - fun reportMarkDirty(affectedFiles: Iterable, reason: String) { - affectedFiles.forEach { file -> - reportVerbose { "${pathsAsString(file)} is marked dirty: $reason" } - } - } - - fun pathsAsString(files: Iterable): String = - files.joinToString { it.canonicalPath } - - fun pathsAsString(vararg files: File): String = - pathsAsString(files.toList()) -} \ No newline at end of file + fun reportCompileIteration(incremental: Boolean, sourceFiles: Collection, exitCode: ExitCode) + fun reportMarkDirtyClass(affectedFiles: Iterable, classFqName: String) + fun reportMarkDirtyMember(affectedFiles: Iterable, scope: String, name: String) + fun reportMarkDirty(affectedFiles: Iterable, reason: String) +} diff --git a/build-common/src/org/jetbrains/kotlin/incremental/ICReporterBase.kt b/build-common/src/org/jetbrains/kotlin/incremental/ICReporterBase.kt new file mode 100644 index 00000000000..c762857e4eb --- /dev/null +++ b/build-common/src/org/jetbrains/kotlin/incremental/ICReporterBase.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2010-2019 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.incremental + +import java.io.File + +abstract class ICReporterBase(private val pathsBase: File? = null) : ICReporter { + override fun reportMarkDirtyClass(affectedFiles: Iterable, classFqName: String) { + reportMarkDirty(affectedFiles, "dirty class $classFqName") + } + + override fun reportMarkDirtyMember(affectedFiles: Iterable, scope: String, name: String) { + reportMarkDirty(affectedFiles, "dirty member $scope#$name") + } + + override fun reportMarkDirty(affectedFiles: Iterable, reason: String) { + affectedFiles.forEach { file -> + reportVerbose { "${pathsAsString(file)} is marked dirty: $reason" } + } + } + + protected fun relativizeIfPossible(files: Iterable): List = + files.map { it.relativeOrCanonical() } + + protected fun pathsAsString(files: Iterable): String = + relativizeIfPossible(files).map { it.path }.sorted().joinToString() + + protected fun pathsAsString(vararg files: File): String = + pathsAsString(files.toList()) + + protected fun File.relativeOrCanonical(): File = + pathsBase?.let { relativeToOrNull(it) } ?: canonicalFile +} \ No newline at end of file diff --git a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompilationResults.kt b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompilationResults.kt index 8d25e81a632..92bdec7ab7e 100644 --- a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompilationResults.kt +++ b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompilationResults.kt @@ -27,5 +27,6 @@ interface CompilationResults : Remote { enum class CompilationResultCategory(val code: Int) { IC_COMPILE_ITERATION(0), - IC_LOG(1) + BUILD_REPORT_LINES(1), + VERBOSE_BUILD_REPORT_LINES(2), } \ No newline at end of file diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt index 11f124335b5..3c3d7fef32b 100644 --- a/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt +++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt @@ -41,10 +41,7 @@ import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment import org.jetbrains.kotlin.cli.metadata.K2MetadataCompiler import org.jetbrains.kotlin.config.Services import org.jetbrains.kotlin.daemon.common.* -import org.jetbrains.kotlin.daemon.report.CompileServicesFacadeMessageCollector -import org.jetbrains.kotlin.daemon.report.DaemonMessageReporter -import org.jetbrains.kotlin.daemon.report.DaemonMessageReporterPrintStreamAdapter -import org.jetbrains.kotlin.daemon.report.RemoteICReporter +import org.jetbrains.kotlin.daemon.report.* import org.jetbrains.kotlin.incremental.* import org.jetbrains.kotlin.incremental.components.ExpectActualTracker import org.jetbrains.kotlin.incremental.components.LookupTracker @@ -501,7 +498,7 @@ class CompileServiceImpl( } args.freeArgs = freeArgsWithoutKotlinFiles - val reporter = RemoteICReporter(servicesFacade, compilationResults, incrementalCompilationOptions) + val reporter = getICReporter(servicesFacade, compilationResults, incrementalCompilationOptions) val changedFiles = if (incrementalCompilationOptions.areFileChangesKnown) { ChangedFiles.Known(incrementalCompilationOptions.modifiedFiles!!, incrementalCompilationOptions.deletedFiles!!) @@ -533,8 +530,6 @@ class CompileServiceImpl( compilerMessageCollector: MessageCollector, daemonMessageReporter: DaemonMessageReporter ): ExitCode { - val reporter = RemoteICReporter(servicesFacade, compilationResults, incrementalCompilationOptions) - val moduleFile = k2jvmArgs.buildFile?.let(::File) assert(moduleFile?.exists() ?: false) { "Module does not exist ${k2jvmArgs.buildFile}" } @@ -574,6 +569,7 @@ class CompileServiceImpl( val workingDir = incrementalCompilationOptions.workingDir + val reporter = getICReporter(servicesFacade, compilationResults, incrementalCompilationOptions) val modulesApiHistory = incrementalCompilationOptions.run { reporter.report { "Use module detection: ${multiModuleICSettings.useModuleDetection}" } diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/BuildReportICReporter.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/BuildReportICReporter.kt new file mode 100644 index 00000000000..a3d88165a32 --- /dev/null +++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/BuildReportICReporter.kt @@ -0,0 +1,51 @@ +/* + * Copyright 2010-2019 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.daemon.report + +import org.jetbrains.kotlin.cli.common.ExitCode +import org.jetbrains.kotlin.daemon.common.CompilationResultCategory +import org.jetbrains.kotlin.daemon.common.CompilationResults +import org.jetbrains.kotlin.incremental.ICReporterBase +import java.io.File +import java.util.HashMap + +internal class BuildReportICReporter( + private val compilationResults: CompilationResults, + rootDir: File, + private val isVerbose: Boolean = false +) : ICReporterBase(rootDir), RemoteICReporter { + private val icLogLines = arrayListOf() + private val recompilationReason = HashMap() + + override fun report(message: () -> String) { + icLogLines.add(message()) + } + + override fun reportVerbose(message: () -> String) { + if (isVerbose) { + report(message) + } + } + + override fun reportCompileIteration(incremental: Boolean, sourceFiles: Collection, exitCode: ExitCode) { + if (!incremental) return + + icLogLines.add("Compile iteration:") + for (file in sourceFiles) { + val reason = recompilationReason[file]?.let { " <- $it" } ?: "" + icLogLines.add(" ${file.relativeOrCanonical()}$reason") + } + recompilationReason.clear() + } + + override fun reportMarkDirty(affectedFiles: Iterable, reason: String) { + affectedFiles.forEach { recompilationReason[it] = reason } + } + + override fun flush() { + compilationResults.add(CompilationResultCategory.BUILD_REPORT_LINES.code, icLogLines) + } +} \ No newline at end of file diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/CompileIterationICReporter.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/CompileIterationICReporter.kt new file mode 100644 index 00000000000..ba8b6b7c8d3 --- /dev/null +++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/CompileIterationICReporter.kt @@ -0,0 +1,33 @@ +/* + * Copyright 2010-2019 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.daemon.report + +import org.jetbrains.kotlin.cli.common.ExitCode +import org.jetbrains.kotlin.daemon.common.CompilationResultCategory +import org.jetbrains.kotlin.daemon.common.CompilationResults +import org.jetbrains.kotlin.daemon.common.CompileIterationResult +import org.jetbrains.kotlin.incremental.ICReporterBase +import java.io.File + +internal class CompileIterationICReporter( + private val compilationResults: CompilationResults +) : ICReporterBase(), RemoteICReporter { + override fun reportCompileIteration(incremental: Boolean, sourceFiles: Collection, exitCode: ExitCode) { + compilationResults.add( + CompilationResultCategory.IC_COMPILE_ITERATION.code, + CompileIterationResult(sourceFiles, exitCode.toString()) + ) + } + + override fun report(message: () -> String) { + } + + override fun reportVerbose(message: () -> String) { + } + + override fun flush() { + } +} \ No newline at end of file diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/CompositeICReporter.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/CompositeICReporter.kt new file mode 100644 index 00000000000..bf402ed347f --- /dev/null +++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/CompositeICReporter.kt @@ -0,0 +1,40 @@ +/* + * Copyright 2010-2019 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.daemon.report + +import org.jetbrains.kotlin.cli.common.ExitCode +import java.io.File + +internal class CompositeICReporter(private val reporters: Iterable) : + RemoteICReporter { + override fun report(message: () -> String) { + reporters.forEach { it.report(message) } + } + + override fun reportVerbose(message: () -> String) { + reporters.forEach { it.reportVerbose(message) } + } + + override fun reportCompileIteration(incremental: Boolean, sourceFiles: Collection, exitCode: ExitCode) { + reporters.forEach { it.reportCompileIteration(incremental, sourceFiles, exitCode) } + } + + override fun reportMarkDirtyClass(affectedFiles: Iterable, classFqName: String) { + reporters.forEach { it.reportMarkDirtyClass(affectedFiles, classFqName) } + } + + override fun reportMarkDirtyMember(affectedFiles: Iterable, scope: String, name: String) { + reporters.forEach { it.reportMarkDirtyMember(affectedFiles, scope, name) } + } + + override fun reportMarkDirty(affectedFiles: Iterable, reason: String) { + reporters.forEach { it.reportMarkDirty(affectedFiles, reason) } + } + + override fun flush() { + reporters.forEach { it.flush() } + } +} \ No newline at end of file diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/DebugMessagesICReporter.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/DebugMessagesICReporter.kt new file mode 100644 index 00000000000..23f4f86f5dc --- /dev/null +++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/DebugMessagesICReporter.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2010-2019 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.daemon.report + +import org.jetbrains.kotlin.cli.common.ExitCode +import org.jetbrains.kotlin.daemon.common.* +import org.jetbrains.kotlin.incremental.ICReporterBase +import java.io.File + +internal class DebugMessagesICReporter( + private val servicesFacade: CompilerServicesFacadeBase, + rootDir: File, + private val isVerbose: Boolean +) : ICReporterBase(rootDir), RemoteICReporter { + override fun report(message: () -> String) { + servicesFacade.report( + ReportCategory.IC_MESSAGE, + ReportSeverity.DEBUG, message() + ) + } + + override fun reportVerbose(message: () -> String) { + if (isVerbose) { + report(message) + } + } + + override fun reportCompileIteration(incremental: Boolean, sourceFiles: Collection, exitCode: ExitCode) { + } + + override fun flush() { + } +} \ No newline at end of file diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/RemoteICReporter.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/RemoteICReporter.kt index 2006c33a897..e19128cffbf 100644 --- a/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/RemoteICReporter.kt +++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/RemoteICReporter.kt @@ -1,95 +1,12 @@ /* - * 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. + * Copyright 2010-2019 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.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 - -internal class RemoteICReporter( - private val servicesFacade: CompilerServicesFacadeBase, - private val compilationResults: CompilationResults, - compilationOptions: IncrementalCompilationOptions -) : ICReporter { - - private val rootDir = compilationOptions.modulesInfo.projectRoot - private val shouldReportMessages = ReportCategory.IC_MESSAGE.code in compilationOptions.reportCategories - private val isVerbose = compilationOptions.reportSeverity == ReportSeverity.DEBUG.code - private val shouldReportCompileIteration = - CompilationResultCategory.IC_COMPILE_ITERATION.code in compilationOptions.requestedCompilationResults - private val shouldReportICLog = CompilationResultCategory.IC_LOG.code in compilationOptions.requestedCompilationResults - private val icLogLines = arrayListOf() - private val recompilationReason = HashMap() - - override fun report(message: () -> String) { - reportImpl(isMessageVerbose = false, message = message) - } - - override fun reportVerbose(message: () -> String) { - reportImpl(isMessageVerbose = true, message = message) - } - - private fun reportImpl(isMessageVerbose: Boolean, message: () -> String) { - val lazyMessage = lazy { message() } - - val shouldReportVerbose = isVerbose || !isMessageVerbose - if (shouldReportMessages && shouldReportVerbose) { - servicesFacade.report(ReportCategory.IC_MESSAGE, ReportSeverity.DEBUG, lazyMessage.value) - } - if (shouldReportICLog && shouldReportVerbose) { - icLogLines.add(lazyMessage.value) - } - } - - override fun reportCompileIteration(incremental: Boolean, sourceFiles: Collection, exitCode: ExitCode) { - if (shouldReportCompileIteration) { - compilationResults.add( - CompilationResultCategory.IC_COMPILE_ITERATION.code, - CompileIterationResult(sourceFiles, exitCode.toString()) - ) - } - if (shouldReportICLog && incremental) { - icLogLines.add("Compile iteration:") - sourceFiles.relativePaths(rootDir).forEach { file -> - val reason = recompilationReason[file]?.let { " <- $it" } ?: "" - icLogLines.add(" $file$reason") - } - recompilationReason.clear() - } - } - - override fun reportMarkDirty(affectedFiles: Iterable, reason: String) { - super.reportMarkDirty(affectedFiles, reason) - if (shouldReportICLog) { - affectedFiles.forEach { recompilationReason[it] = reason } - } - } - - fun flush() { - if (shouldReportICLog) { - compilationResults.add(CompilationResultCategory.IC_LOG.code, icLogLines) - } - } - - private fun File.relativeOrCanonical(base: File): String = - relativeToOrNull(base)?.path ?: canonicalPath - - private fun Iterable.relativePaths(base: File): List = - map { it.relativeOrCanonical(base) }.sorted() -} +internal interface RemoteICReporter : ICReporter { + fun flush() +} \ No newline at end of file diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/getICReporter.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/getICReporter.kt new file mode 100644 index 00000000000..c5849dafad0 --- /dev/null +++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/getICReporter.kt @@ -0,0 +1,58 @@ +/* + * 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.daemon.common.* +import java.io.File +import java.util.* + +internal fun getICReporter( + servicesFacade: CompilerServicesFacadeBase, + compilationResults: CompilationResults, + compilationOptions: IncrementalCompilationOptions +): RemoteICReporter { + val root = compilationOptions.modulesInfo.projectRoot + val reporters = ArrayList() + + if (ReportCategory.IC_MESSAGE.code in compilationOptions.reportCategories) { + val isVerbose = compilationOptions.reportSeverity == ReportSeverity.DEBUG.code + reporters.add(DebugMessagesICReporter(servicesFacade, root, isVerbose = isVerbose)) + } + + val requestedResults = compilationOptions + .requestedCompilationResults + .mapNotNullTo(HashSet()) { resultCode -> + CompilationResultCategory.values().getOrNull(resultCode) + } + requestedResults.mapTo(reporters) { requestedResult -> + when (requestedResult) { + CompilationResultCategory.IC_COMPILE_ITERATION -> { + CompileIterationICReporter(compilationResults) + } + CompilationResultCategory.BUILD_REPORT_LINES -> { + BuildReportICReporter(compilationResults, root) + } + CompilationResultCategory.VERBOSE_BUILD_REPORT_LINES -> { + BuildReportICReporter(compilationResults, root, isVerbose = true) + } + } + } + + return CompositeICReporter(reporters) +} + + diff --git a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalCompilerRunner.kt b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalCompilerRunner.kt index 449e18d8d87..844c890787f 100644 --- a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalCompilerRunner.kt +++ b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalCompilerRunner.kt @@ -144,10 +144,6 @@ abstract class IncrementalCompilerRunner< if (dirtySourcesSinceLastTimeFile.exists()) { val files = dirtySourcesSinceLastTimeFile.readLines().map(::File) - if (files.isNotEmpty()) { - reporter.reportVerbose { "Source files added since last compilation: ${reporter.pathsAsString(files)}" } - } - dirtyFiles.add(files, "was not compiled last time") } } diff --git a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalJvmCompilerRunner.kt b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalJvmCompilerRunner.kt index 5965b240b0b..f9abe3dd809 100644 --- a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalJvmCompilerRunner.kt +++ b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalJvmCompilerRunner.kt @@ -32,7 +32,6 @@ import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment -import org.jetbrains.kotlin.compilerRunner.ArgumentUtils import org.jetbrains.kotlin.config.CompilerConfiguration import org.jetbrains.kotlin.config.IncrementalCompilation import org.jetbrains.kotlin.config.Services @@ -79,7 +78,10 @@ fun makeIncrementally( } } -object EmptyICReporter : ICReporter { +object EmptyICReporter : ICReporterBase() { + override fun reportCompileIteration(incremental: Boolean, sourceFiles: Collection, exitCode: ExitCode) { + } + override fun report(message: () -> String) { } diff --git a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/utils/TestICReporter.kt b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/utils/TestICReporter.kt index daf6b235c0c..68b39eccfb7 100644 --- a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/utils/TestICReporter.kt +++ b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/utils/TestICReporter.kt @@ -17,10 +17,10 @@ package org.jetbrains.kotlin.incremental.utils import org.jetbrains.kotlin.cli.common.ExitCode -import org.jetbrains.kotlin.incremental.ICReporter +import org.jetbrains.kotlin.incremental.ICReporterBase import java.io.File -class TestICReporter : ICReporter { +class TestICReporter : ICReporterBase() { private val compiledSourcesMutable = arrayListOf() val compiledSources: List diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt index 6230e93bdd3..ae3bb106cd9 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt @@ -30,6 +30,7 @@ import org.jetbrains.jps.incremental.java.JavaBuilder import org.jetbrains.jps.incremental.storage.BuildDataManager import org.jetbrains.jps.model.JpsProject import org.jetbrains.kotlin.build.GeneratedFile +import org.jetbrains.kotlin.cli.common.ExitCode import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.* @@ -42,6 +43,7 @@ import org.jetbrains.kotlin.daemon.common.isDaemonEnabled import org.jetbrains.kotlin.incremental.* import org.jetbrains.kotlin.incremental.components.ExpectActualTracker import org.jetbrains.kotlin.incremental.components.LookupTracker +import org.jetbrains.kotlin.incremental.ICReporterBase import org.jetbrains.kotlin.jps.incremental.JpsIncrementalCache import org.jetbrains.kotlin.jps.incremental.withLookupStorage import org.jetbrains.kotlin.jps.model.kotlinKind @@ -654,7 +656,10 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) { } } -private class JpsICReporter : ICReporter { +private class JpsICReporter : ICReporterBase() { + override fun reportCompileIteration(incremental: Boolean, sourceFiles: Collection, exitCode: ExitCode) { + } + override fun report(message: () -> String) { if (KotlinBuilder.LOG.isDebugEnabled) { KotlinBuilder.LOG.debug(message()) diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleCompilationResults.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleCompilationResults.kt index 553eb9d978e..d2a102af802 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleCompilationResults.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleCompilationResults.kt @@ -39,7 +39,8 @@ internal class GradleCompilationResults( log.kotlinDebug { "compiler exit code: $exitCode" } } } - CompilationResultCategory.IC_LOG.code -> { + CompilationResultCategory.BUILD_REPORT_LINES.code, + CompilationResultCategory.VERBOSE_BUILD_REPORT_LINES.code -> { @Suppress("UNCHECKED_CAST") icLogLines = value as? List } diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleCompilerEnvironment.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleCompilerEnvironment.kt index 3aa360133eb..4748585691b 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleCompilerEnvironment.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleCompilerEnvironment.kt @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.compilerRunner import org.gradle.api.file.FileCollection import org.jetbrains.kotlin.config.Services import org.jetbrains.kotlin.gradle.logging.GradlePrintingMessageCollector +import org.jetbrains.kotlin.gradle.report.BuildReportMode import org.jetbrains.kotlin.gradle.tasks.findToolsJar import java.io.File @@ -16,7 +17,7 @@ internal class GradleCompilerEnvironment( messageCollector: GradlePrintingMessageCollector, outputItemsCollector: OutputItemsCollector, val outputFiles: FileCollection, - val reportExecutionResult: Boolean, + val buildReportMode: BuildReportMode?, val incrementalCompilationEnvironment: IncrementalCompilationEnvironment? = null ) : CompilerEnvironment(Services.EMPTY, messageCollector, outputItemsCollector) { val toolsJar: File? by lazy { findToolsJar() } diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinCompilerRunner.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinCompilerRunner.kt index d55d52e355b..c22fee1c20a 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinCompilerRunner.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinCompilerRunner.kt @@ -142,7 +142,7 @@ internal open class GradleCompilerRunner(protected val task: Task) { buildFile = buildFile, outputFiles = environment.outputFiles.toList(), taskPath = task.path, - reportExecutionResult = environment.reportExecutionResult + buildReportMode = environment.buildReportMode ) TaskLoggers.put(task.path, task.logger) runCompilerAsync(workArgs) diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinCompilerWork.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinCompilerWork.kt index 96926725e9e..a76e3f30d6a 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinCompilerWork.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinCompilerWork.kt @@ -13,6 +13,7 @@ import org.jetbrains.kotlin.daemon.common.* import org.jetbrains.kotlin.gradle.logging.* import org.jetbrains.kotlin.gradle.plugin.internal.state.TaskExecutionResults import org.jetbrains.kotlin.gradle.plugin.internal.state.TaskLoggers +import org.jetbrains.kotlin.gradle.report.BuildReportMode import org.jetbrains.kotlin.gradle.report.TaskExecutionResult import org.jetbrains.kotlin.gradle.tasks.throwGradleExceptionIfError import org.jetbrains.kotlin.gradle.utils.stackTraceAsString @@ -54,7 +55,7 @@ internal class GradleKotlinCompilerWorkArguments( val buildFile: File?, val outputFiles: List, val taskPath: String, - val reportExecutionResult: Boolean + val buildReportMode: BuildReportMode? ) : Serializable { companion object { const val serialVersionUID: Long = 0 @@ -92,7 +93,7 @@ internal class GradleKotlinCompilerWork @Inject constructor( private val buildFile = config.buildFile private val outputFiles = config.outputFiles private val taskPath = config.taskPath - private val reportExecutionResult = config.reportExecutionResult + private val buildReportMode = config.buildReportMode private val log: KotlinLogger = TaskLoggers.get(taskPath)?.let { GradleKotlinLogger(it).apply { debug("Using '$taskPath' logger") } } @@ -253,9 +254,11 @@ internal class GradleKotlinCompilerWork @Inject constructor( val knownChangedFiles = icEnv.changedFiles as? ChangedFiles.Known val requestedCompilationResults = EnumSet.of(CompilationResultCategory.IC_COMPILE_ITERATION) - if (reportExecutionResult) { - requestedCompilationResults.add(CompilationResultCategory.IC_LOG) - } + when (buildReportMode) { + BuildReportMode.SIMPLE -> CompilationResultCategory.BUILD_REPORT_LINES + BuildReportMode.VERBOSE -> CompilationResultCategory.VERBOSE_BUILD_REPORT_LINES + null -> null + }?.let { requestedCompilationResults.add(it) } val compilationOptions = IncrementalCompilationOptions( areFileChangesKnown = knownChangedFiles != null, @@ -366,7 +369,7 @@ internal class GradleKotlinCompilerWork @Inject constructor( } private inline fun reportExecutionResultIfNeeded(fn: () -> TaskExecutionResult) { - if (reportExecutionResult) { + if (buildReportMode != null) { val result = fn() TaskExecutionResults[taskPath] = result } diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/kapt/KaptWithKotlincTask.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/kapt/KaptWithKotlincTask.kt index 5dfd476f30d..807fbbcb94f 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/kapt/KaptWithKotlincTask.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/kapt/KaptWithKotlincTask.kt @@ -64,7 +64,7 @@ open class KaptWithKotlincTask : KaptTask(), CompilerArgumentAwareWithInput graph.allTasks.asSequence() .filterIsInstance>() - .forEach { it.reportExecutionResult = true } + .forEach { it.buildReportMode = buildReportMode } } log.kotlinDebug { "Configured Kotlin build reporter" } diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/KotlinCompileCommon.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/KotlinCompileCommon.kt index 696a18a600c..50c270885e1 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/KotlinCompileCommon.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/KotlinCompileCommon.kt @@ -71,7 +71,7 @@ open class KotlinCompileCommon : AbstractKotlinCompile() : AbstractKo } @get:Internal - var reportExecutionResult: Boolean = false + internal var buildReportMode: BuildReportMode? = null @get:Internal internal val buildHistoryFile: File @@ -439,7 +440,7 @@ open class KotlinCompile : AbstractKotlinCompile(), Kotl val environment = GradleCompilerEnvironment( computedCompilerClasspath, messageCollector, outputItemCollector, outputFiles = allOutputFiles(), - reportExecutionResult = reportExecutionResult, + buildReportMode = buildReportMode, incrementalCompilationEnvironment = icEnv ) compilerRunner.runJvmCompilerAsync( @@ -597,7 +598,7 @@ open class Kotlin2JsCompile : AbstractKotlinCompile(), Ko val environment = GradleCompilerEnvironment( computedCompilerClasspath, messageCollector, outputItemCollector, outputFiles = allOutputFiles(), - reportExecutionResult = reportExecutionResult, + buildReportMode = buildReportMode, incrementalCompilationEnvironment = icEnv ) compilerRunner.runJsCompilerAsync(sourceRoots.kotlinSourceFiles, commonSourceSet.toList(), args, environment)