[Gradle] Add destinationDirProperty to FatFrameworkTask

And use gradle's projectLayout.buildDirectory instead deprecated
project.buildDir.

^KT-56904
This commit is contained in:
Anton Lakotka
2023-12-01 11:25:03 +01:00
committed by Space Team
parent 834602b737
commit 8b335ea051
6 changed files with 37 additions and 21 deletions
@@ -125,7 +125,7 @@ private fun Project.registerAssembleAppleFrameworkTask(framework: Framework): Ta
needFatFramework -> locateOrRegisterTask<FatFrameworkTask>(frameworkTaskName) { task -> needFatFramework -> locateOrRegisterTask<FatFrameworkTask>(frameworkTaskName) { task ->
task.description = "Packs $frameworkBuildType fat framework for Xcode" task.description = "Packs $frameworkBuildType fat framework for Xcode"
task.baseName = framework.baseName task.baseName = framework.baseName
task.destinationDir = appleFrameworkDir(envFrameworkSearchDir) task.destinationDirProperty.convention(appleFrameworkDir(envFrameworkSearchDir))
task.isEnabled = frameworkBuildType == envBuildType task.isEnabled = frameworkBuildType == envBuildType
}.also { }.also {
it.configure { task -> task.from(framework) } it.configure { task -> task.from(framework) }
@@ -8,6 +8,8 @@ package org.jetbrains.kotlin.gradle.plugin.mpp.apple
import org.gradle.api.DefaultTask import org.gradle.api.DefaultTask
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.Task import org.gradle.api.Task
import org.gradle.api.file.Directory
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.ProjectLayout import org.gradle.api.file.ProjectLayout
import org.gradle.api.provider.Provider import org.gradle.api.provider.Provider
import org.gradle.api.tasks.* import org.gradle.api.tasks.*
@@ -20,6 +22,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.Framework
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
import org.jetbrains.kotlin.gradle.tasks.* import org.jetbrains.kotlin.gradle.tasks.*
import org.jetbrains.kotlin.gradle.utils.existsCompat import org.jetbrains.kotlin.gradle.utils.existsCompat
import org.jetbrains.kotlin.gradle.utils.getFile
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
import org.jetbrains.kotlin.konan.target.HostManager import org.jetbrains.kotlin.konan.target.HostManager
import org.jetbrains.kotlin.konan.target.KonanTarget import org.jetbrains.kotlin.konan.target.KonanTarget
@@ -139,7 +142,7 @@ private fun Project.registerAssembleFatForXCFrameworkTask(
) )
return registerTask(taskName) { task -> return registerTask(taskName) { task ->
task.destinationDir = XCFrameworkTask.fatFrameworkDir(project, xcFrameworkName, buildType, appleTarget) task.destinationDirProperty.set(XCFrameworkTask.fatFrameworkDir(project, xcFrameworkName, buildType, appleTarget))
task.onlyIf { task.onlyIf {
task.frameworks.size > 1 task.frameworks.size > 1
} }
@@ -197,7 +200,7 @@ internal constructor(
*/ */
@get:Internal // We take it into account as an input in the buildType and baseName properties. @get:Internal // We take it into account as an input in the buildType and baseName properties.
protected val fatFrameworksDir: File protected val fatFrameworksDir: File
get() = fatFrameworkDir(projectBuildDir, xcFrameworkName.get(), buildType) get() = fatFrameworkDir(projectLayout.buildDirectory, xcFrameworkName.get(), buildType).getFile()
@get:OutputDirectory @get:OutputDirectory
protected val outputXCFrameworkFile: File protected val outputXCFrameworkFile: File
@@ -263,10 +266,10 @@ internal constructor(
else -> null else -> null
} }
} }
createXCFramework(frameworksForXCFramework, outputXCFrameworkFile, buildType) createXCFramework(frameworksForXCFramework, outputXCFrameworkFile)
} }
private fun createXCFramework(frameworkFiles: List<FrameworkDescriptor>, output: File, buildType: NativeBuildType) { private fun createXCFramework(frameworkFiles: List<FrameworkDescriptor>, output: File) {
if (output.exists()) output.deleteRecursively() if (output.exists()) output.deleteRecursively()
val cmdArgs = mutableListOf("xcodebuild", "-create-xcframework") val cmdArgs = mutableListOf("xcodebuild", "-create-xcframework")
@@ -292,20 +295,20 @@ internal constructor(
xcFrameworkName: String, xcFrameworkName: String,
buildType: NativeBuildType, buildType: NativeBuildType,
appleTarget: AppleTarget? = null appleTarget: AppleTarget? = null
) = fatFrameworkDir(project.buildDir, xcFrameworkName, buildType, appleTarget) ): Provider<Directory> = fatFrameworkDir(project.layout.buildDirectory, xcFrameworkName, buildType, appleTarget)
fun fatFrameworkDir( fun fatFrameworkDir(
buildDir: File, buildDir: DirectoryProperty,
xcFrameworkName: String, xcFrameworkName: String,
buildType: NativeBuildType, buildType: NativeBuildType,
appleTarget: AppleTarget? = null appleTarget: AppleTarget? = null
) = buildDir ): Provider<Directory> = buildDir.map {
.resolve(xcFrameworkName.asValidFrameworkName() + "XCFrameworkTemp") it.dir(xcFrameworkName.asValidFrameworkName() + "XCFrameworkTemp")
.resolve("fatframework") .dir("fatframework")
.resolve(buildType.getName()) .dir(buildType.getName())
.resolveIfNotNull(appleTarget?.targetName) .dirIfNotNull(appleTarget?.targetName)
}
private fun Directory.dirIfNotNull(relative: String?): Directory = if (relative == null) this else this.dir(relative)
private fun File.resolveIfNotNull(relative: String?): File = if (relative == null) this else this.resolve(relative)
} }
} }
@@ -209,7 +209,7 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
val fatFrameworkTask = project.registerTask<FatFrameworkTask>("fatFramework") { task -> val fatFrameworkTask = project.registerTask<FatFrameworkTask>("fatFramework") { task ->
task.group = TASK_GROUP task.group = TASK_GROUP
task.description = "Creates a fat framework for requested architectures" task.description = "Creates a fat framework for requested architectures"
task.destinationDir = project.layout.cocoapodsBuildDirs.fatFramework(requestedBuildType).getFile() task.destinationDirProperty.set(project.layout.cocoapodsBuildDirs.fatFramework(requestedBuildType))
fatTargets.forEach { (_, targets) -> fatTargets.forEach { (_, targets) ->
targets.singleOrNull()?.let { targets.singleOrNull()?.let {
@@ -767,8 +767,9 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
lowerCamelCaseName(POD_FRAMEWORK_PREFIX, buildType.getName(), appleTarget.targetName, "FatFramework") lowerCamelCaseName(POD_FRAMEWORK_PREFIX, buildType.getName(), appleTarget.targetName, "FatFramework")
val fatFrameworkTask = locateOrRegisterTask<FatFrameworkTask>(fatFrameworkTaskName) { fatTask -> val fatFrameworkTask = locateOrRegisterTask<FatFrameworkTask>(fatFrameworkTaskName) { fatTask ->
fatTask.baseName = framework.baseName fatTask.baseName = framework.baseName
fatTask.destinationDir = fatTask.destinationDirProperty.set(
XCFrameworkTask.fatFrameworkDir(this, fatTask.fatFrameworkName, buildType, appleTarget) XCFrameworkTask.fatFrameworkDir(this, fatTask.fatFrameworkName, buildType, appleTarget)
)
fatTask.onlyIf { fatTask.onlyIf {
fatTask.frameworks.size > 1 fatTask.frameworks.size > 1
} }
@@ -112,7 +112,7 @@ private fun Project.createFatFramework(groupDescription: FrameworkGroupDescripti
} else { } else {
tasks.register(fatFrameworkTaskName, FatFrameworkTask::class.java) { tasks.register(fatFrameworkTaskName, FatFrameworkTask::class.java) {
it.baseName = groupDescription.baseName it.baseName = groupDescription.baseName
it.destinationDir = it.destinationDir.resolve(groupDescription.buildType.name.toLowerCaseAsciiOnly()) it.destinationDirProperty.set(it.destinationDirProperty.dir(groupDescription.buildType.name.toLowerCaseAsciiOnly()))
} }
} }
@@ -7,8 +7,10 @@
package org.jetbrains.kotlin.gradle.tasks package org.jetbrains.kotlin.gradle.tasks
import org.gradle.api.DefaultTask import org.gradle.api.DefaultTask
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.FileSystemOperations import org.gradle.api.file.FileSystemOperations
import org.gradle.api.file.FileTree import org.gradle.api.file.FileTree
import org.gradle.api.file.ProjectLayout
import org.gradle.api.model.ObjectFactory import org.gradle.api.model.ObjectFactory
import org.gradle.api.tasks.* import org.gradle.api.tasks.*
import org.gradle.process.ExecOperations import org.gradle.process.ExecOperations
@@ -18,6 +20,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.Framework
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeOutputKind import org.jetbrains.kotlin.gradle.plugin.mpp.NativeOutputKind
import org.jetbrains.kotlin.gradle.utils.appendLine import org.jetbrains.kotlin.gradle.utils.appendLine
import org.jetbrains.kotlin.gradle.utils.getFile
import org.jetbrains.kotlin.konan.target.Architecture import org.jetbrains.kotlin.konan.target.Architecture
import org.jetbrains.kotlin.konan.target.Family import org.jetbrains.kotlin.konan.target.Family
import org.jetbrains.kotlin.konan.target.HostManager import org.jetbrains.kotlin.konan.target.HostManager
@@ -123,6 +126,7 @@ internal constructor(
private val execOperations: ExecOperations, private val execOperations: ExecOperations,
private val fileOperations: FileSystemOperations, private val fileOperations: FileSystemOperations,
private val objectFactory: ObjectFactory, private val objectFactory: ObjectFactory,
projectLayout: ProjectLayout,
) : DefaultTask() { ) : DefaultTask() {
init { init {
onlyIf { HostManager.hostIsMac } onlyIf { HostManager.hostIsMac }
@@ -144,11 +148,19 @@ internal constructor(
@Input @Input
var baseName: String = project.name var baseName: String = project.name
@OutputDirectory
val destinationDirProperty: DirectoryProperty = objectFactory
.directoryProperty()
.convention(projectLayout.buildDirectory.dir("fat-framework"))
/** /**
* A parent directory for the fat framework. * A parent directory for the fat framework.
*/ */
@OutputDirectory @get:Internal
var destinationDir: File = project.buildDir.resolve("fat-framework") @Deprecated("please use destinationDirProperty", replaceWith = ReplaceWith("destinationDirProperty"))
var destinationDir: File
get() = destinationDirProperty.get().asFile
set(value) = destinationDirProperty.set(value)
@get:Internal @get:Internal
val fatFrameworkName: String val fatFrameworkName: String
@@ -156,7 +168,7 @@ internal constructor(
@get:Internal @get:Internal
val fatFramework: File val fatFramework: File
get() = destinationDir.resolve(fatFrameworkName + ".framework") get() = destinationDirProperty.file(fatFrameworkName + ".framework").getFile()
@get:PathSensitive(PathSensitivity.ABSOLUTE) @get:PathSensitive(PathSensitivity.ABSOLUTE)
@get:IgnoreEmptyDirectories @get:IgnoreEmptyDirectories
@@ -91,7 +91,7 @@ class KotlinNativeFatFrameworkImpl(
lowerCamelCaseName("assemble", artifactName, buildType.visibleName, "FatFramework") lowerCamelCaseName("assemble", artifactName, buildType.visibleName, "FatFramework")
) { ) {
it.baseName = artifactName it.baseName = artifactName
it.destinationDir = project.buildDir.resolve("$outDir/${buildType.getName()}") it.destinationDirProperty.set(project.layout.buildDirectory.dir("$outDir/${buildType.getName()}"))
} }
parentTask.dependsOn(fatTask) parentTask.dependsOn(fatTask)