From 8b335ea05115f81907e34268eba00bed05f64fac Mon Sep 17 00:00:00 2001 From: Anton Lakotka Date: Fri, 1 Dec 2023 11:25:03 +0100 Subject: [PATCH] [Gradle] Add destinationDirProperty to FatFrameworkTask And use gradle's projectLayout.buildDirectory instead deprecated project.buildDir. ^KT-56904 --- .../plugin/mpp/apple/AppleXcodeTasks.kt | 2 +- .../plugin/mpp/apple/XCFrameworkTask.kt | 29 ++++++++++--------- .../native/cocoapods/KotlinCocoapodsPlugin.kt | 5 ++-- .../native/configureBinaryFrameworks.kt | 2 +- .../targets/native/tasks/FatFrameworkTask.kt | 18 ++++++++++-- .../artifact/KotlinNativeFatFramework.kt | 2 +- 6 files changed, 37 insertions(+), 21 deletions(-) diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/apple/AppleXcodeTasks.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/apple/AppleXcodeTasks.kt index 602b1c26e42..ff4dc3bb7e5 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/apple/AppleXcodeTasks.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/apple/AppleXcodeTasks.kt @@ -125,7 +125,7 @@ private fun Project.registerAssembleAppleFrameworkTask(framework: Framework): Ta needFatFramework -> locateOrRegisterTask(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) } diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/apple/XCFrameworkTask.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/apple/XCFrameworkTask.kt index d60dd371ad5..32c8af6d1f8 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/apple/XCFrameworkTask.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/apple/XCFrameworkTask.kt @@ -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, output: File, buildType: NativeBuildType) { + private fun createXCFramework(frameworkFiles: List, 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 = 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 = 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) } } \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/cocoapods/KotlinCocoapodsPlugin.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/cocoapods/KotlinCocoapodsPlugin.kt index d531e7177fd..8c5cc0e9a8a 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/cocoapods/KotlinCocoapodsPlugin.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/cocoapods/KotlinCocoapodsPlugin.kt @@ -209,7 +209,7 @@ open class KotlinCocoapodsPlugin : Plugin { val fatFrameworkTask = project.registerTask("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 { lowerCamelCaseName(POD_FRAMEWORK_PREFIX, buildType.getName(), appleTarget.targetName, "FatFramework") val fatFrameworkTask = locateOrRegisterTask(fatFrameworkTaskName) { fatTask -> fatTask.baseName = framework.baseName - fatTask.destinationDir = + fatTask.destinationDirProperty.set( XCFrameworkTask.fatFrameworkDir(this, fatTask.fatFrameworkName, buildType, appleTarget) + ) fatTask.onlyIf { fatTask.frameworks.size > 1 } diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/configureBinaryFrameworks.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/configureBinaryFrameworks.kt index 33569cc07be..bb76169d2dd 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/configureBinaryFrameworks.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/configureBinaryFrameworks.kt @@ -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())) } } diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/FatFrameworkTask.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/FatFrameworkTask.kt index 02cdc0abe8a..c9b92772a5c 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/FatFrameworkTask.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/FatFrameworkTask.kt @@ -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 diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/artifact/KotlinNativeFatFramework.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/artifact/KotlinNativeFatFramework.kt index db2de39dd5f..5458331a27c 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/artifact/KotlinNativeFatFramework.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/artifact/KotlinNativeFatFramework.kt @@ -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)