From 26510190cc2caf093cac9dbfe3bcd345a09fe0ac Mon Sep 17 00:00:00 2001 From: Alexander Likhachev Date: Wed, 23 Jun 2021 18:26:35 +0300 Subject: [PATCH] [Gradle, JS] Include compiler type into library filter cache key Previous fix could lead to unresolved symbols from main implementation in test compilation when module is compiled with both JS (IR and legacy) compilers because of single cached filter for both compileTestKotlinJsLegacy and compileTestKotlinJsIr tasks #KT-47154 In Progress --- .../org/jetbrains/kotlin/gradle/tasks/Tasks.kt | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt index cc6c3de5793..d7ad33192a2 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt @@ -724,9 +724,13 @@ abstract class Kotlin2JsCompile @Inject constructor( } internal abstract class LibraryFilterCachingService : BuildService, AutoCloseable { - private val cache = ConcurrentHashMap() + internal data class LibraryFilterCacheKey(val dependency: File, val irEnabled: Boolean, val preIrDisabled: Boolean) - fun getOrCompute(key: File, compute: (File) -> Boolean) = cache.computeIfAbsent(key, compute) + private val cache = ConcurrentHashMap() + + fun getOrCompute(key: LibraryFilterCacheKey, compute: (File) -> Boolean) = cache.computeIfAbsent(key) { + compute(it.dependency) + } override fun close() { cache.clear() @@ -821,6 +825,13 @@ abstract class Kotlin2JsCompile @Inject constructor( "-Xir-produce-klib-file" ).any(freeCompilerArgs::contains) + private val File.asLibraryFilterCacheKey: LibraryFilterCachingService.LibraryFilterCacheKey + get() = LibraryFilterCachingService.LibraryFilterCacheKey( + this, + irEnabled = kotlinOptions.isIrBackendEnabled(), + preIrDisabled = kotlinOptions.isPreIrBackendDisabled() + ) + // Kotlin/JS can operate in 3 modes: // 1) purely pre-IR backend // 2) purely IR backend @@ -842,7 +853,7 @@ abstract class Kotlin2JsCompile @Inject constructor( @get:Internal protected val libraryFilter: (File) -> Boolean get() = { file -> - libraryCache.get().getOrCompute(file, libraryFilterBody) + libraryCache.get().getOrCompute(file.asLibraryFilterCacheKey, libraryFilterBody) } @get:Internal