From 758b0ab457e0966cbc44ea1f9fd8ad47bd1ae79c Mon Sep 17 00:00:00 2001 From: Artem Kobzar Date: Thu, 16 Mar 2023 16:48:53 +0000 Subject: [PATCH] [K/JS] Fix Windows test run with a long test name --- .../kotlin/js/test/converters/JsIrBackendFacade.kt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/converters/JsIrBackendFacade.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/converters/JsIrBackendFacade.kt index 738a3c3b220..b343a174211 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/converters/JsIrBackendFacade.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/converters/JsIrBackendFacade.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.js.test.converters import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig import org.jetbrains.kotlin.backend.common.phaser.toPhaseMap +import org.jetbrains.kotlin.backend.common.serialization.cityHash64 import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureDescriptor import org.jetbrains.kotlin.cli.common.isWindows import org.jetbrains.kotlin.config.CommonConfigurationKeys @@ -302,7 +303,8 @@ val TestModule.kind: ModuleKind get() = directives.moduleKind fun String.augmentWithModuleName(moduleName: String): String { - val normalizedName = moduleName.run { if (isWindows) minify() else this } + val shouldMinimize = isWindows && moduleName.isPath() + val normalizedName = moduleName.run { if (shouldMinimize) minify() else this } val suffix = when { endsWith(ESM_EXTENSION) -> ESM_EXTENSION endsWith(REGULAR_EXTENSION) -> REGULAR_EXTENSION @@ -320,8 +322,14 @@ fun String.augmentWithModuleName(moduleName: String): String { // The hack should be deleted when D8 fixes the bug. // The issue is here: https://bugs.chromium.org/p/v8/issues/detail?id=13318 fun String.minify(): String { - return replace("kotlin_org_jetbrains_kotlin_kotlin_", "") - .replace("_minimal_for_test", "_min") + if (length <= 80) return this + + val directoryPath = substringBeforeLast('/') + val fileFullName = substringAfterLast('/') + val fileName = fileFullName.substringBeforeLast('.') + val fileExtension = fileFullName.substringAfterLast('.') + + return "$directoryPath/${fileName.cityHash64().toULong().toString(16)}.$fileExtension" } private fun String.isPath(): Boolean = contains("/")