[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 ->
task.description = "Packs $frameworkBuildType fat framework for Xcode"
task.baseName = framework.baseName
task.destinationDir = appleFrameworkDir(envFrameworkSearchDir)
task.destinationDirProperty.convention(appleFrameworkDir(envFrameworkSearchDir))
task.isEnabled = frameworkBuildType == envBuildType
}.also {
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.Project
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.provider.Provider
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.tasks.*
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.konan.target.HostManager
import org.jetbrains.kotlin.konan.target.KonanTarget
@@ -139,7 +142,7 @@ private fun Project.registerAssembleFatForXCFrameworkTask(
)
return registerTask(taskName) { task ->
task.destinationDir = XCFrameworkTask.fatFrameworkDir(project, xcFrameworkName, buildType, appleTarget)
task.destinationDirProperty.set(XCFrameworkTask.fatFrameworkDir(project, xcFrameworkName, buildType, appleTarget))
task.onlyIf {
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.
protected val fatFrameworksDir: File
get() = fatFrameworkDir(projectBuildDir, xcFrameworkName.get(), buildType)
get() = fatFrameworkDir(projectLayout.buildDirectory, xcFrameworkName.get(), buildType).getFile()
@get:OutputDirectory
protected val outputXCFrameworkFile: File
@@ -263,10 +266,10 @@ internal constructor(
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()
val cmdArgs = mutableListOf("xcodebuild", "-create-xcframework")
@@ -292,20 +295,20 @@ internal constructor(
xcFrameworkName: String,
buildType: NativeBuildType,
appleTarget: AppleTarget? = null
) = fatFrameworkDir(project.buildDir, xcFrameworkName, buildType, appleTarget)
): Provider<Directory> = fatFrameworkDir(project.layout.buildDirectory, xcFrameworkName, buildType, appleTarget)
fun fatFrameworkDir(
buildDir: File,
buildDir: DirectoryProperty,
xcFrameworkName: String,
buildType: NativeBuildType,
appleTarget: AppleTarget? = null
) = buildDir
.resolve(xcFrameworkName.asValidFrameworkName() + "XCFrameworkTemp")
.resolve("fatframework")
.resolve(buildType.getName())
.resolveIfNotNull(appleTarget?.targetName)
): Provider<Directory> = buildDir.map {
it.dir(xcFrameworkName.asValidFrameworkName() + "XCFrameworkTemp")
.dir("fatframework")
.dir(buildType.getName())
.dirIfNotNull(appleTarget?.targetName)
}
private fun File.resolveIfNotNull(relative: String?): File = if (relative == null) this else this.resolve(relative)
private fun Directory.dirIfNotNull(relative: String?): Directory = if (relative == null) this else this.dir(relative)
}
}
@@ -209,7 +209,7 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
val fatFrameworkTask = project.registerTask<FatFrameworkTask>("fatFramework") { task ->
task.group = TASK_GROUP
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) ->
targets.singleOrNull()?.let {
@@ -767,8 +767,9 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
lowerCamelCaseName(POD_FRAMEWORK_PREFIX, buildType.getName(), appleTarget.targetName, "FatFramework")
val fatFrameworkTask = locateOrRegisterTask<FatFrameworkTask>(fatFrameworkTaskName) { fatTask ->
fatTask.baseName = framework.baseName
fatTask.destinationDir =
fatTask.destinationDirProperty.set(
XCFrameworkTask.fatFrameworkDir(this, fatTask.fatFrameworkName, buildType, appleTarget)
)
fatTask.onlyIf {
fatTask.frameworks.size > 1
}
@@ -112,7 +112,7 @@ private fun Project.createFatFramework(groupDescription: FrameworkGroupDescripti
} else {
tasks.register(fatFrameworkTaskName, FatFrameworkTask::class.java) {
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
import org.gradle.api.DefaultTask
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.FileSystemOperations
import org.gradle.api.file.FileTree
import org.gradle.api.file.ProjectLayout
import org.gradle.api.model.ObjectFactory
import org.gradle.api.tasks.*
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.NativeOutputKind
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.Family
import org.jetbrains.kotlin.konan.target.HostManager
@@ -123,6 +126,7 @@ internal constructor(
private val execOperations: ExecOperations,
private val fileOperations: FileSystemOperations,
private val objectFactory: ObjectFactory,
projectLayout: ProjectLayout,
) : DefaultTask() {
init {
onlyIf { HostManager.hostIsMac }
@@ -144,11 +148,19 @@ internal constructor(
@Input
var baseName: String = project.name
@OutputDirectory
val destinationDirProperty: DirectoryProperty = objectFactory
.directoryProperty()
.convention(projectLayout.buildDirectory.dir("fat-framework"))
/**
* A parent directory for the fat framework.
*/
@OutputDirectory
var destinationDir: File = project.buildDir.resolve("fat-framework")
@get:Internal
@Deprecated("please use destinationDirProperty", replaceWith = ReplaceWith("destinationDirProperty"))
var destinationDir: File
get() = destinationDirProperty.get().asFile
set(value) = destinationDirProperty.set(value)
@get:Internal
val fatFrameworkName: String
@@ -156,7 +168,7 @@ internal constructor(
@get:Internal
val fatFramework: File
get() = destinationDir.resolve(fatFrameworkName + ".framework")
get() = destinationDirProperty.file(fatFrameworkName + ".framework").getFile()
@get:PathSensitive(PathSensitivity.ABSOLUTE)
@get:IgnoreEmptyDirectories
@@ -91,7 +91,7 @@ class KotlinNativeFatFrameworkImpl(
lowerCamelCaseName("assemble", artifactName, buildType.visibleName, "FatFramework")
) {
it.baseName = artifactName
it.destinationDir = project.buildDir.resolve("$outDir/${buildType.getName()}")
it.destinationDirProperty.set(project.layout.buildDirectory.dir("$outDir/${buildType.getName()}"))
}
parentTask.dependsOn(fatTask)