[K/N] Optimized libraries hash computation
#KT-63081 Fixed
This commit is contained in:
+3
-1
@@ -50,6 +50,7 @@ class CacheBuilder(
|
|||||||
|
|
||||||
private val allLibraries by lazy { konanConfig.resolvedLibraries.getFullList(TopologicalLibraryOrder) }
|
private val allLibraries by lazy { konanConfig.resolvedLibraries.getFullList(TopologicalLibraryOrder) }
|
||||||
private val uniqueNameToLibrary by lazy { allLibraries.associateBy { it.uniqueName } }
|
private val uniqueNameToLibrary by lazy { allLibraries.associateBy { it.uniqueName } }
|
||||||
|
private val uniqueNameToHash = mutableMapOf<String, ByteArray>()
|
||||||
|
|
||||||
private val caches = mutableMapOf<KotlinLibrary, CachedLibraries.Cache>()
|
private val caches = mutableMapOf<KotlinLibrary, CachedLibraries.Cache>()
|
||||||
private val cacheRootDirectories = mutableMapOf<KotlinLibrary, String>()
|
private val cacheRootDirectories = mutableMapOf<KotlinLibrary, String>()
|
||||||
@@ -237,7 +238,8 @@ class CacheBuilder(
|
|||||||
|
|
||||||
val libraryCacheDirectory = when {
|
val libraryCacheDirectory = when {
|
||||||
library.isDefault -> konanConfig.systemCacheDirectory
|
library.isDefault -> konanConfig.systemCacheDirectory
|
||||||
isExternal -> CachedLibraries.computeVersionedCacheDirectory(konanConfig.autoCacheDirectory, library, uniqueNameToLibrary)
|
isExternal -> CachedLibraries.computeVersionedCacheDirectory(
|
||||||
|
konanConfig.autoCacheDirectory, library, uniqueNameToLibrary, uniqueNameToHash)
|
||||||
else -> konanConfig.incrementalCacheDirectory!!
|
else -> konanConfig.incrementalCacheDirectory!!
|
||||||
}
|
}
|
||||||
val libraryCache = libraryCacheDirectory.child(
|
val libraryCache = libraryCacheDirectory.child(
|
||||||
|
|||||||
+21
-4
@@ -171,6 +171,7 @@ class CachedLibraries(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val uniqueNameToLibrary = allLibraries.associateBy { it.uniqueName }
|
private val uniqueNameToLibrary = allLibraries.associateBy { it.uniqueName }
|
||||||
|
private val uniqueNameToHash = mutableMapOf<String, ByteArray>()
|
||||||
|
|
||||||
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]
|
||||||
@@ -186,7 +187,7 @@ class CachedLibraries(
|
|||||||
}
|
}
|
||||||
?: autoCacheDirectory.takeIf { autoCacheableFrom.any { libraryPath.startsWith(it.absolutePath) } }
|
?: autoCacheDirectory.takeIf { autoCacheableFrom.any { libraryPath.startsWith(it.absolutePath) } }
|
||||||
?.let {
|
?.let {
|
||||||
val dir = computeVersionedCacheDirectory(it, library, uniqueNameToLibrary)
|
val dir = computeVersionedCacheDirectory(it, library, uniqueNameToLibrary, uniqueNameToHash)
|
||||||
selectCache(library, dir.child(getPerFileCachedLibraryName(library)))
|
selectCache(library, dir.child(getPerFileCachedLibraryName(library)))
|
||||||
?: selectCache(library, dir.child(getCachedLibraryName(library)))
|
?: selectCache(library, dir.child(getCachedLibraryName(library)))
|
||||||
}
|
}
|
||||||
@@ -220,12 +221,28 @@ 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"
|
||||||
|
|
||||||
fun computeVersionedCacheDirectory(baseCacheDirectory: File, library: KotlinLibrary, allLibraries: Map<String, KotlinLibrary>): File {
|
private fun computeLibraryHash(
|
||||||
|
library: KotlinLibrary,
|
||||||
|
librariesHashes: MutableMap<String, ByteArray>,
|
||||||
|
): ByteArray = librariesHashes.getOrPut(library.uniqueName) {
|
||||||
|
val messageDigest = MessageDigest.getInstance("SHA-256")
|
||||||
|
messageDigest.digestLibrary(library)
|
||||||
|
messageDigest.digest()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun computeVersionedCacheDirectory(
|
||||||
|
baseCacheDirectory: File,
|
||||||
|
library: KotlinLibrary,
|
||||||
|
allLibraries: Map<String, KotlinLibrary>,
|
||||||
|
librariesHashes: MutableMap<String, ByteArray>,
|
||||||
|
): File {
|
||||||
val dependencies = library.getAllTransitiveDependencies(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.update(computeLibraryHash(library, librariesHashes))
|
||||||
dependencies.sortedBy { it.uniqueName }.forEach { messageDigest.digestLibrary(it) }
|
dependencies.sortedBy { it.uniqueName }.forEach {
|
||||||
|
messageDigest.update(computeLibraryHash(it, librariesHashes))
|
||||||
|
}
|
||||||
|
|
||||||
val version = library.versions.libraryVersion ?: "unspecified"
|
val version = library.versions.libraryVersion ?: "unspecified"
|
||||||
val hashString = messageDigest.digest()
|
val hashString = messageDigest.digest()
|
||||||
|
|||||||
Reference in New Issue
Block a user