From df46dfc63de6d3192d4514015ad3d960de4b2469 Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Thu, 12 Dec 2019 19:28:52 +0700 Subject: [PATCH] Gradle, native: Don't pass to compiler missing klib files We don't compile a klib if there are no sources for it (NO-SOURCE checks). So, we need to take this fact into account and don't pass such libraries to compiler in dependent modules. See also: GH-2617 in the K/N repo. This patch checks that a klib file exists before passing it to the compiler. --- .../targets/native/tasks/KotlinNativeTasks.kt | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativeTasks.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativeTasks.kt index 0d4b3de2dad..3d6066b0d47 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativeTasks.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativeTasks.kt @@ -87,9 +87,23 @@ private fun FileCollection.filterOutPublishableInteropLibs(project: Project): Fi } } -private fun Collection.filterExternalKlibs(project: Project) = filter { - // Support only klib files for now. - it.extension == "klib" && !it.providedByCompiler(project) +/** + * We pass to the compiler: + * + * - Only *.klib files. A dependency configuration may contain jar files + * (e.g. when a common artifact was directly added to commonMain source set). + * So, we need to filter out such artifacts. + * + * - Only existing files. We don't compile a klib if there are no sources + * for it (NO-SOURCE check). So we need to take this case into account + * and skip libraries that were not compiled. See also: GH-2617 (K/N repo). + * + * - Only external libraries (not stdlib/platform libs). We add stdlib and + * platform libs to dependencies to get an IDE support. But the compiler + * uses them by default so we don't pass them to the compiler explicitly. + */ +private fun Collection.filterKlibsPassedToCompiler(project: Project) = filter { + it.extension == "klib" && it.exists() && !it.providedByCompiler(project) } // endregion @@ -234,7 +248,7 @@ abstract class AbstractKotlinNativeCompile : Abstra addArg("-o", outputFile.get().absolutePath) // Libraries. - libraries.files.filterExternalKlibs(project).forEach { library -> + libraries.files.filterKlibsPassedToCompiler(project).forEach { library -> addArg("-l", library.absolutePath) } } @@ -531,7 +545,7 @@ open class KotlinNativeLink : AbstractKotlinNativeCompile() exportConfiguration.allDependencies.forEach { - val dependencyFiles = exportConfiguration.files(it).filterExternalKlibs(project) + val dependencyFiles = exportConfiguration.files(it).filterKlibsPassedToCompiler(project) if (!apiFiles.containsAll(dependencyFiles)) { failed.add(it) } @@ -747,7 +761,7 @@ class CacheBuilder(val project: Project, val binary: NativeBinary) { getAllDependencies(dependency) .flatMap { it.moduleArtifacts } .map { it.file } - .filterExternalKlibs(project) + .filterKlibsPassedToCompiler(project) .forEach { args += "-l" args += it.absolutePath @@ -903,7 +917,7 @@ open class CInteropProcess : DefaultTask() { addArg("-linker-option", it) } - libraries.files.filterExternalKlibs(project).forEach { library -> + libraries.files.filterKlibsPassedToCompiler(project).forEach { library -> addArg("-library", library.absolutePath) }