jps: Don't create cache for common modules (KOTLIN-CR-2028)
This commit is contained in:
+6
-3
@@ -300,9 +300,12 @@ abstract class AbstractIncrementalJpsTest(
|
|||||||
): String {
|
): String {
|
||||||
return buildString {
|
return buildString {
|
||||||
for (target in project.allModuleTargets.sortedBy { it.presentableName }) {
|
for (target in project.allModuleTargets.sortedBy { it.presentableName }) {
|
||||||
append("<target $target>\n")
|
val kotlinCache = project.dataManager.getKotlinCache(dummyCompileContext.kotlinBuildTargets[target])
|
||||||
append(project.dataManager.getKotlinCache(dummyCompileContext.kotlinBuildTargets[target]!!).dump())
|
if (kotlinCache != null) {
|
||||||
append("</target $target>\n\n\n")
|
append("<target $target>\n")
|
||||||
|
append(kotlinCache.dump())
|
||||||
|
append("</target $target>\n\n\n")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,10 +47,7 @@ import org.jetbrains.kotlin.incremental.*
|
|||||||
import org.jetbrains.kotlin.incremental.components.ExpectActualTracker
|
import org.jetbrains.kotlin.incremental.components.ExpectActualTracker
|
||||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||||
import org.jetbrains.kotlin.jps.incremental.*
|
import org.jetbrains.kotlin.jps.incremental.*
|
||||||
import org.jetbrains.kotlin.jps.platforms.KotlinCommonModuleBuildTarget
|
import org.jetbrains.kotlin.jps.platforms.*
|
||||||
import org.jetbrains.kotlin.jps.platforms.KotlinJsModuleBuildTarget
|
|
||||||
import org.jetbrains.kotlin.jps.platforms.KotlinModuleBuildTarget
|
|
||||||
import org.jetbrains.kotlin.jps.platforms.kotlinBuildTargets
|
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.preloading.ClassCondition
|
import org.jetbrains.kotlin.preloading.ClassCondition
|
||||||
import org.jetbrains.kotlin.utils.KotlinPaths
|
import org.jetbrains.kotlin.utils.KotlinPaths
|
||||||
@@ -427,7 +424,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
|
|||||||
|
|
||||||
val kotlinBuildTargets = context.kotlinBuildTargets
|
val kotlinBuildTargets = context.kotlinBuildTargets
|
||||||
for (target in targets) {
|
for (target in targets) {
|
||||||
dataManager.getKotlinCache(kotlinBuildTargets[target]!!).clean()
|
dataManager.getKotlinCache(kotlinBuildTargets[target])?.clean()
|
||||||
hasKotlin.clean(target)
|
hasKotlin.clean(target)
|
||||||
rebuildAfterCacheVersionChanged[target] = true
|
rebuildAfterCacheVersionChanged[target] = true
|
||||||
}
|
}
|
||||||
@@ -441,7 +438,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
|
|||||||
|
|
||||||
val kotlinBuildTargets = context.kotlinBuildTargets
|
val kotlinBuildTargets = context.kotlinBuildTargets
|
||||||
for (target in context.allTargets()) {
|
for (target in context.allTargets()) {
|
||||||
dataManager.getKotlinCache(kotlinBuildTargets[target]!!).clean()
|
dataManager.getKotlinCache(kotlinBuildTargets[target])?.clean()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CacheVersion.Action.CLEAN_DATA_CONTAINER -> {
|
CacheVersion.Action.CLEAN_DATA_CONTAINER -> {
|
||||||
@@ -473,7 +470,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
|
|||||||
|
|
||||||
val kotlinBuildTargets = context.kotlinBuildTargets
|
val kotlinBuildTargets = context.kotlinBuildTargets
|
||||||
for (target in context.allTargets()) {
|
for (target in context.allTargets()) {
|
||||||
dataManager.getKotlinCache(kotlinBuildTargets[target]!!).clean()
|
dataManager.getKotlinCache(kotlinBuildTargets[target])?.clean()
|
||||||
rebuildAfterCacheVersionChanged[target] = true
|
rebuildAfterCacheVersionChanged[target] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -703,23 +700,17 @@ private fun getIncrementalCaches(
|
|||||||
chunk: ModuleChunk,
|
chunk: ModuleChunk,
|
||||||
context: CompileContext
|
context: CompileContext
|
||||||
): Map<ModuleBuildTarget, JpsIncrementalCache> {
|
): Map<ModuleBuildTarget, JpsIncrementalCache> {
|
||||||
val dependentTargets = getDependentTargets(chunk, context)
|
|
||||||
|
|
||||||
val dataManager = context.projectDescriptor.dataManager
|
val dataManager = context.projectDescriptor.dataManager
|
||||||
val kotlinBuildTargets = context.kotlinBuildTargets
|
val kotlinBuildTargets = context.kotlinBuildTargets
|
||||||
|
|
||||||
val chunkCaches = chunk.targets.keysToMapExceptNulls {
|
val chunkCaches = chunk.targets.keysToMapExceptNulls {
|
||||||
val kotlinModuleBuilderTarget = kotlinBuildTargets[it]
|
dataManager.getKotlinCache(kotlinBuildTargets[it])
|
||||||
if (kotlinModuleBuilderTarget !is KotlinCommonModuleBuildTarget) {
|
|
||||||
dataManager.getKotlinCache(kotlinBuildTargets[it]!!)
|
|
||||||
} else null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val dependentTargets = getDependentTargets(chunkCaches.keys, context)
|
||||||
|
|
||||||
val dependentCaches = dependentTargets.mapNotNull {
|
val dependentCaches = dependentTargets.mapNotNull {
|
||||||
val kotlinModuleBuilderTarget = kotlinBuildTargets[it]
|
dataManager.getKotlinCache(kotlinBuildTargets[it])
|
||||||
if (kotlinModuleBuilderTarget !is KotlinCommonModuleBuildTarget) {
|
|
||||||
dataManager.getKotlinCache(kotlinModuleBuilderTarget!!)
|
|
||||||
} else null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (chunkCache in chunkCaches.values) {
|
for (chunkCache in chunkCaches.values) {
|
||||||
@@ -732,17 +723,20 @@ private fun getIncrementalCaches(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getDependentTargets(
|
fun getDependentTargets(
|
||||||
compilingChunk: ModuleChunk,
|
compilingChunkTargets: Set<ModuleBuildTarget>,
|
||||||
context: CompileContext
|
context: CompileContext
|
||||||
): Set<ModuleBuildTarget> {
|
): Set<ModuleBuildTarget> {
|
||||||
val compilingChunkIsTests = compilingChunk.targets.any { it.isTests }
|
if (compilingChunkTargets.isEmpty()) return setOf()
|
||||||
|
|
||||||
|
val compilingChunkModules: Set<JpsModule> = compilingChunkTargets.mapTo(mutableSetOf()) { it.module }
|
||||||
|
val compilingChunkIsTests = compilingChunkTargets.any { it.isTests }
|
||||||
val classpathKind = JpsJavaClasspathKind.compile(compilingChunkIsTests)
|
val classpathKind = JpsJavaClasspathKind.compile(compilingChunkIsTests)
|
||||||
|
|
||||||
fun dependsOnCompilingChunk(target: BuildTarget<*>): Boolean {
|
fun dependsOnCompilingChunk(target: BuildTarget<*>): Boolean {
|
||||||
if (target !is ModuleBuildTarget || compilingChunkIsTests && !target.isTests) return false
|
if (target !is ModuleBuildTarget || compilingChunkIsTests && !target.isTests) return false
|
||||||
|
|
||||||
val dependencies = getDependenciesRecursively(target.module, classpathKind)
|
val dependencies = getDependenciesRecursively(target.module, classpathKind)
|
||||||
return ContainerUtil.intersects(dependencies, compilingChunk.modules)
|
return ContainerUtil.intersects(dependencies, compilingChunkModules)
|
||||||
}
|
}
|
||||||
|
|
||||||
val dependentTargets = HashSet<ModuleBuildTarget>()
|
val dependentTargets = HashSet<ModuleBuildTarget>()
|
||||||
@@ -750,7 +744,7 @@ fun getDependentTargets(
|
|||||||
|
|
||||||
// skip chunks that are compiled before compilingChunk
|
// skip chunks that are compiled before compilingChunk
|
||||||
while (sortedChunks.hasNext()) {
|
while (sortedChunks.hasNext()) {
|
||||||
if (sortedChunks.next().targets == compilingChunk.targets) break
|
if (sortedChunks.next().targets == compilingChunkTargets) break
|
||||||
}
|
}
|
||||||
|
|
||||||
// process chunks that compiled after compilingChunk
|
// process chunks that compiled after compilingChunk
|
||||||
|
|||||||
@@ -60,6 +60,10 @@ private class KotlinIncrementalStorageProvider(
|
|||||||
private val target: KotlinModuleBuildTarget,
|
private val target: KotlinModuleBuildTarget,
|
||||||
private val paths: BuildDataPaths
|
private val paths: BuildDataPaths
|
||||||
) : StorageProvider<JpsIncrementalCache>() {
|
) : StorageProvider<JpsIncrementalCache>() {
|
||||||
|
init {
|
||||||
|
check(target.hasCaches)
|
||||||
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?) = other is KotlinIncrementalStorageProvider && target == other.target
|
override fun equals(other: Any?) = other is KotlinIncrementalStorageProvider && target == other.target
|
||||||
|
|
||||||
override fun hashCode() = target.hashCode()
|
override fun hashCode() = target.hashCode()
|
||||||
@@ -67,6 +71,7 @@ private class KotlinIncrementalStorageProvider(
|
|||||||
override fun createStorage(targetDataDir: File): JpsIncrementalCache = target.createCacheStorage(paths)
|
override fun createStorage(targetDataDir: File): JpsIncrementalCache = target.createCacheStorage(paths)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun BuildDataManager.getKotlinCache(target: KotlinModuleBuildTarget): JpsIncrementalCache =
|
fun BuildDataManager.getKotlinCache(target: KotlinModuleBuildTarget?): JpsIncrementalCache? =
|
||||||
getStorage(target.jpsModuleBuildTarget, KotlinIncrementalStorageProvider(target, dataPaths))
|
if (target == null || !target.hasCaches) null
|
||||||
|
else getStorage(target.jpsModuleBuildTarget, KotlinIncrementalStorageProvider(target, dataPaths))
|
||||||
|
|
||||||
|
|||||||
@@ -85,5 +85,9 @@ class KotlinCommonModuleBuildTarget(context: CompileContext, jpsModuleBuildTarge
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createCacheStorage(paths: BuildDataPaths) = JpsIncrementalJvmCache(jpsModuleBuildTarget, paths) // todo: delete
|
override val hasCaches: Boolean
|
||||||
|
get() = false
|
||||||
|
|
||||||
|
override fun createCacheStorage(paths: BuildDataPaths) =
|
||||||
|
error("incremental K2MetadataCompiler not supported yet, createCacheStorage() should not be called")
|
||||||
}
|
}
|
||||||
@@ -174,6 +174,8 @@ abstract class KotlinModuleBuildTarget(val context: CompileContext, val jpsModul
|
|||||||
open fun doAfterBuild() {
|
open fun doAfterBuild() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open val hasCaches: Boolean = true
|
||||||
|
|
||||||
abstract fun createCacheStorage(paths: BuildDataPaths): JpsIncrementalCache
|
abstract fun createCacheStorage(paths: BuildDataPaths): JpsIncrementalCache
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user