[JS IR] Use jsOutputName for module naming when IC is enabled
^KT-53986 Fixed
This commit is contained in:
committed by
Space
parent
ef05a0d9ed
commit
dd7d669464
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||
import org.jetbrains.kotlin.ir.backend.js.*
|
||||
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsIrLinker
|
||||
import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.JsIrFragmentAndBinaryAst
|
||||
import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.safeModuleName
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
@@ -514,6 +515,7 @@ class CacheUpdater(
|
||||
}
|
||||
artifacts += incrementalCache.buildModuleArtifactAndCommitCache(
|
||||
moduleName = libFragment.name.asString(),
|
||||
externalModuleName = lib.jsOutputName,
|
||||
rebuiltFileFragments = libRebuiltFiles,
|
||||
signatureToIndexMapping = signatureToIndexMapping
|
||||
)
|
||||
|
||||
+2
-1
@@ -84,6 +84,7 @@ class IncrementalCache(private val library: KotlinLibrary, cachePath: String) {
|
||||
|
||||
fun buildModuleArtifactAndCommitCache(
|
||||
moduleName: String,
|
||||
externalModuleName: String?,
|
||||
rebuiltFileFragments: Map<KotlinSourceFile, JsIrFragmentAndBinaryAst>,
|
||||
signatureToIndexMapping: Map<KotlinSourceFile, Map<IdSignature, Int>>
|
||||
): ModuleArtifact {
|
||||
@@ -98,7 +99,7 @@ class IncrementalCache(private val library: KotlinLibrary, cachePath: String) {
|
||||
SrcFileArtifact(srcFile.path, rebuiltFileFragment?.fragment, binaryAstFile)
|
||||
}
|
||||
|
||||
return ModuleArtifact(moduleName, fileArtifacts, cacheDir, forceRebuildJs)
|
||||
return ModuleArtifact(moduleName, fileArtifacts, cacheDir, forceRebuildJs, externalModuleName)
|
||||
}
|
||||
|
||||
data class ModifiedFiles(
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ class JsMultiModuleCache(private val moduleArtifacts: List<ModuleArtifact>) {
|
||||
}
|
||||
CachedModuleInfo(
|
||||
artifact = this@fetchModuleInfo,
|
||||
jsIrHeader = JsIrModuleHeader(moduleSafeName, moduleSafeName, definitions, nameBindings, hasJsExports, null),
|
||||
jsIrHeader = JsIrModuleHeader(moduleSafeName, moduleExternalName, definitions, nameBindings, hasJsExports, null),
|
||||
crossModuleReferencesHash = crossModuleReferencesHash
|
||||
)
|
||||
}
|
||||
|
||||
@@ -31,13 +31,15 @@ class ModuleArtifact(
|
||||
moduleName: String,
|
||||
val fileArtifacts: List<SrcFileArtifact>,
|
||||
val artifactsDir: File? = null,
|
||||
val forceRebuildJs: Boolean = false
|
||||
val forceRebuildJs: Boolean = false,
|
||||
externalModuleName: String? = null
|
||||
) {
|
||||
val moduleSafeName = moduleName.safeModuleName
|
||||
val moduleExternalName = externalModuleName ?: moduleSafeName
|
||||
|
||||
fun loadJsIrModule(): JsIrModule {
|
||||
val deserializer = JsIrAstDeserializer()
|
||||
val fragments = fileArtifacts.sortedBy { it.srcFilePath }.mapNotNull { it.loadJsIrFragment(deserializer) }
|
||||
return JsIrModule(moduleSafeName, moduleSafeName, fragments)
|
||||
return JsIrModule(moduleSafeName, moduleExternalName, fragments)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +79,9 @@ val KotlinLibrary.isBuiltIns: Boolean
|
||||
.propertyList(KLIB_PROPERTY_DEPENDS, escapeInQuotes = true)
|
||||
.isEmpty()
|
||||
|
||||
val KotlinLibrary.jsOutputName: String?
|
||||
get() = manifestProperties.getProperty(KLIB_PROPERTY_JS_OUTPUT_NAME)
|
||||
|
||||
private val CompilerConfiguration.metadataVersion
|
||||
get() = get(CommonConfigurationKeys.METADATA_VERSION) as? KlibMetadataVersion ?: KlibMetadataVersion.INSTANCE
|
||||
|
||||
@@ -869,8 +872,6 @@ private fun KlibMetadataIncrementalSerializer(configuration: CompilerConfigurati
|
||||
|
||||
private fun Map<IrModuleFragment, KotlinLibrary>.getUniqueNameForEachFragment(): Map<IrModuleFragment, String> {
|
||||
return this.entries.mapNotNull { (moduleFragment, klib) ->
|
||||
klib.manifestProperties.getProperty(KLIB_PROPERTY_JS_OUTPUT_NAME)?.let {
|
||||
moduleFragment to it
|
||||
}
|
||||
klib.jsOutputName?.let { moduleFragment to it }
|
||||
}.toMap()
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ abstract class AbstractInvalidationTest : KotlinTestWithEnvironment() {
|
||||
private const val BOX_FUNCTION_NAME = "box"
|
||||
private const val STDLIB_ALIAS = "stdlib"
|
||||
|
||||
private val STDLIB_MODULE_NAME = "kotlin".safeModuleName
|
||||
private val STDLIB_MODULE_NAME = "kotlin-kotlin-stdlib-js-ir"
|
||||
private val STDLIB_KLIB = File(System.getProperty("kotlin.js.stdlib.klib.path") ?: error("Please set stdlib path")).canonicalPath
|
||||
|
||||
private val KT_FILE_IGNORE_PATTERN = Regex("^.*\\..+\\.kt$")
|
||||
@@ -175,9 +175,8 @@ abstract class AbstractInvalidationTest : KotlinTestWithEnvironment() {
|
||||
}
|
||||
|
||||
private fun verifyJsExecutableProducerBuildModules(stepId: Int, gotRebuilt: Set<String>, expectedRebuilt: List<String>) {
|
||||
val expected = expectedRebuilt.map { it.safeModuleName }
|
||||
val got = gotRebuilt.filter { it != STDLIB_MODULE_NAME }
|
||||
JUnit4Assertions.assertSameElements(got, expected) {
|
||||
JUnit4Assertions.assertSameElements(got, expectedRebuilt) {
|
||||
"Mismatched rebuilt modules at step $stepId"
|
||||
}
|
||||
}
|
||||
@@ -249,8 +248,9 @@ abstract class AbstractInvalidationTest : KotlinTestWithEnvironment() {
|
||||
val icCaches = cacheUpdater.actualizeCaches()
|
||||
verifyCacheUpdateStats(projStep.id, cacheUpdater.getDirtyFileStats(), testInfo)
|
||||
|
||||
val mainModuleName = icCaches.last().moduleExternalName
|
||||
val jsExecutableProducer = JsExecutableProducer(
|
||||
mainModuleName = testInfo.last().moduleName,
|
||||
mainModuleName = mainModuleName,
|
||||
moduleKind = configuration[JSConfigurationKeys.MODULE_KIND]!!,
|
||||
sourceMapsInfo = SourceMapsInfo.from(configuration),
|
||||
caches = icCaches,
|
||||
@@ -260,7 +260,7 @@ abstract class AbstractInvalidationTest : KotlinTestWithEnvironment() {
|
||||
val rebuiltModules = mutableSetOf<String>()
|
||||
val jsOutput = jsExecutableProducer.buildExecutable(multiModule = true, outJsProgram = true) { rebuiltModules += it }
|
||||
verifyJsExecutableProducerBuildModules(projStep.id, rebuiltModules, projStep.dirtyJS)
|
||||
verifyJsCode(projStep.id, testInfo.last().moduleName, jsOutput)
|
||||
verifyJsCode(projStep.id, mainModuleName, jsOutput)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -194,14 +194,14 @@ class Kotlin2JsIrGradlePluginIT : AbstractKotlin2JsGradlePluginIT(true) {
|
||||
.forEach {
|
||||
val text = it.readText()
|
||||
// cache keeps the js code of compiled module, this substring from that js code
|
||||
if (text.contains("kotlin_js_ir_ic_multiple_artifacts_lib ")) {
|
||||
if (text.contains("root['kotlin-js-ir-ic-multiple-artifacts-lib']")) {
|
||||
if (lib) {
|
||||
error("lib should be only once in cache")
|
||||
}
|
||||
lib = true
|
||||
}
|
||||
// cache keeps the js code of compiled module, this substring from that js code
|
||||
if (text.contains("kotlin_js_ir_ic_multiple_artifacts_lib_other ")) {
|
||||
if (text.contains("root['kotlin-js-ir-ic-multiple-artifacts-lib-other']")) {
|
||||
if (libOther) {
|
||||
error("libOther should be only once in cache")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user