Adjust build report verbosity

This commit is contained in:
Alexey Tsvetkov
2019-01-29 00:51:55 +03:00
parent 98ef00b957
commit 47bb938b94
9 changed files with 48 additions and 36 deletions
@@ -21,14 +21,13 @@ import java.io.File
interface ICReporter { interface ICReporter {
fun report(message: () -> String) fun report(message: () -> String)
fun reportVerbose(message: () -> String)
// used in Gradle plugin fun reportCompileIteration(incremental: Boolean, sourceFiles: Collection<File>, exitCode: ExitCode) {}
@Suppress("unused")
fun reportCompileIteration(sourceFiles: Collection<File>, exitCode: ExitCode) {}
fun pathsAsString(files: Iterable<File>): String = fun pathsAsString(files: Iterable<File>): String =
files.joinToString { it.canonicalPath } files.joinToString { it.canonicalPath }
fun pathsAsString(vararg files: File): String = fun pathsAsString(vararg files: File): String =
pathsAsString(files.toList()) pathsAsString(files.toList())
} }
@@ -130,7 +130,7 @@ fun ChangesCollector.getDirtyData(
val dirtyClassesFqNames = HashSet<FqName>() val dirtyClassesFqNames = HashSet<FqName>()
for (change in changes()) { for (change in changes()) {
reporter.report { "Process $change" } reporter.reportVerbose { "Process $change" }
if (change is ChangeInfo.SignatureChanged) { if (change is ChangeInfo.SignatureChanged) {
val fqNames = if (!change.areSubclassesAffected) listOf(change.fqName) else withSubtypes(change.fqName, caches) val fqNames = if (!change.areSubclassesAffected) listOf(change.fqName) else withSubtypes(change.fqName, caches)
@@ -190,7 +190,7 @@ fun mapClassesFqNamesToFiles(
val srcFile = cache.getSourceFileIfClass(dirtyClassFqName) val srcFile = cache.getSourceFileIfClass(dirtyClassFqName)
if (srcFile == null || srcFile in excludes || srcFile.isJavaFile()) continue 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) dirtyFiles.add(srcFile)
} }
} }
@@ -36,24 +36,34 @@ internal class RemoteICReporter(
private val icLogLines = arrayListOf<String>() private val icLogLines = arrayListOf<String>()
override fun report(message: () -> 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 lazyMessage = lazy { message() }
if (shouldReportMessages && isVerbose) {
val shouldReportVerbose = isVerbose || !isMessageVerbose
if (shouldReportMessages && shouldReportVerbose) {
servicesFacade.report(ReportCategory.IC_MESSAGE, ReportSeverity.DEBUG, lazyMessage.value) servicesFacade.report(ReportCategory.IC_MESSAGE, ReportSeverity.DEBUG, lazyMessage.value)
} }
if (shouldReportICLog) { if (shouldReportICLog && shouldReportVerbose) {
icLogLines.add(lazyMessage.value) icLogLines.add(lazyMessage.value)
} }
} }
override fun reportCompileIteration(sourceFiles: Collection<File>, exitCode: ExitCode) { override fun reportCompileIteration(incremental: Boolean, sourceFiles: Collection<File>, exitCode: ExitCode) {
if (shouldReportCompileIteration) { if (shouldReportCompileIteration) {
compilationResults.add( compilationResults.add(
CompilationResultCategory.IC_COMPILE_ITERATION.code, CompilationResultCategory.IC_COMPILE_ITERATION.code,
CompileIterationResult(sourceFiles, exitCode.toString()) CompileIterationResult(sourceFiles, exitCode.toString())
) )
} }
if (shouldReportICLog) { if (shouldReportICLog && incremental) {
icLogLines.add("compile iteration:") icLogLines.add("Compile iteration:")
sourceFiles.relativePaths(rootDir).forEach { sourceFiles.relativePaths(rootDir).forEach {
icLogLines.add(" $it") icLogLines.add(" $it")
} }
@@ -105,22 +105,22 @@ abstract class IncrementalCompilerRunner<
private fun clearLocalStateOnRebuild(args: Args) { private fun clearLocalStateOnRebuild(args: Args) {
val destinationDir = destinationDir(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()) { for (file in sequenceOf(destinationDir, workingDir) + outputFiles.asSequence()) {
val deleted: Boolean? = when { val deleted: Boolean? = when {
file.isDirectory -> { file.isDirectory -> {
reporter.report { "Deleting directory $file" } reporter.reportVerbose { " Deleting directory $file" }
file.deleteRecursively() file.deleteRecursively()
} }
file.isFile -> { file.isFile -> {
reporter.report { "Deleting $file" } reporter.reportVerbose { " Deleting $file" }
file.delete() file.delete()
} }
else -> null else -> null
} }
if (deleted == false) { 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) exitCode = runCompiler(sourcesToCompile.toSet(), args, caches, services, messageCollectorAdapter)
postCompilationHook(exitCode) postCompilationHook(exitCode)
reporter.reportCompileIteration(compilationMode is CompilationMode.Incremental, sourcesToCompile, exitCode)
if (exitCode != ExitCode.OK) break if (exitCode != ExitCode.OK) break
dirtySourcesSinceLastTimeFile.delete() dirtySourcesSinceLastTimeFile.delete()
@@ -153,13 +153,10 @@ class IncrementalJsCompilerRunner(
): ExitCode { ): ExitCode {
val freeArgsBackup = args.freeArgs val freeArgsBackup = args.freeArgs
try { return try {
args.freeArgs += sourcesToCompile.map() { it.absolutePath } args.freeArgs += sourcesToCompile.map { it.absolutePath }
val exitCode = K2JSCompiler().exec(messageCollector, services, args) K2JSCompiler().exec(messageCollector, services, args)
reporter.reportCompileIteration(sourcesToCompile, exitCode) } finally {
return exitCode
}
finally {
args.freeArgs = freeArgsBackup args.freeArgs = freeArgsBackup
} }
} }
@@ -82,6 +82,9 @@ fun makeIncrementally(
object EmptyICReporter : ICReporter { object EmptyICReporter : ICReporter {
override fun report(message: () -> String) { override fun report(message: () -> String) {
} }
override fun reportVerbose(message: () -> String) {
}
} }
inline fun <R> withIC(enabled: Boolean = true, fn: ()->R): R { inline fun <R> withIC(enabled: Boolean = true, fn: ()->R): R {
@@ -146,7 +149,7 @@ class IncrementalJvmCompilerRunner(
initDirtyFiles(dirtyFiles, changedFiles) initDirtyFiles(dirtyFiles, changedFiles)
val lastBuildInfo = BuildInfo.read(lastBuildInfoFile) ?: return CompilationMode.Rebuild { "No information on previous build" } 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) val classpathChanges = getClasspathChanges(args.classpathAsList, changedFiles, lastBuildInfo, modulesApiHistory, reporter)
@@ -351,14 +354,9 @@ class IncrementalJvmCompilerRunner(
args.destination = null args.destination = null
args.buildFile = moduleFile.absolutePath args.buildFile = moduleFile.absolutePath
try { return try {
reporter.report { "compiling with args: ${ArgumentUtils.convertArgumentsToStringList(args)}" } compiler.exec(messageCollector, services, args)
reporter.report { "compiling with classpath: ${classpath.toList().sorted().joinToString()}" } } finally {
val exitCode = compiler.exec(messageCollector, services, args)
reporter.reportCompileIteration(sourcesToCompile, exitCode)
return exitCode
}
finally {
args.destination = destination args.destination = destination
moduleFile.delete() moduleFile.delete()
} }
@@ -39,7 +39,7 @@ class InputsCache(
fun removeOutputForSourceFiles(sources: Iterable<File>) { fun removeOutputForSourceFiles(sources: Iterable<File>) {
for (sourceFile in sources) { for (sourceFile in sources) {
sourceToOutputMap.remove(sourceFile).forEach { it -> 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() it.delete()
} }
} }
@@ -32,7 +32,10 @@ class TestICReporter : ICReporter {
override fun report(message: () -> String) { override fun report(message: () -> String) {
} }
override fun reportCompileIteration(sourceFiles: Collection<File>, exitCode: ExitCode) { override fun reportVerbose(message: () -> String) {
}
override fun reportCompileIteration(incremental: Boolean, sourceFiles: Collection<File>, exitCode: ExitCode) {
compiledSourcesMutable.addAll(sourceFiles) compiledSourcesMutable.addAll(sourceFiles)
this.exitCode = exitCode this.exitCode = exitCode
} }
@@ -661,6 +661,10 @@ private class JpsICReporter : ICReporter {
KotlinBuilder.LOG.debug(message()) KotlinBuilder.LOG.debug(message())
} }
} }
override fun reportVerbose(message: () -> String) {
report(message)
}
} }
private fun ChangesCollector.processChangesUsingLookups( private fun ChangesCollector.processChangesUsingLookups(
@@ -672,12 +676,12 @@ private fun ChangesCollector.processChangesUsingLookups(
val allCaches = caches.flatMap { it.thisWithDependentCaches } val allCaches = caches.flatMap { it.thisWithDependentCaches }
val reporter = JpsICReporter() val reporter = JpsICReporter()
reporter.report { "Start processing changes" } reporter.reportVerbose { "Start processing changes" }
val dirtyFiles = getDirtyFiles(allCaches, dataManager) val dirtyFiles = getDirtyFiles(allCaches, dataManager)
fsOperations.markInChunkOrDependents(dirtyFiles.asIterable(), excludeFiles = compiledFiles) fsOperations.markInChunkOrDependents(dirtyFiles.asIterable(), excludeFiles = compiledFiles)
reporter.report { "End of processing changes" } reporter.reportVerbose { "End of processing changes" }
} }
private fun ChangesCollector.getDirtyFiles( private fun ChangesCollector.getDirtyFiles(