Add verbose mode to build reports
#KT-12700 Verbose mode can be enabled by adding `kotlin.build.report.verbose=true` to `gradle.properties` file.
This commit is contained in:
+2
-1
@@ -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),
|
||||
}
|
||||
@@ -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}" }
|
||||
|
||||
|
||||
@@ -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<String>()
|
||||
private val recompilationReason = HashMap<File, String>()
|
||||
|
||||
override fun report(message: () -> String) {
|
||||
icLogLines.add(message())
|
||||
}
|
||||
|
||||
override fun reportVerbose(message: () -> String) {
|
||||
if (isVerbose) {
|
||||
report(message)
|
||||
}
|
||||
}
|
||||
|
||||
override fun reportCompileIteration(incremental: Boolean, sourceFiles: Collection<File>, 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<File>, reason: String) {
|
||||
affectedFiles.forEach { recompilationReason[it] = reason }
|
||||
}
|
||||
|
||||
override fun flush() {
|
||||
compilationResults.add(CompilationResultCategory.BUILD_REPORT_LINES.code, icLogLines)
|
||||
}
|
||||
}
|
||||
@@ -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<File>, 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() {
|
||||
}
|
||||
}
|
||||
@@ -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>) :
|
||||
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<File>, exitCode: ExitCode) {
|
||||
reporters.forEach { it.reportCompileIteration(incremental, sourceFiles, exitCode) }
|
||||
}
|
||||
|
||||
override fun reportMarkDirtyClass(affectedFiles: Iterable<File>, classFqName: String) {
|
||||
reporters.forEach { it.reportMarkDirtyClass(affectedFiles, classFqName) }
|
||||
}
|
||||
|
||||
override fun reportMarkDirtyMember(affectedFiles: Iterable<File>, scope: String, name: String) {
|
||||
reporters.forEach { it.reportMarkDirtyMember(affectedFiles, scope, name) }
|
||||
}
|
||||
|
||||
override fun reportMarkDirty(affectedFiles: Iterable<File>, reason: String) {
|
||||
reporters.forEach { it.reportMarkDirty(affectedFiles, reason) }
|
||||
}
|
||||
|
||||
override fun flush() {
|
||||
reporters.forEach { it.flush() }
|
||||
}
|
||||
}
|
||||
@@ -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<File>, exitCode: ExitCode) {
|
||||
}
|
||||
|
||||
override fun flush() {
|
||||
}
|
||||
}
|
||||
@@ -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<String>()
|
||||
private val recompilationReason = HashMap<File, String>()
|
||||
|
||||
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<File>, 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<File>, 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<File>.relativePaths(base: File): List<String> =
|
||||
map { it.relativeOrCanonical(base) }.sorted()
|
||||
}
|
||||
|
||||
internal interface RemoteICReporter : ICReporter {
|
||||
fun flush()
|
||||
}
|
||||
@@ -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<RemoteICReporter>()
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
-4
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -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<File>, exitCode: ExitCode) {
|
||||
}
|
||||
|
||||
override fun report(message: () -> String) {
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -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<File>()
|
||||
|
||||
val compiledSources: List<File>
|
||||
|
||||
Reference in New Issue
Block a user