[Gradle] Added definitionFile RegularFileProperty in cinterop task

^KT-62795 Fixed

Merge-request: KT-MR-13307
Merged-by: Dmitrii Krasnov <Dmitrii.Krasnov@jetbrains.com>
This commit is contained in:
Dmitrii Krasnov
2023-12-08 12:56:52 +00:00
committed by Space Team
parent f1b6c2df45
commit 331ec5318d
11 changed files with 107 additions and 21 deletions
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.gradle.native
import org.gradle.util.GradleVersion
import org.jetbrains.kotlin.gradle.testbase.*
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.condition.OS
@NativeGradlePluginTests
@@ -53,4 +54,25 @@ class CinteropIT : KGPBaseTest() {
}
}
}
@DisplayName("KT-62795: checking that we can pass def file to cinterop task as a output file property from another task")
@GradleTest
fun cinteropWithDefFileFromTaskOutput(gradleVersion: GradleVersion) {
nativeProject("cinterop-with-def-creation-task", gradleVersion = gradleVersion) {
val defFilePath = projectPath.resolve("def/cinterop.def").toFile().canonicalFile.absolutePath
build(":assemble") {
assertTasksUpToDate(":createDefFileTask") // this task does not have any action, so it always just UpToDate
extractNativeTasksCommandLineArgumentsFromOutput(":cinteropCinteropNative", toolName = NativeToolKind.C_INTEROP) {
assertCommandLineArgumentsContainSequentially("-def", defFilePath)
}
}
build(":assemble") {
assertTasksUpToDate(":createDefFileTask")
assertTasksUpToDate(":cinteropCinteropNative")
}
}
}
}
@@ -0,0 +1,27 @@
plugins {
kotlin("multiplatform")
}
repositories {
mavenCentral()
mavenLocal()
}
val createDefFileTask = project.tasks.register("createDefFileTask", CreateDefFileTask::class) {
defFile.set(project.layout.buildDirectory.file(project.file("def/cinterop.def").absolutePath))
}
kotlin {
<SingleNativeTarget>("native") {
binaries {
executable()
}
compilations.getByName("main") {
cinterops {
val cinterop by creating {
definitionFile.set(createDefFileTask.flatMap { it.defFile })
}
}
}
}
}
@@ -0,0 +1,7 @@
plugins {
`kotlin-dsl`
}
repositories {
mavenCentral()
}
@@ -0,0 +1,9 @@
import org.gradle.api.DefaultTask
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.tasks.OutputFile
abstract class CreateDefFileTask : DefaultTask() {
@get:OutputFile
abstract val defFile: RegularFileProperty
}
@@ -0,0 +1,6 @@
package = my.cinterop
---
static int foo() {
return 42;
}