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.
This commit is contained in:
+23
-9
@@ -87,9 +87,23 @@ private fun FileCollection.filterOutPublishableInteropLibs(project: Project): Fi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Collection<File>.filterExternalKlibs(project: Project) = filter {
|
/**
|
||||||
// Support only klib files for now.
|
* We pass to the compiler:
|
||||||
it.extension == "klib" && !it.providedByCompiler(project)
|
*
|
||||||
|
* - 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<File>.filterKlibsPassedToCompiler(project: Project) = filter {
|
||||||
|
it.extension == "klib" && it.exists() && !it.providedByCompiler(project)
|
||||||
}
|
}
|
||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
@@ -234,7 +248,7 @@ abstract class AbstractKotlinNativeCompile<T : KotlinCommonToolOptions> : Abstra
|
|||||||
addArg("-o", outputFile.get().absolutePath)
|
addArg("-o", outputFile.get().absolutePath)
|
||||||
|
|
||||||
// Libraries.
|
// Libraries.
|
||||||
libraries.files.filterExternalKlibs(project).forEach { library ->
|
libraries.files.filterKlibsPassedToCompiler(project).forEach { library ->
|
||||||
addArg("-l", library.absolutePath)
|
addArg("-l", library.absolutePath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -531,7 +545,7 @@ open class KotlinNativeLink : AbstractKotlinNativeCompile<KotlinCommonToolOption
|
|||||||
linkerOpts.forEach {
|
linkerOpts.forEach {
|
||||||
addArg("-linker-option", it)
|
addArg("-linker-option", it)
|
||||||
}
|
}
|
||||||
exportLibraries.files.filterExternalKlibs(project).forEach {
|
exportLibraries.files.filterKlibsPassedToCompiler(project).forEach {
|
||||||
add("-Xexport-library=${it.absolutePath}")
|
add("-Xexport-library=${it.absolutePath}")
|
||||||
}
|
}
|
||||||
addKey("-Xstatic-framework", isStaticFramework)
|
addKey("-Xstatic-framework", isStaticFramework)
|
||||||
@@ -580,11 +594,11 @@ open class KotlinNativeLink : AbstractKotlinNativeCompile<KotlinCommonToolOption
|
|||||||
|
|
||||||
private fun validatedExportedLibraries() {
|
private fun validatedExportedLibraries() {
|
||||||
val exportConfiguration = exportLibraries as? Configuration ?: return
|
val exportConfiguration = exportLibraries as? Configuration ?: return
|
||||||
val apiFiles = project.configurations.getByName(compilation.apiConfigurationName).files.filterExternalKlibs(project)
|
val apiFiles = project.configurations.getByName(compilation.apiConfigurationName).files.filterKlibsPassedToCompiler(project)
|
||||||
|
|
||||||
val failed = mutableSetOf<Dependency>()
|
val failed = mutableSetOf<Dependency>()
|
||||||
exportConfiguration.allDependencies.forEach {
|
exportConfiguration.allDependencies.forEach {
|
||||||
val dependencyFiles = exportConfiguration.files(it).filterExternalKlibs(project)
|
val dependencyFiles = exportConfiguration.files(it).filterKlibsPassedToCompiler(project)
|
||||||
if (!apiFiles.containsAll(dependencyFiles)) {
|
if (!apiFiles.containsAll(dependencyFiles)) {
|
||||||
failed.add(it)
|
failed.add(it)
|
||||||
}
|
}
|
||||||
@@ -747,7 +761,7 @@ class CacheBuilder(val project: Project, val binary: NativeBinary) {
|
|||||||
getAllDependencies(dependency)
|
getAllDependencies(dependency)
|
||||||
.flatMap { it.moduleArtifacts }
|
.flatMap { it.moduleArtifacts }
|
||||||
.map { it.file }
|
.map { it.file }
|
||||||
.filterExternalKlibs(project)
|
.filterKlibsPassedToCompiler(project)
|
||||||
.forEach {
|
.forEach {
|
||||||
args += "-l"
|
args += "-l"
|
||||||
args += it.absolutePath
|
args += it.absolutePath
|
||||||
@@ -903,7 +917,7 @@ open class CInteropProcess : DefaultTask() {
|
|||||||
addArg("-linker-option", it)
|
addArg("-linker-option", it)
|
||||||
}
|
}
|
||||||
|
|
||||||
libraries.files.filterExternalKlibs(project).forEach { library ->
|
libraries.files.filterKlibsPassedToCompiler(project).forEach { library ->
|
||||||
addArg("-library", library.absolutePath)
|
addArg("-library", library.absolutePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user