[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.
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 4c8ddd1..ca9096d 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.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 @@
     @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")
         }