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:
Alexey Tsvetkov
2019-02-05 23:49:10 +03:00
parent 01c23510c7
commit dbdc7a5b07
24 changed files with 320 additions and 155 deletions
@@ -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<File>, exitCode: ExitCode) {}
fun reportMarkDirtyClass(affectedFiles: Iterable<File>, classFqName: String) {
reportMarkDirty(affectedFiles, "dirty class $classFqName")
}
fun reportMarkDirtyMember(affectedFiles: Iterable<File>, scope: String, name: String) {
reportMarkDirty(affectedFiles, "dirty member $scope#$name")
}
fun reportMarkDirty(affectedFiles: Iterable<File>, reason: String) {
affectedFiles.forEach { file ->
reportVerbose { "${pathsAsString(file)} is marked dirty: $reason" }
}
}
fun pathsAsString(files: Iterable<File>): String =
files.joinToString { it.canonicalPath }
fun pathsAsString(vararg files: File): String =
pathsAsString(files.toList())
}
fun reportCompileIteration(incremental: Boolean, sourceFiles: Collection<File>, exitCode: ExitCode)
fun reportMarkDirtyClass(affectedFiles: Iterable<File>, classFqName: String)
fun reportMarkDirtyMember(affectedFiles: Iterable<File>, scope: String, name: String)
fun reportMarkDirty(affectedFiles: Iterable<File>, reason: String)
}
@@ -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<File>, classFqName: String) {
reportMarkDirty(affectedFiles, "dirty class $classFqName")
}
override fun reportMarkDirtyMember(affectedFiles: Iterable<File>, scope: String, name: String) {
reportMarkDirty(affectedFiles, "dirty member $scope#$name")
}
override fun reportMarkDirty(affectedFiles: Iterable<File>, reason: String) {
affectedFiles.forEach { file ->
reportVerbose { "${pathsAsString(file)} is marked dirty: $reason" }
}
}
protected fun relativizeIfPossible(files: Iterable<File>): List<File> =
files.map { it.relativeOrCanonical() }
protected fun pathsAsString(files: Iterable<File>): 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
}
@@ -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)
}
@@ -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")
}
}
@@ -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) {
}
@@ -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>
@@ -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<File>, exitCode: ExitCode) {
}
override fun report(message: () -> String) {
if (KotlinBuilder.LOG.isDebugEnabled) {
KotlinBuilder.LOG.debug(message())
@@ -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<String>
}
@@ -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() }
@@ -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)
@@ -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<File>,
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
}
@@ -64,7 +64,7 @@ open class KaptWithKotlincTask : KaptTask(), CompilerArgumentAwareWithInput<K2JV
val outputItemCollector = OutputItemsCollectorImpl()
val environment = GradleCompilerEnvironment(
compilerClasspath, messageCollector, outputItemCollector,
reportExecutionResult = kotlinCompileTask.reportExecutionResult,
buildReportMode = kotlinCompileTask.buildReportMode,
outputFiles = allOutputFiles()
)
if (environment.toolsJar == null && !isAtLeastJava9) {
@@ -59,6 +59,9 @@ internal class PropertiesProvider(private val project: Project) {
val buildReportEnabled: Boolean
get() = booleanProperty("kotlin.build.report.enable") ?: false
val buildReportVerbose: Boolean
get() = booleanProperty("kotlin.build.report.verbose") ?: false
val buildReportDir: File?
get() = property("kotlin.build.report.dir")?.let { File(it) }
@@ -0,0 +1,11 @@
/*
* 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.gradle.report
enum class BuildReportMode {
SIMPLE,
VERBOSE
}
@@ -43,10 +43,12 @@ internal fun configureBuildReporter(gradle: Gradle, log: Logger) {
val reporter = KotlinBuildReporter(perfReportFile)
gradle.addBuildListener(reporter)
val buildReportMode = if (properties.buildReportVerbose) BuildReportMode.VERBOSE else BuildReportMode.SIMPLE
gradle.taskGraph.whenReady { graph ->
graph.allTasks.asSequence()
.filterIsInstance<AbstractKotlinCompile<*>>()
.forEach { it.reportExecutionResult = true }
.forEach { it.buildReportMode = buildReportMode }
}
log.kotlinDebug { "Configured Kotlin build reporter" }
@@ -71,7 +71,7 @@ open class KotlinCompileCommon : AbstractKotlinCompile<K2MetadataCompilerArgumen
val compilerRunner = compilerRunner()
val environment = GradleCompilerEnvironment(
computedCompilerClasspath, messageCollector, outputItemCollector,
reportExecutionResult = reportExecutionResult,
buildReportMode = buildReportMode,
outputFiles = allOutputFiles()
)
compilerRunner.runMetadataCompilerAsync(sourceRoots.kotlinSourceFiles, args, environment)
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.gradle.internal.tasks.TaskWithLocalState
import org.jetbrains.kotlin.gradle.internal.tasks.allOutputFiles
import org.jetbrains.kotlin.gradle.logging.*
import org.jetbrains.kotlin.gradle.plugin.*
import org.jetbrains.kotlin.gradle.report.BuildReportMode
import org.jetbrains.kotlin.gradle.utils.*
import org.jetbrains.kotlin.incremental.ChangedFiles
import org.jetbrains.kotlin.incremental.classpathAsList
@@ -133,7 +134,7 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : 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<K2JVMCompilerArguments>(), 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<K2JSCompilerArguments>(), Ko
val environment = GradleCompilerEnvironment(
computedCompilerClasspath, messageCollector, outputItemCollector,
outputFiles = allOutputFiles(),
reportExecutionResult = reportExecutionResult,
buildReportMode = buildReportMode,
incrementalCompilationEnvironment = icEnv
)
compilerRunner.runJsCompilerAsync(sourceRoots.kotlinSourceFiles, commonSourceSet.toList(), args, environment)