[JS IR] Enable DTS generation in IC
^KT-54398 Fixed
This commit is contained in:
committed by
Space Team
parent
d21cbfe02e
commit
9edaebf235
+7
-3
@@ -95,10 +95,14 @@ internal fun File.fileHashForIC(): ICHash {
|
||||
}
|
||||
|
||||
internal fun CompilerConfiguration.configHashForIC() = HashCalculatorForIC().apply {
|
||||
val importantBooleanSettingKeys = listOf(JSConfigurationKeys.PROPERTY_LAZY_INITIALIZATION)
|
||||
updateForEach(importantBooleanSettingKeys) { key ->
|
||||
val importantSettings = listOf(
|
||||
JSConfigurationKeys.GENERATE_DTS,
|
||||
JSConfigurationKeys.MODULE_KIND,
|
||||
JSConfigurationKeys.PROPERTY_LAZY_INITIALIZATION
|
||||
)
|
||||
updateForEach(importantSettings) { key ->
|
||||
update(key.toString())
|
||||
update(getBoolean(key).toString())
|
||||
update(get(key).toString())
|
||||
}
|
||||
|
||||
update(languageVersionSettings.toString())
|
||||
|
||||
+16
-10
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.ir.backend.js.ic
|
||||
|
||||
import org.jetbrains.kotlin.ir.backend.js.CompilationOutputs
|
||||
import org.jetbrains.kotlin.ir.backend.js.export.TypeScriptFragment
|
||||
import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.CrossModuleReferences
|
||||
import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.JsIrModuleHeader
|
||||
import java.io.File
|
||||
@@ -15,6 +16,7 @@ class JsMultiModuleCache(private val moduleArtifacts: List<ModuleArtifact>) {
|
||||
private const val JS_MODULE_HEADER = "js.module.header.bin"
|
||||
private const val CACHED_MODULE_JS = "module.js"
|
||||
private const val CACHED_MODULE_JS_MAP = "module.js.map"
|
||||
private const val CACHED_MODULE_D_TS = "module.d.ts"
|
||||
}
|
||||
|
||||
private enum class NameType(val typeMask: Int) {
|
||||
@@ -71,22 +73,26 @@ class JsMultiModuleCache(private val moduleArtifacts: List<ModuleArtifact>) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun File.writeIfNotNull(data: String?) {
|
||||
if (data != null) {
|
||||
recreate()
|
||||
writeText(data)
|
||||
} else {
|
||||
ifExists { delete() }
|
||||
}
|
||||
}
|
||||
|
||||
fun fetchCompiledJsCode(artifact: ModuleArtifact) = artifact.artifactsDir?.let { cacheDir ->
|
||||
val jsCode = File(cacheDir, CACHED_MODULE_JS).ifExists { readText() }
|
||||
val sourceMap = File(cacheDir, CACHED_MODULE_JS_MAP).ifExists { readText() }
|
||||
jsCode?.let { CompilationOutputs(it, null, null, sourceMap) }
|
||||
val tsDefinitions = File(cacheDir, CACHED_MODULE_D_TS).ifExists { TypeScriptFragment(readText()) }
|
||||
jsCode?.let { CompilationOutputs(it, tsDefinitions, null, sourceMap) }
|
||||
}
|
||||
|
||||
fun commitCompiledJsCode(artifact: ModuleArtifact, compilationOutputs: CompilationOutputs) = artifact.artifactsDir?.let { cacheDir ->
|
||||
val jsCodeCache = File(cacheDir, CACHED_MODULE_JS).apply { recreate() }
|
||||
jsCodeCache.writeText(compilationOutputs.jsCode)
|
||||
val jsMapCache = File(cacheDir, CACHED_MODULE_JS_MAP)
|
||||
if (compilationOutputs.sourceMap != null) {
|
||||
jsMapCache.recreate()
|
||||
jsMapCache.writeText(compilationOutputs.sourceMap)
|
||||
} else {
|
||||
jsMapCache.ifExists { delete() }
|
||||
}
|
||||
File(cacheDir, CACHED_MODULE_JS).writeIfNotNull(compilationOutputs.jsCode)
|
||||
File(cacheDir, CACHED_MODULE_JS_MAP).writeIfNotNull(compilationOutputs.sourceMap)
|
||||
File(cacheDir, CACHED_MODULE_D_TS).writeIfNotNull(compilationOutputs.tsDefinitions?.raw)
|
||||
}
|
||||
|
||||
fun loadProgramHeadersFromCache(): List<CachedModuleInfo> {
|
||||
|
||||
@@ -47,7 +47,8 @@ class ModuleInfo(val moduleName: String) {
|
||||
val id: Int,
|
||||
val dependencies: Collection<Dependency>,
|
||||
val modifications: List<Modification>,
|
||||
val expectedFileStats: Map<String, Set<String>>
|
||||
val expectedFileStats: Map<String, Set<String>>,
|
||||
val expectedDTS: Set<String>
|
||||
)
|
||||
|
||||
val steps = mutableListOf<ModuleStep>()
|
||||
@@ -65,6 +66,7 @@ private const val FRIENDS = "friends"
|
||||
private const val MODIFICATIONS = "modifications"
|
||||
private const val MODIFICATION_UPDATE = "U"
|
||||
private const val MODIFICATION_DELETE = "D"
|
||||
private const val EXPECTED_DTS_LIST = "expected dts"
|
||||
|
||||
private val STEP_PATTERN = Pattern.compile("^\\s*STEP\\s+(\\d+)\\.*(\\d+)?\\s*:?$")
|
||||
|
||||
@@ -210,6 +212,7 @@ class ModuleInfoParser(infoFile: File) : InfoParser<ModuleInfo>(infoFile) {
|
||||
val regularDependencies = mutableSetOf<String>()
|
||||
val friendDependencies = mutableSetOf<String>()
|
||||
val modifications = mutableListOf<ModuleInfo.Modification>()
|
||||
val expectedDTS = mutableSetOf<String>()
|
||||
|
||||
loop { line ->
|
||||
if (line.matches(STEP_PATTERN.toRegex()))
|
||||
@@ -230,6 +233,7 @@ class ModuleInfoParser(infoFile: File) : InfoParser<ModuleInfo>(infoFile) {
|
||||
DEPENDENCIES -> getOpArgs().forEach { regularDependencies += it }
|
||||
FRIENDS -> getOpArgs().forEach { friendDependencies += it }
|
||||
MODIFICATIONS -> modifications += parseModifications()
|
||||
EXPECTED_DTS_LIST -> getOpArgs().forEach { expectedDTS += it }
|
||||
else -> error(diagnosticMessage("Unknown op $op", line))
|
||||
}
|
||||
}
|
||||
@@ -250,7 +254,8 @@ class ModuleInfoParser(infoFile: File) : InfoParser<ModuleInfo>(infoFile) {
|
||||
id = it,
|
||||
dependencies = dependencies,
|
||||
modifications = modifications,
|
||||
expectedFileStats = expectedFileStats
|
||||
expectedFileStats = expectedFileStats,
|
||||
expectedDTS = expectedDTS
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user