From 62544ec9c816ec7165b15082c8bfa1366f56e898 Mon Sep 17 00:00:00 2001 From: Artem Daugel-Dauge Date: Wed, 4 Oct 2023 20:48:43 +0200 Subject: [PATCH] [Gradle] Don't copy DSYM in embedAndSign task ^KT-62232 Verification Pending --- .../kotlin/gradle/native/AppleFrameworkIT.kt | 26 +++++++++++++++++++ .../plugin/mpp/apple/AppleXcodeTasks.kt | 18 ++++++++----- .../native/cocoapods/KotlinCocoapodsPlugin.kt | 14 +++++----- 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/AppleFrameworkIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/AppleFrameworkIT.kt index f2e32ccbe57..70c9c9391e3 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/AppleFrameworkIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/AppleFrameworkIT.kt @@ -137,6 +137,32 @@ class AppleFrameworkIT : KGPBaseTest() { } } + @DisplayName("embedAndSign task does not copy dSYM to Xcode frameworks folder") + @OptIn(EnvironmentalVariablesOverride::class) + @GradleTest + fun testEmbedAnsSignDoesNotCopyDsym( + gradleVersion: GradleVersion, + ) { + + nativeProject( + "sharedAppleFramework", + gradleVersion, + ) { + val environmentVariables = mapOf( + "CONFIGURATION" to "debug", + "SDK_NAME" to "iphoneos", + "ARCHS" to "arm64", + "EXPANDED_CODE_SIGN_IDENTITY" to "-", + "TARGET_BUILD_DIR" to projectPath.absolutePathString(), + "FRAMEWORKS_FOLDER_PATH" to "build/xcode-derived" + ) + build(":shared:embedAndSignAppleFrameworkForXcode", environmentVariables = EnvironmentalVariables(environmentVariables)) { + assertDirectoryInProjectExists("build/xcode-derived/sdk.framework") + assertDirectoryInProjectDoesNotExist("build/xcode-derived/sdk.framework.DSYM") + } + } + } + @DisplayName("embedAndSignAppleFrameworkForXcode fail") @GradleTest fun shouldFailWithExecutingEmbedAndSignAppleFrameworkForXcode( 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 1c39cf02186..602b1c26e42 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 @@ -19,6 +19,7 @@ import org.jetbrains.kotlin.gradle.plugin.diagnostics.KotlinToolingDiagnostics import org.jetbrains.kotlin.gradle.plugin.diagnostics.reportDiagnostic import org.jetbrains.kotlin.gradle.plugin.mpp.Framework import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType +import org.jetbrains.kotlin.gradle.plugin.mpp.apple.FrameworkCopy.Companion.dsymFile import org.jetbrains.kotlin.gradle.plugin.mpp.enabledOnCurrentHost import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask import org.jetbrains.kotlin.gradle.tasks.locateOrRegisterTask @@ -133,6 +134,7 @@ private fun Project.registerAssembleAppleFrameworkTask(framework: Framework): Ta task.description = "Packs $frameworkBuildType ${frameworkTarget.name} framework for Xcode" task.isEnabled = frameworkBuildType == envBuildType task.sourceFramework.fileProvider(framework.linkTaskProvider.flatMap { it.outputFile }) + task.sourceDsym.fileProvider(dsymFile(task.sourceFramework.mapToFile())) task.dependsOn(framework.linkTaskProvider) task.destinationDirectory.set(appleFrameworkDir(envFrameworkSearchDir)) } @@ -223,7 +225,6 @@ private fun Project.appleFrameworkDir(frameworkSearchDir: File) = * See https://youtrack.jetbrains.com/issue/KT-48594. */ @DisableCachingByDefault -@Suppress("LeakingThis") // Should be extended only by Gradle internal abstract class FrameworkCopy : DefaultTask() { @get:Inject @@ -235,22 +236,23 @@ internal abstract class FrameworkCopy : DefaultTask() { @get:PathSensitive(PathSensitivity.ABSOLUTE) @get:InputFiles + @get:Optional @get:IgnoreEmptyDirectories - protected val sourceDsym = sourceFramework.mapToFile().map { File(it.path + ".dSYM") } + abstract val sourceDsym: DirectoryProperty @get:OutputDirectory abstract val destinationDirectory: DirectoryProperty @TaskAction open fun copy() { - copy(sourceFramework.mapToFile()) - if (sourceDsym.get().exists()) { + copy(sourceFramework) + if (sourceDsym.isPresent && sourceDsym.getFile().exists()) { copy(sourceDsym) } } - private fun copy(sourceProvider: Provider) { - val source = sourceProvider.get() + private fun copy(sourceProperty: DirectoryProperty) { + val source = sourceProperty.getFile() val destination = destinationDirectory.getFile() val destinationFile = File(destination, source.name) @@ -260,4 +262,8 @@ internal abstract class FrameworkCopy : DefaultTask() { execOperations.exec { it.commandLine("cp", "-R", source.absolutePath, destination.absolutePath) } } + + companion object { + fun dsymFile(framework: Provider): Provider = framework.map { File(it.path + ".dSYM") } + } } 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 9348159351c..31248076b60 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 @@ -32,6 +32,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.* import org.jetbrains.kotlin.gradle.plugin.mpp.apple.* import org.jetbrains.kotlin.gradle.plugin.mpp.apple.AppleSdk import org.jetbrains.kotlin.gradle.plugin.mpp.apple.AppleTarget +import org.jetbrains.kotlin.gradle.plugin.mpp.apple.FrameworkCopy.Companion.dsymFile import org.jetbrains.kotlin.gradle.plugin.whenEvaluated import org.jetbrains.kotlin.gradle.targets.native.cocoapods.CocoapodsPluginDiagnostics import org.jetbrains.kotlin.gradle.targets.native.cocoapods.KotlinArtifactsPodspecExtension @@ -177,13 +178,14 @@ open class KotlinCocoapodsPlugin : Plugin { private fun Project.createCopyFrameworkTask( frameworkFile: Provider, buildingTask: TaskProvider<*> - ) = registerTask(SYNC_TASK_NAME) { - it.group = TASK_GROUP - it.description = "Copies a framework for given platform and build type into the CocoaPods build directory" + ) = registerTask(SYNC_TASK_NAME) { task -> + task.group = TASK_GROUP + task.description = "Copies a framework for given platform and build type into the CocoaPods build directory" - it.sourceFramework.fileProvider(frameworkFile) - it.dependsOn(buildingTask) - it.destinationDirectory.set(layout.cocoapodsBuildDirs.framework) + task.sourceFramework.fileProvider(frameworkFile) + task.sourceDsym.fileProvider(dsymFile(frameworkFile)) + task.dependsOn(buildingTask) + task.destinationDirectory.set(layout.cocoapodsBuildDirs.framework) } private fun createSyncForFatFramework(