Avoid computing source files changes in IC for Gradle

This commit is contained in:
Alexey Tsvetkov
2017-12-01 22:08:52 +03:00
parent 5a8c0f8f42
commit dfe176efca
4 changed files with 16 additions and 17 deletions
@@ -453,8 +453,8 @@ class CompileServiceImpl(
workingDir, workingDir,
enabled = true) enabled = true)
return IncrementalJsCompilerRunner(workingDir, versions, reporter) val compiler = IncrementalJsCompilerRunner(workingDir, versions, reporter)
.compile(allKotlinFiles, args, compilerMessageCollector, { changedFiles }) return compiler.compile(allKotlinFiles, args, compilerMessageCollector, changedFiles)
} }
private fun execIncrementalCompiler( private fun execIncrementalCompiler(
@@ -514,7 +514,7 @@ class CompileServiceImpl(
friendBuildHistoryFile = incrementalCompilationOptions.friendDifferenceFile, friendBuildHistoryFile = incrementalCompilationOptions.friendDifferenceFile,
usePreciseJavaTracking = incrementalCompilationOptions.usePreciseJavaTracking usePreciseJavaTracking = incrementalCompilationOptions.usePreciseJavaTracking
) )
return compiler.compile(allKotlinFiles, k2jvmArgs, compilerMessageCollector, { changedFiles }) return compiler.compile(allKotlinFiles, k2jvmArgs, compilerMessageCollector, changedFiles)
} }
override fun leaseReplSession( override fun leaseReplSession(
@@ -54,10 +54,12 @@ abstract class IncrementalCompilerRunner<
protected abstract fun destinationDir(args: Args): File protected abstract fun destinationDir(args: Args): File
fun compile( fun compile(
allKotlinSources: List<File>, allSourceFiles: List<File>,
args: Args, args: Args,
messageCollector: MessageCollector, messageCollector: MessageCollector,
getChangedFiles: (CacheManager)-> ChangedFiles // when [providedChangedFiles] is not null, changes are provided by external system (e.g. Gradle)
// otherwise we track source files changes ourselves.
providedChangedFiles: ChangedFiles?
): ExitCode { ): ExitCode {
assert(isICEnabled()) { "Incremental compilation is not enabled" } assert(isICEnabled()) { "Incremental compilation is not enabled" }
var caches = createCacheManager(args) var caches = createCacheManager(args)
@@ -70,18 +72,20 @@ abstract class IncrementalCompilerRunner<
destinationDir(args).deleteRecursively() destinationDir(args).deleteRecursively()
caches = createCacheManager(args) caches = createCacheManager(args)
// todo more optimal fix if (providedChangedFiles == null) {
caches.inputsCache.sourceSnapshotMap.compareAndUpdate(allKotlinSources) caches.inputsCache.sourceSnapshotMap.compareAndUpdate(allSourceFiles)
return compileIncrementally(args, caches, allKotlinSources, CompilationMode.Rebuild(), messageCollector) }
val allKotlinFiles = allSourceFiles.filter { it.isKotlinFile() }
return compileIncrementally(args, caches, allKotlinFiles, CompilationMode.Rebuild(), messageCollector)
} }
return try { return try {
val changedFiles = getChangedFiles(caches) val changedFiles = providedChangedFiles ?: caches.inputsCache.sourceSnapshotMap.compareAndUpdate(allSourceFiles)
val compilationMode = sourcesToCompile(caches, changedFiles, args) val compilationMode = sourcesToCompile(caches, changedFiles, args)
val exitCode = when (compilationMode) { val exitCode = when (compilationMode) {
is CompilationMode.Incremental -> { is CompilationMode.Incremental -> {
compileIncrementally(args, caches, allKotlinSources, compilationMode, messageCollector) compileIncrementally(args, caches, allSourceFiles, compilationMode, messageCollector)
} }
is CompilationMode.Rebuild -> { is CompilationMode.Rebuild -> {
rebuild { "Non-incremental compilation will be performed: ${compilationMode.reason}" } rebuild { "Non-incremental compilation will be performed: ${compilationMode.reason}" }
@@ -41,9 +41,7 @@ fun makeJsIncrementally(
withJsIC { withJsIC {
val compiler = IncrementalJsCompilerRunner(cachesDir, versions, reporter) val compiler = IncrementalJsCompilerRunner(cachesDir, versions, reporter)
compiler.compile(allKotlinFiles, args, messageCollector) { compiler.compile(allKotlinFiles, args, messageCollector, providedChangedFiles = null)
it.inputsCache.sourceSnapshotMap.compareAndUpdate(allKotlinFiles)
}
} }
} }
@@ -63,7 +63,6 @@ fun makeIncrementally(
val rootsWalk = sourceRoots.asSequence().flatMap { it.walk() } val rootsWalk = sourceRoots.asSequence().flatMap { it.walk() }
val files = rootsWalk.filter(File::isFile) val files = rootsWalk.filter(File::isFile)
val sourceFiles = files.filter { it.extension.toLowerCase() in allExtensions }.toList() val sourceFiles = files.filter { it.extension.toLowerCase() in allExtensions }.toList()
val kotlinFiles = sourceFiles.filter { it.extension.toLowerCase() in kotlinExtensions }
withIC { withIC {
val compiler = IncrementalJvmCompilerRunner( val compiler = IncrementalJvmCompilerRunner(
@@ -73,9 +72,7 @@ fun makeIncrementally(
// Use precise setting in case of non-Gradle build // Use precise setting in case of non-Gradle build
usePreciseJavaTracking = true usePreciseJavaTracking = true
) )
compiler.compile(kotlinFiles, args, messageCollector) { compiler.compile(sourceFiles, args, messageCollector, providedChangedFiles = null)
it.inputsCache.sourceSnapshotMap.compareAndUpdate(sourceFiles)
}
} }
} }