[JS IR] Manage cache root dir from IC cache updater
- pass cache root directory instead of dir list - manage klib cache dirs from cache updater
This commit is contained in:
committed by
Space Team
parent
c7589245c4
commit
ec6a7094e6
@@ -650,7 +650,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
|||||||
val cacheUpdater = CacheUpdater(
|
val cacheUpdater = CacheUpdater(
|
||||||
mainModule = arguments.includes!!,
|
mainModule = arguments.includes!!,
|
||||||
allModules = libraries,
|
allModules = libraries,
|
||||||
icCachePaths = cacheDirectories,
|
icCacheRootDir = cacheDirectories.last(),
|
||||||
compilerConfiguration = configurationJs,
|
compilerConfiguration = configurationJs,
|
||||||
irFactory = { IrFactoryImplForJsIC(WholeWorldStageController()) },
|
irFactory = { IrFactoryImplForJsIC(WholeWorldStageController()) },
|
||||||
mainArguments = mainCallArguments,
|
mainArguments = mainCallArguments,
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.library.KLIB_PROPERTY_DEPENDS
|
|||||||
import org.jetbrains.kotlin.library.KotlinLibrary
|
import org.jetbrains.kotlin.library.KotlinLibrary
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.security.MessageDigest
|
||||||
import java.util.EnumSet
|
import java.util.EnumSet
|
||||||
|
|
||||||
fun interface JsIrCompilerICInterface {
|
fun interface JsIrCompilerICInterface {
|
||||||
@@ -48,7 +49,7 @@ enum class DirtyFileState(val str: String) {
|
|||||||
class CacheUpdater(
|
class CacheUpdater(
|
||||||
mainModule: String,
|
mainModule: String,
|
||||||
allModules: Collection<String>,
|
allModules: Collection<String>,
|
||||||
icCachePaths: Collection<String>,
|
private val icCacheRootDir: String,
|
||||||
private val compilerConfiguration: CompilerConfiguration,
|
private val compilerConfiguration: CompilerConfiguration,
|
||||||
private val irFactory: () -> IrFactory,
|
private val irFactory: () -> IrFactory,
|
||||||
private val mainArguments: List<String>?,
|
private val mainArguments: List<String>?,
|
||||||
@@ -60,8 +61,6 @@ class CacheUpdater(
|
|||||||
private val dependencyGraph = buildDependenciesGraph(libraries)
|
private val dependencyGraph = buildDependenciesGraph(libraries)
|
||||||
private val configHash = compilerConfiguration.configHashForIC()
|
private val configHash = compilerConfiguration.configHashForIC()
|
||||||
|
|
||||||
private val cacheMap = libraries.values.zip(icCachePaths).toMap()
|
|
||||||
|
|
||||||
private val mainLibraryFile = KotlinLibraryFile(File(mainModule).canonicalPath)
|
private val mainLibraryFile = KotlinLibraryFile(File(mainModule).canonicalPath)
|
||||||
private val mainLibrary = libraries[mainLibraryFile] ?: notFoundIcError("main library", mainLibraryFile)
|
private val mainLibrary = libraries[mainLibraryFile] ?: notFoundIcError("main library", mainLibraryFile)
|
||||||
|
|
||||||
@@ -114,9 +113,13 @@ class CacheUpdater(
|
|||||||
private inner class CacheUpdaterInternal {
|
private inner class CacheUpdaterInternal {
|
||||||
val signatureHashCalculator = IdSignatureHashCalculator()
|
val signatureHashCalculator = IdSignatureHashCalculator()
|
||||||
|
|
||||||
private val incrementalCaches = libraries.entries.associate { (libFile, lib) ->
|
private val incrementalCaches = run {
|
||||||
val cachePath = cacheMap[lib] ?: notFoundIcError("cache path", KotlinLibraryFile(lib))
|
val md5 = MessageDigest.getInstance("MD5")
|
||||||
libFile to IncrementalCache(lib, cachePath)
|
libraries.entries.associate { (libFile, lib) ->
|
||||||
|
val file = File(libFile.path)
|
||||||
|
val hash = md5.digest(file.absolutePath.encodeToByteArray()).joinToString("", transform = { "%02x".format(it) })
|
||||||
|
libFile to IncrementalCache(lib, File(icCacheRootDir, "${file.name}.$hash"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getLibIncrementalCache(libFile: KotlinLibraryFile) =
|
private fun getLibIncrementalCache(libFile: KotlinLibraryFile) =
|
||||||
|
|||||||
+1
-2
@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.protobuf.CodedOutputStream
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
|
|
||||||
internal class IncrementalCache(private val library: KotlinLibrary, cachePath: String) {
|
internal class IncrementalCache(private val library: KotlinLibrary, private val cacheDir: File) {
|
||||||
companion object {
|
companion object {
|
||||||
private const val CACHE_HEADER = "ic.header.bin"
|
private const val CACHE_HEADER = "ic.header.bin"
|
||||||
|
|
||||||
@@ -24,7 +24,6 @@ internal class IncrementalCache(private val library: KotlinLibrary, cachePath: S
|
|||||||
}
|
}
|
||||||
|
|
||||||
private var forceRebuildJs = false
|
private var forceRebuildJs = false
|
||||||
private val cacheDir = File(cachePath)
|
|
||||||
private val signatureToIndexMappingFromMetadata = hashMapOf<KotlinSourceFile, MutableMap<IdSignature, Int>>()
|
private val signatureToIndexMappingFromMetadata = hashMapOf<KotlinSourceFile, MutableMap<IdSignature, Int>>()
|
||||||
|
|
||||||
private val libraryFile = KotlinLibraryFile(library)
|
private val libraryFile = KotlinLibraryFile(library)
|
||||||
|
|||||||
@@ -92,10 +92,6 @@ abstract class AbstractInvalidationTest : KotlinTestWithEnvironment() {
|
|||||||
return File(File(buildDir, moduleName), "$moduleName.klib")
|
return File(File(buildDir, moduleName), "$moduleName.klib")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun resolveModuleCache(moduleName: String, buildDir: File): File {
|
|
||||||
return File(File(buildDir, moduleName), "cache")
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createConfiguration(moduleName: String, language: List<String>): CompilerConfiguration {
|
private fun createConfiguration(moduleName: String, language: List<String>): CompilerConfiguration {
|
||||||
val copy = environment.configuration.copy()
|
val copy = environment.configuration.copy()
|
||||||
copy.put(CommonConfigurationKeys.MODULE_NAME, moduleName)
|
copy.put(CommonConfigurationKeys.MODULE_NAME, moduleName)
|
||||||
@@ -127,7 +123,6 @@ abstract class AbstractInvalidationTest : KotlinTestWithEnvironment() {
|
|||||||
private inner class TestStepInfo(
|
private inner class TestStepInfo(
|
||||||
val moduleName: String,
|
val moduleName: String,
|
||||||
val modulePath: String,
|
val modulePath: String,
|
||||||
val icCacheDir: String,
|
|
||||||
val expectedFileStats: Map<String, Set<String>>
|
val expectedFileStats: Map<String, Set<String>>
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -157,7 +152,6 @@ abstract class AbstractInvalidationTest : KotlinTestWithEnvironment() {
|
|||||||
return TestStepInfo(
|
return TestStepInfo(
|
||||||
module.safeModuleName,
|
module.safeModuleName,
|
||||||
outputKlibFile.canonicalPath,
|
outputKlibFile.canonicalPath,
|
||||||
resolveModuleCache(module, buildDir).canonicalPath,
|
|
||||||
expectedFileStats
|
expectedFileStats
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -229,7 +223,6 @@ abstract class AbstractInvalidationTest : KotlinTestWithEnvironment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun execute() {
|
fun execute() {
|
||||||
val stdlibCacheDir = resolveModuleCache(STDLIB_ALIAS, buildDir).canonicalPath
|
|
||||||
for (projStep in projectInfo.steps) {
|
for (projStep in projectInfo.steps) {
|
||||||
val testInfo = projStep.order.map { setupTestStep(projStep, it) }
|
val testInfo = projStep.order.map { setupTestStep(projStep, it) }
|
||||||
|
|
||||||
@@ -237,7 +230,7 @@ abstract class AbstractInvalidationTest : KotlinTestWithEnvironment() {
|
|||||||
val cacheUpdater = CacheUpdater(
|
val cacheUpdater = CacheUpdater(
|
||||||
mainModule = testInfo.last().modulePath,
|
mainModule = testInfo.last().modulePath,
|
||||||
allModules = testInfo.mapTo(mutableListOf(STDLIB_KLIB)) { it.modulePath },
|
allModules = testInfo.mapTo(mutableListOf(STDLIB_KLIB)) { it.modulePath },
|
||||||
icCachePaths = testInfo.mapTo(mutableListOf(stdlibCacheDir)) { it.icCacheDir },
|
icCacheRootDir = buildDir.resolve("incremental-cache").absolutePath,
|
||||||
compilerConfiguration = configuration,
|
compilerConfiguration = configuration,
|
||||||
irFactory = { IrFactoryImplForJsIC(WholeWorldStageController()) },
|
irFactory = { IrFactoryImplForJsIC(WholeWorldStageController()) },
|
||||||
mainArguments = null,
|
mainArguments = null,
|
||||||
|
|||||||
@@ -189,13 +189,11 @@ abstract class AbstractJsKLibABITestCase : KtUsefulTestCase() {
|
|||||||
mainModuleKlibFile: File,
|
mainModuleKlibFile: File,
|
||||||
allDependencies: KlibABITestUtils.Dependencies
|
allDependencies: KlibABITestUtils.Dependencies
|
||||||
): CompilationOutputs {
|
): CompilationOutputs {
|
||||||
fun cacheDir(library: File): File = buildDir.resolve("libs-cache").resolve(library.name).apply { mkdirs() }
|
|
||||||
|
|
||||||
// TODO: what about friend dependencies?
|
// TODO: what about friend dependencies?
|
||||||
val cacheUpdater = CacheUpdater(
|
val cacheUpdater = CacheUpdater(
|
||||||
mainModule = mainModuleKlibFile.absolutePath,
|
mainModule = mainModuleKlibFile.absolutePath,
|
||||||
allModules = allDependencies.regularDependencies.map { it.path },
|
allModules = allDependencies.regularDependencies.map { it.path },
|
||||||
icCachePaths = allDependencies.regularDependencies.map { cacheDir(it).path },
|
icCacheRootDir = buildDir.resolve("libs-cache").absolutePath,
|
||||||
compilerConfiguration = configuration,
|
compilerConfiguration = configuration,
|
||||||
irFactory = { IrFactoryImplForJsIC(WholeWorldStageController()) },
|
irFactory = { IrFactoryImplForJsIC(WholeWorldStageController()) },
|
||||||
mainArguments = null,
|
mainArguments = null,
|
||||||
|
|||||||
Reference in New Issue
Block a user