From 8ff1d66ec9aa2afdd8dc75ed12efa579e6f6d801 Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Mon, 1 Nov 2021 21:09:32 +0700 Subject: [PATCH] [K/N][build] Fix up-do-date checks for cache tasks A name of a cache directory produced by the compiler for a library is based on the unique name of this library. The cache task, when declaring its outputs, assumes that this unique name is equal to the name of the library file/directory. If this is not the case, the up-to-date check works inconsistently and Gradle doesn't rerun the task. This patch fixes this issue by obtaining the real unique name of the library. --- .../gradle/plugin/konan/tasks/KonanCacheTask.kt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/kotlin-native/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/konan/tasks/KonanCacheTask.kt b/kotlin-native/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/konan/tasks/KonanCacheTask.kt index 4c8ddd16147..ca9096d36d9 100644 --- a/kotlin-native/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/konan/tasks/KonanCacheTask.kt +++ b/kotlin-native/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/konan/tasks/KonanCacheTask.kt @@ -6,8 +6,11 @@ import org.gradle.api.provider.Property import org.gradle.api.tasks.* import org.jetbrains.kotlin.gradle.plugin.konan.KonanCompilerRunner import org.jetbrains.kotlin.gradle.plugin.konan.konanHome +import org.jetbrains.kotlin.konan.library.defaultResolver import org.jetbrains.kotlin.konan.target.CompilerOutputKind +import org.jetbrains.kotlin.konan.target.Distribution import org.jetbrains.kotlin.konan.target.PlatformManager +import org.jetbrains.kotlin.library.uniqueName import org.jetbrains.kotlin.* import java.io.File @@ -34,9 +37,13 @@ open class KonanCacheTask: DefaultTask() { @get:OutputDirectory val cacheFile: File get() { - val klibName = originalKlib?.let { - if (it.isDirectory) it.name else it.nameWithoutExtension - } + val konanHome = compilerDistributionPath.get().absolutePath + val resolver = defaultResolver( + emptyList(), + PlatformManager(konanHome).targetByName(target), + Distribution(konanHome) + ) + val klibName = resolver.resolve(originalKlib!!.absolutePath).uniqueName return cacheDirectory.resolve("${klibName}-cache") }