From 26373d4952676f8acf3edea0b67b8f2d55524701 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Mon, 3 Oct 2016 16:03:32 +0300 Subject: [PATCH] Refactoring: pass incremental compilation state explicitly --- .../jetbrains/kotlin/gradle/tasks/Tasks.kt | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt index f2be9b12376..98b8e062227 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt @@ -189,19 +189,12 @@ open class KotlinCompile : AbstractKotlinCompile(), Kotl fun filesToString(files: Iterable) = "[" + files.map(::relativePathOrCanonical).sorted().joinToString(separator = ", \n") + "]" - val targetType = "java-production" - val moduleName = args.moduleName - val targetId = TargetId(moduleName, targetType) val outputDir = destinationDir - val caches = IncrementalCachesManager(targetId, cacheDirectory, outputDir) - val lookupTracker = LookupTrackerImpl(LookupTracker.DO_NOTHING) var currentRemoved = removed.filter { it.isKotlinFile() } val allGeneratedFiles = hashSetOf>() val logAction = { logStr: String -> logger.kotlinInfo(logStr) } - val lastBuildInfo = BuildInfo.read(lastBuildInfoFile) - logger.kotlinDebug { "Last Kotlin Build info for task $path -- $lastBuildInfo" } - fun getClasspathChanges(modifiedClasspath: List): ChangesEither { + fun getClasspathChanges(modifiedClasspath: List, lastBuildInfo: BuildInfo?): ChangesEither { if (modifiedClasspath.isEmpty()) { logger.kotlinDebug { "No classpath changes" } return ChangesEither.Known() @@ -241,7 +234,7 @@ open class KotlinCompile : AbstractKotlinCompile(), Kotl return ChangesEither.Known(symbols, fqNames) } - fun calculateSourcesToCompile(javaFilesProcessor: ChangedJavaFilesProcessor): Pair, Boolean> { + fun calculateSourcesToCompile(javaFilesProcessor: ChangedJavaFilesProcessor, caches: IncrementalCachesManager, lastBuildInfo: BuildInfo?): Pair, Boolean> { fun rebuild(reason: String): Pair, Boolean> { logger.kotlinInfo("Non-incremental compilation will be performed: $reason") caches.clean() @@ -259,7 +252,7 @@ open class KotlinCompile : AbstractKotlinCompile(), Kotl if (modifiedClassFiles.any()) return rebuild("Modified class files: ${filesToString(modifiedClassFiles)}") val modifiedClasspathEntries = modified.filter { it in classpath } - val classpathChanges = getClasspathChanges(modifiedClasspathEntries) + val classpathChanges = getClasspathChanges(modifiedClasspathEntries, lastBuildInfo) if (classpathChanges is ChangesEither.Unknown) { return rebuild("could not get changes from modified classpath entries: ${filesToString(modifiedClasspathEntries)}") } @@ -313,9 +306,6 @@ open class KotlinCompile : AbstractKotlinCompile(), Kotl cleanupOnError() } - caches.close(flush = true) - logger.debug("flushed incremental caches") - when (exitCode) { ExitCode.COMPILATION_ERROR -> throw GradleException("Compilation error. See log for more details") ExitCode.INTERNAL_ERROR -> throw GradleException("Internal compiler error. See log for more details") @@ -337,8 +327,14 @@ open class KotlinCompile : AbstractKotlinCompile(), Kotl logger.warn(USING_EXPERIMENTAL_INCREMENTAL_MESSAGE) anyClassesCompiled = false val javaFilesProcessor = ChangedJavaFilesProcessor() + val targetId = TargetId(name = args.moduleName, type = "java-production") + val lookupTracker = LookupTrackerImpl(LookupTracker.DO_NOTHING) + val lastBuildInfo = BuildInfo.read(lastBuildInfoFile) + logger.kotlinDebug { "Last Kotlin Build info for task $path -- $lastBuildInfo" } + val caches = IncrementalCachesManager(targetId, cacheDirectory, outputDir) + // TODO: decide what to do if no files are considered dirty - rebuild or skip the module - var (sourcesToCompile, isIncrementalDecided) = calculateSourcesToCompile(javaFilesProcessor) + var (sourcesToCompile, isIncrementalDecided) = calculateSourcesToCompile(javaFilesProcessor, caches, lastBuildInfo) if (isIncrementalDecided) { additionalClasspath.add(destinationDir) @@ -440,6 +436,8 @@ open class KotlinCompile : AbstractKotlinCompile(), Kotl } anyClassesCompiled = anyClassesCompiled || allGeneratedFiles.isNotEmpty() + caches.close(flush = true) + logger.kotlinDebug { "flushed incremental caches" } processCompilerExitCode(exitCode) }