From 47bb938b94745b977f9bf5483259a829b00b4a40 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Tue, 29 Jan 2019 00:51:55 +0300 Subject: [PATCH] Adjust build report verbosity --- .../kotlin/incremental/ICReporter.kt | 9 ++++----- .../jetbrains/kotlin/incremental/buildUtil.kt | 4 ++-- .../kotlin/daemon/report/RemoteICReporter.kt | 20 ++++++++++++++----- .../incremental/IncrementalCompilerRunner.kt | 9 +++++---- .../IncrementalJsCompilerRunner.kt | 11 ++++------ .../IncrementalJvmCompilerRunner.kt | 16 +++++++-------- .../kotlin/incremental/InputsCache.kt | 2 +- .../incremental/utils/TestICReporter.kt | 5 ++++- .../kotlin/jps/build/KotlinBuilder.kt | 8 ++++++-- 9 files changed, 48 insertions(+), 36 deletions(-) diff --git a/build-common/src/org/jetbrains/kotlin/incremental/ICReporter.kt b/build-common/src/org/jetbrains/kotlin/incremental/ICReporter.kt index 1c6a8e62bba..64afbf0323f 100644 --- a/build-common/src/org/jetbrains/kotlin/incremental/ICReporter.kt +++ b/build-common/src/org/jetbrains/kotlin/incremental/ICReporter.kt @@ -21,14 +21,13 @@ import java.io.File interface ICReporter { fun report(message: () -> String) + fun reportVerbose(message: () -> String) - // used in Gradle plugin - @Suppress("unused") - fun reportCompileIteration(sourceFiles: Collection, exitCode: ExitCode) {} + fun reportCompileIteration(incremental: Boolean, sourceFiles: Collection, exitCode: ExitCode) {} fun pathsAsString(files: Iterable): String = - files.joinToString { it.canonicalPath } + files.joinToString { it.canonicalPath } fun pathsAsString(vararg files: File): String = - pathsAsString(files.toList()) + pathsAsString(files.toList()) } \ No newline at end of file diff --git a/build-common/src/org/jetbrains/kotlin/incremental/buildUtil.kt b/build-common/src/org/jetbrains/kotlin/incremental/buildUtil.kt index 64fce730140..d9d263cb9ca 100644 --- a/build-common/src/org/jetbrains/kotlin/incremental/buildUtil.kt +++ b/build-common/src/org/jetbrains/kotlin/incremental/buildUtil.kt @@ -130,7 +130,7 @@ fun ChangesCollector.getDirtyData( val dirtyClassesFqNames = HashSet() for (change in changes()) { - reporter.report { "Process $change" } + reporter.reportVerbose { "Process $change" } if (change is ChangeInfo.SignatureChanged) { val fqNames = if (!change.areSubclassesAffected) listOf(change.fqName) else withSubtypes(change.fqName, caches) @@ -190,7 +190,7 @@ fun mapClassesFqNamesToFiles( val srcFile = cache.getSourceFileIfClass(dirtyClassFqName) if (srcFile == null || srcFile in excludes || srcFile.isJavaFile()) continue - reporter.report { ("Class $dirtyClassFqName caused recompilation of: ${reporter.pathsAsString(srcFile)}") } + reporter.report { "Class $dirtyClassFqName caused recompilation of: ${reporter.pathsAsString(srcFile)}" } dirtyFiles.add(srcFile) } } 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 fbae38fe125..cc5169478dc 100644 --- a/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/RemoteICReporter.kt +++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/RemoteICReporter.kt @@ -36,24 +36,34 @@ internal class RemoteICReporter( private val icLogLines = arrayListOf() 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() } - if (shouldReportMessages && isVerbose) { + + val shouldReportVerbose = isVerbose || !isMessageVerbose + if (shouldReportMessages && shouldReportVerbose) { servicesFacade.report(ReportCategory.IC_MESSAGE, ReportSeverity.DEBUG, lazyMessage.value) } - if (shouldReportICLog) { + if (shouldReportICLog && shouldReportVerbose) { icLogLines.add(lazyMessage.value) } } - override fun reportCompileIteration(sourceFiles: Collection, exitCode: ExitCode) { + override fun reportCompileIteration(incremental: Boolean, sourceFiles: Collection, exitCode: ExitCode) { if (shouldReportCompileIteration) { compilationResults.add( CompilationResultCategory.IC_COMPILE_ITERATION.code, CompileIterationResult(sourceFiles, exitCode.toString()) ) } - if (shouldReportICLog) { - icLogLines.add("compile iteration:") + if (shouldReportICLog && incremental) { + icLogLines.add("Compile iteration:") sourceFiles.relativePaths(rootDir).forEach { icLogLines.add(" $it") } 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 d52f538fe39..b092a200936 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 @@ -105,22 +105,22 @@ abstract class IncrementalCompilerRunner< private fun clearLocalStateOnRebuild(args: Args) { val destinationDir = destinationDir(args) - reporter.report { "Clearing output on rebuild" } + reporter.reportVerbose { "Clearing output on rebuild" } for (file in sequenceOf(destinationDir, workingDir) + outputFiles.asSequence()) { val deleted: Boolean? = when { file.isDirectory -> { - reporter.report { "Deleting directory $file" } + reporter.reportVerbose { " Deleting directory $file" } file.deleteRecursively() } file.isFile -> { - reporter.report { "Deleting $file" } + reporter.reportVerbose { " Deleting $file" } file.delete() } else -> null } if (deleted == false) { - reporter.report { "Could not delete $file" } + reporter.reportVerbose { " Could not delete $file" } } } @@ -241,6 +241,7 @@ abstract class IncrementalCompilerRunner< exitCode = runCompiler(sourcesToCompile.toSet(), args, caches, services, messageCollectorAdapter) postCompilationHook(exitCode) + reporter.reportCompileIteration(compilationMode is CompilationMode.Incremental, sourcesToCompile, exitCode) if (exitCode != ExitCode.OK) break dirtySourcesSinceLastTimeFile.delete() diff --git a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalJsCompilerRunner.kt b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalJsCompilerRunner.kt index 38d9d12164e..788b582bdf6 100644 --- a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalJsCompilerRunner.kt +++ b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalJsCompilerRunner.kt @@ -153,13 +153,10 @@ class IncrementalJsCompilerRunner( ): ExitCode { val freeArgsBackup = args.freeArgs - try { - args.freeArgs += sourcesToCompile.map() { it.absolutePath } - val exitCode = K2JSCompiler().exec(messageCollector, services, args) - reporter.reportCompileIteration(sourcesToCompile, exitCode) - return exitCode - } - finally { + return try { + args.freeArgs += sourcesToCompile.map { it.absolutePath } + K2JSCompiler().exec(messageCollector, services, args) + } finally { args.freeArgs = freeArgsBackup } } 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 b617c4922a0..5965b240b0b 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 @@ -82,6 +82,9 @@ fun makeIncrementally( object EmptyICReporter : ICReporter { override fun report(message: () -> String) { } + + override fun reportVerbose(message: () -> String) { + } } inline fun withIC(enabled: Boolean = true, fn: ()->R): R { @@ -146,7 +149,7 @@ class IncrementalJvmCompilerRunner( initDirtyFiles(dirtyFiles, changedFiles) val lastBuildInfo = BuildInfo.read(lastBuildInfoFile) ?: return CompilationMode.Rebuild { "No information on previous build" } - reporter.report { "Last Kotlin Build info -- $lastBuildInfo" } + reporter.reportVerbose { "Last Kotlin Build info -- $lastBuildInfo" } val classpathChanges = getClasspathChanges(args.classpathAsList, changedFiles, lastBuildInfo, modulesApiHistory, reporter) @@ -351,14 +354,9 @@ class IncrementalJvmCompilerRunner( args.destination = null args.buildFile = moduleFile.absolutePath - try { - reporter.report { "compiling with args: ${ArgumentUtils.convertArgumentsToStringList(args)}" } - reporter.report { "compiling with classpath: ${classpath.toList().sorted().joinToString()}" } - val exitCode = compiler.exec(messageCollector, services, args) - reporter.reportCompileIteration(sourcesToCompile, exitCode) - return exitCode - } - finally { + return try { + compiler.exec(messageCollector, services, args) + } finally { args.destination = destination moduleFile.delete() } diff --git a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/InputsCache.kt b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/InputsCache.kt index 657b80886f8..918a1793a5a 100644 --- a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/InputsCache.kt +++ b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/InputsCache.kt @@ -39,7 +39,7 @@ class InputsCache( fun removeOutputForSourceFiles(sources: Iterable) { for (sourceFile in sources) { sourceToOutputMap.remove(sourceFile).forEach { it -> - reporter.report { "Deleting $it on clearing cache for $sourceFile" } + reporter.reportVerbose { "Deleting $it on clearing cache for $sourceFile" } it.delete() } } 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 d138a400b6b..daf6b235c0c 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 @@ -32,7 +32,10 @@ class TestICReporter : ICReporter { override fun report(message: () -> String) { } - override fun reportCompileIteration(sourceFiles: Collection, exitCode: ExitCode) { + override fun reportVerbose(message: () -> String) { + } + + override fun reportCompileIteration(incremental: Boolean, sourceFiles: Collection, exitCode: ExitCode) { compiledSourcesMutable.addAll(sourceFiles) this.exitCode = exitCode } 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 7ba504e43ee..d6f50f1749e 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt @@ -661,6 +661,10 @@ private class JpsICReporter : ICReporter { KotlinBuilder.LOG.debug(message()) } } + + override fun reportVerbose(message: () -> String) { + report(message) + } } private fun ChangesCollector.processChangesUsingLookups( @@ -672,12 +676,12 @@ private fun ChangesCollector.processChangesUsingLookups( val allCaches = caches.flatMap { it.thisWithDependentCaches } val reporter = JpsICReporter() - reporter.report { "Start processing changes" } + reporter.reportVerbose { "Start processing changes" } val dirtyFiles = getDirtyFiles(allCaches, dataManager) fsOperations.markInChunkOrDependents(dirtyFiles.asIterable(), excludeFiles = compiledFiles) - reporter.report { "End of processing changes" } + reporter.reportVerbose { "End of processing changes" } } private fun ChangesCollector.getDirtyFiles(