[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:
committed by
Space Team
parent
f1b6c2df45
commit
331ec5318d
+22
@@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+27
@@ -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 })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
plugins {
|
||||
`kotlin-dsl`
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
+9
@@ -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
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package = my.cinterop
|
||||
---
|
||||
|
||||
static int foo() {
|
||||
return 42;
|
||||
}
|
||||
+1
@@ -45,6 +45,7 @@ internal val KotlinCreateNativeCInteropTasksSideEffect = KotlinCompilationSideEf
|
||||
"for compilation '${compilation.compilationName}'" +
|
||||
"of target '${it.konanTarget.name}'."
|
||||
it.enabled = compilation.konanTarget.enabledOnCurrentHost
|
||||
it.definitionFile.set(params.settings.definitionFile)
|
||||
}
|
||||
|
||||
|
||||
|
||||
+12
-5
@@ -10,6 +10,7 @@ import org.gradle.api.Action
|
||||
import org.gradle.api.NamedDomainObjectFactory
|
||||
import org.gradle.api.file.FileCollection
|
||||
import org.gradle.api.file.ProjectLayout
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.internal.file.FileOperations
|
||||
import org.gradle.api.model.ObjectFactory
|
||||
import org.gradle.api.provider.ListProperty
|
||||
@@ -19,9 +20,8 @@ import org.jetbrains.kotlin.gradle.plugin.CInteropSettings
|
||||
import org.jetbrains.kotlin.gradle.plugin.CInteropSettings.IncludeDirectories
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||
import org.jetbrains.kotlin.gradle.targets.native.internal.CInteropIdentifier
|
||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||
import org.jetbrains.kotlin.gradle.utils.newInstance
|
||||
import org.jetbrains.kotlin.gradle.utils.property
|
||||
import org.jetbrains.kotlin.gradle.utils.*
|
||||
import org.jetbrains.kotlin.gradle.utils.getFile
|
||||
import org.jetbrains.kotlin.util.capitalizeDecapitalize.capitalizeAsciiOnly
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
@@ -71,12 +71,19 @@ abstract class DefaultCInteropSettings @Inject internal constructor(
|
||||
|
||||
val interopProcessingTaskName get() = params.interopProcessingTaskName
|
||||
|
||||
val defFileProperty: Property<File> = params.services.objectFactory.property<File>().value(
|
||||
|
||||
@Deprecated("Deprecated. Please, use definitionFile.", ReplaceWith("definitionFile"))
|
||||
val defFileProperty: Property<File> = params.services.objectFactory.property<File>().convention(
|
||||
params.services.projectLayout.projectDirectory.file("src/nativeInterop/cinterop/$name.def").asFile
|
||||
)
|
||||
|
||||
val definitionFile: RegularFileProperty = params.services.objectFactory.fileProperty().convention(
|
||||
params.services.projectLayout.file(defFileProperty)
|
||||
)
|
||||
|
||||
@Deprecated("Deprecated because it is a non-lazy property.", ReplaceWith("definitionFile"))
|
||||
var defFile: File
|
||||
get() = defFileProperty.get()
|
||||
get() = definitionFile.getFile()
|
||||
set(value) {
|
||||
defFileProperty.set(value)
|
||||
}
|
||||
|
||||
+8
-6
@@ -310,9 +310,13 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
|
||||
|
||||
val defTask = project.registerTask<DefFileTask>(
|
||||
lowerCamelCaseName("generateDef", pod.moduleName).asValidTaskName()
|
||||
) {
|
||||
it.pod.set(pod)
|
||||
it.description = "Generates a def file for CocoaPods dependencies with module ${pod.moduleName}"
|
||||
) {task ->
|
||||
task.pod.set(pod)
|
||||
val defFileAbsolutePath = project.layout.cocoapodsBuildDirs.defs.map {
|
||||
it.asFile.resolve("${task.pod.get().moduleName}.def").absolutePath
|
||||
}
|
||||
task.defFile.set(project.layout.projectDirectory.file(defFileAbsolutePath))
|
||||
task.description = "Generates a def file for CocoaPods dependencies with module ${pod.moduleName}"
|
||||
// This task is an implementation detail so we don't add it in any group
|
||||
// to avoid showing it in the `tasks` output.
|
||||
}
|
||||
@@ -325,14 +329,12 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
|
||||
|
||||
interopTask.onlyIf { HostManager.hostIsMac }
|
||||
|
||||
interopTask.dependsOn(defTask)
|
||||
|
||||
pod.interopBindingDependencies.forEach { dependencyName ->
|
||||
addPodDependencyToInterop(project, cocoapodsExtension, pod, cinterops, interop, dependencyName)
|
||||
}
|
||||
|
||||
with(interop) {
|
||||
defFileProperty.set(defTask.flatMap { it.defFile.mapToFile() })
|
||||
defFileProperty.set(defTask.flatMap { it.defFile.asFile })
|
||||
_packageNameProp.set(project.provider { pod.packageName })
|
||||
_extraOptsProp.addAll(project.provider { pod.extraOpts })
|
||||
}
|
||||
|
||||
+3
-7
@@ -7,33 +7,29 @@
|
||||
package org.jetbrains.kotlin.gradle.tasks
|
||||
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.file.ProjectLayout
|
||||
import org.gradle.api.file.RegularFile
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.tasks.Internal
|
||||
import org.gradle.api.tasks.Nested
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.work.DisableCachingByDefault
|
||||
import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension.CocoapodsDependency
|
||||
import org.jetbrains.kotlin.gradle.plugin.cocoapods.cocoapodsBuildDirs
|
||||
import org.jetbrains.kotlin.gradle.utils.appendLine
|
||||
import org.jetbrains.kotlin.gradle.utils.getFile
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* Generates a def-file for the given CocoaPods dependency.
|
||||
*/
|
||||
@DisableCachingByDefault
|
||||
abstract class DefFileTask @Inject constructor(projectLayout: ProjectLayout) : DefaultTask() {
|
||||
abstract class DefFileTask : DefaultTask() {
|
||||
|
||||
@get:Nested
|
||||
abstract val pod: Property<CocoapodsDependency>
|
||||
|
||||
@get:OutputFile
|
||||
val defFile: Provider<RegularFile> = projectLayout.cocoapodsBuildDirs.defs.map { it.file("${pod.get().moduleName}.def") }
|
||||
abstract val defFile: RegularFileProperty
|
||||
|
||||
@get:Internal
|
||||
@Deprecated("Use `defFile` instead", replaceWith = ReplaceWith("defFile.get().asFile"))
|
||||
|
||||
+10
-2
@@ -1094,7 +1094,15 @@ abstract class CInteropProcess @Inject internal constructor(params: Params) :
|
||||
@get:InputFile
|
||||
@get:PathSensitive(PathSensitivity.RELATIVE)
|
||||
@get:NormalizeLineEndings
|
||||
val defFile: File get() = settings.defFileProperty.get()
|
||||
abstract val definitionFile: RegularFileProperty
|
||||
|
||||
@get:Internal
|
||||
@Deprecated(
|
||||
"This eager parameter is deprecated.",
|
||||
replaceWith = ReplaceWith("definitionFile")
|
||||
)
|
||||
val defFile: File get() = definitionFile.asFile.get()
|
||||
|
||||
|
||||
@get:Optional
|
||||
@get:Input
|
||||
@@ -1147,7 +1155,7 @@ abstract class CInteropProcess @Inject internal constructor(params: Params) :
|
||||
addArg("-o", outputFile.absolutePath)
|
||||
|
||||
addArgIfNotNull("-target", konanTarget.visibleName)
|
||||
addArgIfNotNull("-def", defFile.canonicalPath)
|
||||
addArgIfNotNull("-def", definitionFile.getFile().canonicalPath)
|
||||
addArgIfNotNull("-pkg", packageName)
|
||||
|
||||
addFileArgs("-header", headers)
|
||||
|
||||
+2
-1
@@ -10,6 +10,7 @@ package org.jetbrains.kotlin.gradle.unitTests
|
||||
import org.jetbrains.kotlin.gradle.util.MultiplatformExtensionTest
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.DefaultCInteropSettings
|
||||
import org.jetbrains.kotlin.gradle.tasks.CInteropProcess
|
||||
import org.jetbrains.kotlin.gradle.utils.getFile
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@@ -48,7 +49,7 @@ class CInteropTaskTest : MultiplatformExtensionTest() {
|
||||
project.evaluate()
|
||||
|
||||
assertEquals("updated-dependencyFile", cinteropTask.libraries.files.single().name)
|
||||
assertEquals("updated-defFile", cinteropTask.defFile.name)
|
||||
assertEquals("updated-defFile", cinteropTask.definitionFile.getFile().name)
|
||||
assertEquals("updated-packageName", cinteropTask.packageName)
|
||||
assertEquals(listOf("default-compilerOpts", "updated-compilerOpts"), cinteropTask.compilerOpts)
|
||||
assertEquals(listOf("default-linkerOpts", "updated-linkerOpts"), cinteropTask.linkerOpts)
|
||||
|
||||
Reference in New Issue
Block a user