[Gradle] Implement CInteropIdeaSyncIT to cover ^KT-48882

This commit is contained in:
sebastian.sellmair
2021-09-23 12:12:01 +02:00
committed by Space
parent ffaaadcfb6
commit 52c6713fff
8 changed files with 114 additions and 0 deletions
@@ -0,0 +1,66 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.gradle.native
import org.jetbrains.kotlin.gradle.BaseGradleIT
import kotlin.test.Test
class CInteropIdeaSyncIT : BaseGradleIT() {
private val ideaSyncBuildOptions = defaultBuildOptions().copy(
freeCommandLineArgs = listOf("-Didea.sync.active=true")
)
@Test
fun `test failing cinterop warning`() {
val ideaSyncWarningMessage = "Warning: Failed to generate cinterop for :cinteropSampleInteropNative"
val interopTaskName = ":cinteropSampleInteropNative"
with(Project("cinterop-failing")) {
/* Task still fails on 'normal' builds */
build("commonize") {
assertTasksFailed(interopTaskName)
}
/* Task failure is just a warning during import */
build("commonize", options = ideaSyncBuildOptions) {
assertSuccessful()
assertTasksExecuted(interopTaskName)
assertContains(ideaSyncWarningMessage)
}
/* Task is not considered up-to-date after lenient failure */
build("commonize", options = ideaSyncBuildOptions) {
assertSuccessful()
assertTasksExecuted(interopTaskName)
assertContains(ideaSyncWarningMessage)
}
/* Remove noise that causes failure */
projectDir.resolve("src/nativeInterop/cinterop/sampleInteropNoise.h").writeText("")
build("commonize", options = ideaSyncBuildOptions) {
assertSuccessful()
assertTasksExecuted(interopTaskName)
assertNotContains(ideaSyncWarningMessage)
}
/* Task is considered up-to-date after first successful run */
build("commonize", options = ideaSyncBuildOptions) {
assertSuccessful()
assertTasksUpToDate(interopTaskName)
assertNotContains(ideaSyncWarningMessage)
}
/* Task is still considered up-to-date after successful run in idea sync */
build("commonize") {
assertSuccessful()
assertTasksUpToDate(interopTaskName)
assertNotContains(ideaSyncWarningMessage)
}
}
}
}
@@ -0,0 +1,25 @@
import org.jetbrains.kotlin.konan.target.HostManager
plugins {
kotlin("multiplatform")
}
repositories {
mavenCentral()
mavenLocal()
}
kotlin {
val nativeTarget = when {
HostManager.hostIsMac -> macosX64("native")
HostManager.hostIsMingw -> mingwX64("native")
HostManager.hostIsLinux -> linuxX64("native")
else -> error("Unexpected host: ${HostManager.host}")
}
nativeTarget.compilations["main"].cinterops.create("sampleInterop") {
header(file("src/nativeInterop/cinterop/sampleInterop.h"))
header(file("src/nativeInterop/cinterop/sampleInteropNoise.h"))
}
}
@@ -0,0 +1,3 @@
kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.mpp.enableCInteropCommonization=true
kotlin.native.enableDependencyPropagation=false
@@ -0,0 +1,10 @@
pluginManagement {
repositories {
mavenLocal()
gradlePluginPortal()
}
val kotlin_version: String by settings
plugins {
kotlin("multiplatform").version(kotlin_version)
}
}
@@ -0,0 +1,7 @@
@file:Suppress("unused")
import sampleInterop.sampleInterop
object NativeMain {
fun x() = sampleInterop()
}