[K/N] Pass transitive dependencies for forked caching compilation
This commit is contained in:
+20
-3
@@ -11,9 +11,26 @@ import org.jetbrains.kotlin.konan.file.File
|
|||||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
||||||
import org.jetbrains.kotlin.library.KotlinLibrary
|
import org.jetbrains.kotlin.library.KotlinLibrary
|
||||||
import org.jetbrains.kotlin.library.metadata.resolver.TopologicalLibraryOrder
|
import org.jetbrains.kotlin.library.metadata.resolver.TopologicalLibraryOrder
|
||||||
import org.jetbrains.kotlin.library.unresolvedDependencies
|
|
||||||
import org.jetbrains.kotlin.library.uniqueName
|
import org.jetbrains.kotlin.library.uniqueName
|
||||||
import org.jetbrains.kotlin.backend.konan.descriptors.isInteropLibrary
|
import org.jetbrains.kotlin.backend.konan.descriptors.isInteropLibrary
|
||||||
|
import org.jetbrains.kotlin.library.unresolvedDependencies
|
||||||
|
|
||||||
|
internal fun KotlinLibrary.getAllTransitiveDependencies(allLibraries: Map<String, KotlinLibrary>): List<KotlinLibrary> {
|
||||||
|
val allDependencies = mutableSetOf<KotlinLibrary>()
|
||||||
|
|
||||||
|
fun traverseDependencies(library: KotlinLibrary) {
|
||||||
|
library.unresolvedDependencies.forEach {
|
||||||
|
val dependency = allLibraries[it.path]!!
|
||||||
|
if (dependency !in allDependencies) {
|
||||||
|
allDependencies += dependency
|
||||||
|
traverseDependencies(dependency)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
traverseDependencies(this)
|
||||||
|
return allDependencies.toList()
|
||||||
|
}
|
||||||
|
|
||||||
class CacheBuilder(
|
class CacheBuilder(
|
||||||
val konanConfig: KonanConfig,
|
val konanConfig: KonanConfig,
|
||||||
@@ -39,7 +56,7 @@ class CacheBuilder(
|
|||||||
if (!isLibraryAutoCacheable)
|
if (!isLibraryAutoCacheable)
|
||||||
return@librariesLoop
|
return@librariesLoop
|
||||||
|
|
||||||
val dependencies = library.unresolvedDependencies.map { uniqueNameToLibrary[it.path]!! }
|
val dependencies = library.getAllTransitiveDependencies(uniqueNameToLibrary)
|
||||||
val dependencyCaches = dependencies.map {
|
val dependencyCaches = dependencies.map {
|
||||||
caches[it] ?: run {
|
caches[it] ?: run {
|
||||||
configuration.report(CompilerMessageSeverity.LOGGING,
|
configuration.report(CompilerMessageSeverity.LOGGING,
|
||||||
@@ -54,7 +71,7 @@ class CacheBuilder(
|
|||||||
val libraryCacheDirectory = if (library.isDefault)
|
val libraryCacheDirectory = if (library.isDefault)
|
||||||
konanConfig.systemCacheDirectory
|
konanConfig.systemCacheDirectory
|
||||||
else
|
else
|
||||||
CachedLibraries.computeVersionedCacheDirectory(konanConfig.autoCacheDirectory, library, allLibraries)
|
CachedLibraries.computeVersionedCacheDirectory(konanConfig.autoCacheDirectory, library, uniqueNameToLibrary)
|
||||||
val libraryCache = libraryCacheDirectory.child(
|
val libraryCache = libraryCacheDirectory.child(
|
||||||
if (makePerFileCache)
|
if (makePerFileCache)
|
||||||
CachedLibraries.getPerFileCachedLibraryName(library)
|
CachedLibraries.getPerFileCachedLibraryName(library)
|
||||||
|
|||||||
+5
-22
@@ -13,7 +13,6 @@ import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
|||||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||||
import org.jetbrains.kotlin.library.KotlinLibrary
|
import org.jetbrains.kotlin.library.KotlinLibrary
|
||||||
import org.jetbrains.kotlin.library.uniqueName
|
import org.jetbrains.kotlin.library.uniqueName
|
||||||
import org.jetbrains.kotlin.library.unresolvedDependencies
|
|
||||||
import java.security.MessageDigest
|
import java.security.MessageDigest
|
||||||
|
|
||||||
private fun MessageDigest.digestFile(file: File) =
|
private fun MessageDigest.digestFile(file: File) =
|
||||||
@@ -166,6 +165,8 @@ class CachedLibraries(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val uniqueNameToLibrary = allLibraries.associateBy { it.uniqueName }
|
||||||
|
|
||||||
private val allCaches: Map<KotlinLibrary, Cache> = allLibraries.mapNotNull { library ->
|
private val allCaches: Map<KotlinLibrary, Cache> = allLibraries.mapNotNull { library ->
|
||||||
val explicitPath = explicitCaches[library]
|
val explicitPath = explicitCaches[library]
|
||||||
|
|
||||||
@@ -175,7 +176,7 @@ class CachedLibraries(
|
|||||||
} else {
|
} else {
|
||||||
val libraryPath = library.libraryFile.absolutePath
|
val libraryPath = library.libraryFile.absolutePath
|
||||||
if (autoCacheableFrom.any { libraryPath.startsWith(it.absolutePath) }) {
|
if (autoCacheableFrom.any { libraryPath.startsWith(it.absolutePath) }) {
|
||||||
val dir = computeVersionedCacheDirectory(autoCacheDirectory, library, allLibraries)
|
val dir = computeVersionedCacheDirectory(autoCacheDirectory, library, uniqueNameToLibrary)
|
||||||
selectCache(library, dir.child(getPerFileCachedLibraryName(library)))
|
selectCache(library, dir.child(getPerFileCachedLibraryName(library)))
|
||||||
?: selectCache(library, dir.child(getCachedLibraryName(library)))
|
?: selectCache(library, dir.child(getCachedLibraryName(library)))
|
||||||
} else {
|
} else {
|
||||||
@@ -214,27 +215,9 @@ class CachedLibraries(
|
|||||||
fun getCachedLibraryName(library: KotlinLibrary): String = getCachedLibraryName(library.uniqueName)
|
fun getCachedLibraryName(library: KotlinLibrary): String = getCachedLibraryName(library.uniqueName)
|
||||||
fun getCachedLibraryName(libraryName: String): String = "$libraryName-cache"
|
fun getCachedLibraryName(libraryName: String): String = "$libraryName-cache"
|
||||||
|
|
||||||
private fun getAllDependencies(library: KotlinLibrary, allLibraries: List<KotlinLibrary>): List<KotlinLibrary> {
|
|
||||||
val uniqueNameToLibrary = allLibraries.associateBy { it.uniqueName }
|
|
||||||
val allDependencies = mutableSetOf<KotlinLibrary>()
|
|
||||||
|
|
||||||
fun traverseDependencies(library: KotlinLibrary) {
|
|
||||||
library.unresolvedDependencies.forEach {
|
|
||||||
val dependency = uniqueNameToLibrary[it.path]!!
|
|
||||||
if (dependency !in allDependencies) {
|
|
||||||
allDependencies += dependency
|
|
||||||
traverseDependencies(dependency)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
traverseDependencies(library)
|
|
||||||
return allDependencies.toList()
|
|
||||||
}
|
|
||||||
|
|
||||||
@OptIn(ExperimentalUnsignedTypes::class)
|
@OptIn(ExperimentalUnsignedTypes::class)
|
||||||
fun computeVersionedCacheDirectory(baseCacheDirectory: File, library: KotlinLibrary, allLibraries: List<KotlinLibrary>): File {
|
fun computeVersionedCacheDirectory(baseCacheDirectory: File, library: KotlinLibrary, allLibraries: Map<String, KotlinLibrary>): File {
|
||||||
val dependencies = getAllDependencies(library, allLibraries)
|
val dependencies = library.getAllTransitiveDependencies(allLibraries)
|
||||||
val messageDigest = MessageDigest.getInstance("SHA-256")
|
val messageDigest = MessageDigest.getInstance("SHA-256")
|
||||||
messageDigest.update(compilerMarker)
|
messageDigest.update(compilerMarker)
|
||||||
messageDigest.digestLibrary(library)
|
messageDigest.digestLibrary(library)
|
||||||
|
|||||||
Reference in New Issue
Block a user