[Gradle] CInteropProcess: Prevent compilation when depending on project without c-interops
This commit is contained in:
committed by
Space
parent
4ce3f87361
commit
947e97511b
+2
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.gradle.targets.metadata.isKotlinGranularMetadataEnab
|
|||||||
import org.jetbrains.kotlin.gradle.targets.native.*
|
import org.jetbrains.kotlin.gradle.targets.native.*
|
||||||
import org.jetbrains.kotlin.gradle.targets.native.internal.commonizeCInteropTask
|
import org.jetbrains.kotlin.gradle.targets.native.internal.commonizeCInteropTask
|
||||||
import org.jetbrains.kotlin.gradle.targets.native.internal.createCInteropApiElementsKlibArtifact
|
import org.jetbrains.kotlin.gradle.targets.native.internal.createCInteropApiElementsKlibArtifact
|
||||||
|
import org.jetbrains.kotlin.gradle.targets.native.internal.locateOrCreateCInteropApiElementsConfiguration
|
||||||
import org.jetbrains.kotlin.gradle.targets.native.internal.locateOrCreateCInteropDependencyConfiguration
|
import org.jetbrains.kotlin.gradle.targets.native.internal.locateOrCreateCInteropDependencyConfiguration
|
||||||
import org.jetbrains.kotlin.gradle.targets.native.tasks.*
|
import org.jetbrains.kotlin.gradle.targets.native.tasks.*
|
||||||
import org.jetbrains.kotlin.gradle.tasks.*
|
import org.jetbrains.kotlin.gradle.tasks.*
|
||||||
@@ -278,6 +279,7 @@ open class KotlinNativeTargetConfigurator<T : KotlinNativeTarget> : AbstractKotl
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected fun configureCInterops(target: KotlinNativeTarget): Unit = with(target.project) {
|
protected fun configureCInterops(target: KotlinNativeTarget): Unit = with(target.project) {
|
||||||
|
locateOrCreateCInteropApiElementsConfiguration(target)
|
||||||
target.compilations.all { compilation ->
|
target.compilations.all { compilation ->
|
||||||
createCInteropTasks(compilation, compilation.cinterops)
|
createCInteropTasks(compilation, compilation.cinterops)
|
||||||
compilation.cinterops.all { cinterop ->
|
compilation.cinterops.all { cinterop ->
|
||||||
|
|||||||
+7
-3
@@ -25,7 +25,8 @@ internal fun createCInteropApiElementsKlibArtifact(
|
|||||||
interopTask: TaskProvider<out CInteropProcess>
|
interopTask: TaskProvider<out CInteropProcess>
|
||||||
) {
|
) {
|
||||||
val project = settings.compilation.project
|
val project = settings.compilation.project
|
||||||
val configuration = project.locateOrCreateCInteropApiElementsConfiguration(settings.target ?: return)
|
val configurationName = cInteropApiElementsConfigurationName(settings.target ?: return)
|
||||||
|
val configuration = project.configurations.getByName(configurationName)
|
||||||
project.artifacts.add(configuration.name, interopTask.map { it.outputFile }) { artifact ->
|
project.artifacts.add(configuration.name, interopTask.map { it.outputFile }) { artifact ->
|
||||||
artifact.extension = "klib"
|
artifact.extension = "klib"
|
||||||
artifact.type = "klib"
|
artifact.type = "klib"
|
||||||
@@ -55,8 +56,8 @@ internal fun Project.locateOrCreateCInteropDependencyConfiguration(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Project.locateOrCreateCInteropApiElementsConfiguration(target: KotlinTarget): Configuration {
|
internal fun Project.locateOrCreateCInteropApiElementsConfiguration(target: KotlinTarget): Configuration {
|
||||||
val configurationName = target.name + "CInteropApiElements"
|
val configurationName = cInteropApiElementsConfigurationName(target)
|
||||||
configurations.findByName(configurationName)?.let { return it }
|
configurations.findByName(configurationName)?.let { return it }
|
||||||
|
|
||||||
return configurations.create(configurationName).apply {
|
return configurations.create(configurationName).apply {
|
||||||
@@ -70,6 +71,9 @@ private fun Project.locateOrCreateCInteropApiElementsConfiguration(target: Kotli
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun cInteropApiElementsConfigurationName(target: KotlinTarget): String {
|
||||||
|
return target.name + "CInteropApiElements"
|
||||||
|
}
|
||||||
|
|
||||||
internal object CInteropKlibLibraryElements {
|
internal object CInteropKlibLibraryElements {
|
||||||
const val CINTEROP_KLIB = "cinterop-klib"
|
const val CINTEROP_KLIB = "cinterop-klib"
|
||||||
|
|||||||
Reference in New Issue
Block a user