From 7ff7c71b964f5a7d43854f9c52142cb714ab67d4 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Fri, 6 Jul 2018 16:30:56 +0300 Subject: [PATCH] Refactoring: extract function for getting classpath changes --- .../IncrementalJvmCompilerRunner.kt | 108 +++++++++--------- 1 file changed, 55 insertions(+), 53 deletions(-) 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 7ed87681eb6..ff05efdebf8 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 @@ -150,7 +150,7 @@ class IncrementalJvmCompilerRunner( val lastBuildInfo = BuildInfo.read(lastBuildInfoFile) ?: return CompilationMode.Rebuild { "No information on previous build" } reporter.report { "Last Kotlin Build info -- $lastBuildInfo" } - val classpathChanges = getClasspathChanges(args.classpathAsList, changedFiles, lastBuildInfo) + val classpathChanges = getClasspathChanges(args.classpathAsList, changedFiles, lastBuildInfo, modulesApiHistory, reporter) @Suppress("UNUSED_VARIABLE") // for sealed when val unused = when (classpathChanges) { @@ -242,58 +242,6 @@ class IncrementalJvmCompilerRunner( return result } - private fun getClasspathChanges( - classpath: List, - changedFiles: ChangedFiles.Known, - lastBuildInfo: BuildInfo - ): ChangesEither { - val classpathSet = HashSet() - for (file in classpath) { - when { - file.isFile -> classpathSet.add(file) - file.isDirectory -> file.walk().filterTo(classpathSet) { it.isFile } - } - } - - val modifiedClasspath = changedFiles.modified.filterTo(HashSet()) { it in classpathSet } - val removedClasspath = changedFiles.removed.filterTo(HashSet()) { it in classpathSet } - - // todo: removed classes could be processed normally - if (removedClasspath.isNotEmpty()) return ChangesEither.Unknown("Some files are removed from classpath $removedClasspath") - - if (modifiedClasspath.isEmpty()) return ChangesEither.Known() - - val lastBuildTS = lastBuildInfo.startTS - - val symbols = HashSet() - val fqNames = HashSet() - - val historyFilesEither = modulesApiHistory.historyFilesForChangedFiles(modifiedClasspath) - val historyFiles = when (historyFilesEither) { - is Either.Success> -> historyFilesEither.value - is Either.Error -> return ChangesEither.Unknown(historyFilesEither.reason) - } - - for (historyFile in historyFiles) { - val allBuilds = BuildDiffsStorage.readDiffsFromFile(historyFile, reporter = reporter) - ?: return ChangesEither.Unknown("Could not read diffs from $historyFile") - val (knownBuilds, newBuilds) = allBuilds.partition { it.ts <= lastBuildTS } - if (knownBuilds.isEmpty()) { - return ChangesEither.Unknown("No previously known builds for $historyFile") - } - - for (buildDiff in newBuilds) { - if (!buildDiff.isIncremental) return ChangesEither.Unknown("Non-incremental build from dependency $historyFile") - - val dirtyData = buildDiff.dirtyData - symbols.addAll(dirtyData.dirtyLookupSymbols) - fqNames.addAll(dirtyData.dirtyClassesFqNames) - } - } - - return ChangesEither.Known(symbols, fqNames) - } - override fun preBuildHook(args: K2JVMCompilerArguments, compilationMode: CompilationMode) { if (compilationMode is CompilationMode.Incremental) { val destinationDir = args.destinationAsFile @@ -439,3 +387,57 @@ var K2JVMCompilerArguments.destinationAsFile: File var K2JVMCompilerArguments.classpathAsList: List get() = classpath.orEmpty().split(File.pathSeparator).map(::File) set(value) { classpath = value.joinToString(separator = File.pathSeparator, transform = { it.path }) } + +private fun getClasspathChanges( + classpath: List, + changedFiles: ChangedFiles.Known, + lastBuildInfo: BuildInfo, + modulesApiHistory: ModulesApiHistory, + reporter: ICReporter? +): ChangesEither { + val classpathSet = HashSet() + for (file in classpath) { + when { + file.isFile -> classpathSet.add(file) + file.isDirectory -> file.walk().filterTo(classpathSet) { it.isFile } + } + } + + val modifiedClasspath = changedFiles.modified.filterTo(HashSet()) { it in classpathSet } + val removedClasspath = changedFiles.removed.filterTo(HashSet()) { it in classpathSet } + + // todo: removed classes could be processed normally + if (removedClasspath.isNotEmpty()) return ChangesEither.Unknown("Some files are removed from classpath $removedClasspath") + + if (modifiedClasspath.isEmpty()) return ChangesEither.Known() + + val lastBuildTS = lastBuildInfo.startTS + + val symbols = HashSet() + val fqNames = HashSet() + + val historyFilesEither = modulesApiHistory.historyFilesForChangedFiles(modifiedClasspath) + val historyFiles = when (historyFilesEither) { + is Either.Success> -> historyFilesEither.value + is Either.Error -> return ChangesEither.Unknown(historyFilesEither.reason) + } + + for (historyFile in historyFiles) { + val allBuilds = BuildDiffsStorage.readDiffsFromFile(historyFile, reporter = reporter) + ?: return ChangesEither.Unknown("Could not read diffs from $historyFile") + val (knownBuilds, newBuilds) = allBuilds.partition { it.ts <= lastBuildTS } + if (knownBuilds.isEmpty()) { + return ChangesEither.Unknown("No previously known builds for $historyFile") + } + + for (buildDiff in newBuilds) { + if (!buildDiff.isIncremental) return ChangesEither.Unknown("Non-incremental build from dependency $historyFile") + + val dirtyData = buildDiff.dirtyData + symbols.addAll(dirtyData.dirtyLookupSymbols) + fqNames.addAll(dirtyData.dirtyClassesFqNames) + } + } + + return ChangesEither.Known(symbols, fqNames) +} \ No newline at end of file