Track changes for jar files for non-Android Gradle projects
This commit is contained in:
+2
-1
@@ -22,7 +22,8 @@ data class IncrementalModuleEntry(
|
||||
class IncrementalModuleInfo(
|
||||
val projectRoot: File,
|
||||
val dirToModule: Map<File, IncrementalModuleEntry>,
|
||||
val nameToModules: Map<String, Set<IncrementalModuleEntry>>
|
||||
val nameToModules: Map<String, Set<IncrementalModuleEntry>>,
|
||||
val jarToClassListFile: Map<File, File>
|
||||
) : Serializable {
|
||||
companion object {
|
||||
private const val serialVersionUID = 0L
|
||||
|
||||
@@ -48,8 +48,7 @@ import org.jetbrains.kotlin.daemon.report.RemoteICReporter
|
||||
import org.jetbrains.kotlin.incremental.*
|
||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.incremental.parsing.classesFqNames
|
||||
import org.jetbrains.kotlin.incremental.multiproject.EmptyModulesApiHistory
|
||||
import org.jetbrains.kotlin.incremental.multiproject.ModulesApiHistoryImpl
|
||||
import org.jetbrains.kotlin.incremental.multiproject.ModulesApiHistoryJvm
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents
|
||||
import org.jetbrains.kotlin.modules.Module
|
||||
import org.jetbrains.kotlin.progress.CompilationCanceledStatus
|
||||
@@ -524,9 +523,7 @@ class CompileServiceImpl(
|
||||
workingDir,
|
||||
enabled = true)
|
||||
|
||||
val modulesApiHistory = incrementalCompilationOptions.run {
|
||||
ModulesApiHistoryImpl(modulesInfo)
|
||||
}
|
||||
val modulesApiHistory = ModulesApiHistoryJvm(incrementalCompilationOptions.modulesInfo)
|
||||
|
||||
val compiler = IncrementalJvmCompilerRunner(
|
||||
workingDir,
|
||||
|
||||
+26
-11
@@ -21,10 +21,8 @@ object EmptyModulesApiHistory : ModulesApiHistory {
|
||||
Either.Error("Multi-module IC is not configured")
|
||||
}
|
||||
|
||||
class ModulesApiHistoryImpl(
|
||||
private val modulesInfo: IncrementalModuleInfo
|
||||
) : ModulesApiHistory {
|
||||
private val projectRootPath = Paths.get(modulesInfo.projectRoot.absolutePath)
|
||||
open class ModulesApiHistoryJvm(protected val modulesInfo: IncrementalModuleInfo) : ModulesApiHistory {
|
||||
protected val projectRootPath: Path = Paths.get(modulesInfo.projectRoot.absolutePath)
|
||||
private val dirToHistoryFileCache = HashMap<File, File?>()
|
||||
|
||||
override fun historyFilesForChangedFiles(changedFiles: Set<File>): Either<Set<File>> {
|
||||
@@ -46,9 +44,9 @@ class ModulesApiHistoryImpl(
|
||||
}
|
||||
|
||||
for (jar in jarFiles) {
|
||||
val historyEither = getBuildHistoryForJar(jar)
|
||||
val historyEither = getBuildHistoryFilesForJar(jar)
|
||||
when (historyEither) {
|
||||
is Either.Success<File> -> result.add(historyEither.value)
|
||||
is Either.Success<Set<File>> -> result.addAll(historyEither.value)
|
||||
is Either.Error -> return historyEither
|
||||
}
|
||||
}
|
||||
@@ -78,9 +76,26 @@ class ModulesApiHistoryImpl(
|
||||
}
|
||||
}
|
||||
|
||||
private fun getBuildHistoryForJar(jar: File): Either<File> =
|
||||
Either.Error("Cannot get changes for jar $jar")
|
||||
protected open fun getBuildHistoryFilesForJar(jar: File): Either<Set<File>> {
|
||||
val classListFile = modulesInfo.jarToClassListFile[jar] ?: return Either.Error("Unknown jar: $jar")
|
||||
if (!classListFile.isFile) return Either.Error("Class list file does not exist $classListFile")
|
||||
|
||||
private fun Path.isParentOf(path: Path) = path.startsWith(this)
|
||||
private fun Path.isParentOf(file: File) = this.isParentOf(Paths.get(file.absolutePath))
|
||||
}
|
||||
val classFiles = try {
|
||||
classListFile.readText().split(File.pathSeparator).map(::File)
|
||||
} catch (t: Throwable) {
|
||||
return Either.Error("Could not read class list for $jar from $classListFile: $t")
|
||||
}
|
||||
|
||||
val classFileDirs = classFiles.groupBy { it.parentFile }
|
||||
val result = HashSet<File>()
|
||||
for ((dir, files) in classFileDirs) {
|
||||
val buildHistory = getBuildHistoryForDir(dir)
|
||||
?: return Either.Error("Could not get build history for class files: ${files.joinToString()}")
|
||||
result.add(buildHistory)
|
||||
}
|
||||
return Either.Success(result)
|
||||
}
|
||||
}
|
||||
|
||||
private fun Path.isParentOf(path: Path) = path.startsWith(this)
|
||||
private fun Path.isParentOf(file: File) = this.isParentOf(Paths.get(file.absolutePath))
|
||||
Reference in New Issue
Block a user