[Gradle] Don't copy DSYM in embedAndSign task

^KT-62232 Verification Pending
This commit is contained in:
Artem Daugel-Dauge
2023-10-04 20:48:43 +02:00
committed by Space Team
parent fa4de48d0e
commit 62544ec9c8
3 changed files with 46 additions and 12 deletions
@@ -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") @DisplayName("embedAndSignAppleFrameworkForXcode fail")
@GradleTest @GradleTest
fun shouldFailWithExecutingEmbedAndSignAppleFrameworkForXcode( fun shouldFailWithExecutingEmbedAndSignAppleFrameworkForXcode(
@@ -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.diagnostics.reportDiagnostic
import org.jetbrains.kotlin.gradle.plugin.mpp.Framework 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.plugin.mpp.apple.FrameworkCopy.Companion.dsymFile
import org.jetbrains.kotlin.gradle.plugin.mpp.enabledOnCurrentHost import org.jetbrains.kotlin.gradle.plugin.mpp.enabledOnCurrentHost
import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask
import org.jetbrains.kotlin.gradle.tasks.locateOrRegisterTask 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.description = "Packs $frameworkBuildType ${frameworkTarget.name} framework for Xcode"
task.isEnabled = frameworkBuildType == envBuildType task.isEnabled = frameworkBuildType == envBuildType
task.sourceFramework.fileProvider(framework.linkTaskProvider.flatMap { it.outputFile }) task.sourceFramework.fileProvider(framework.linkTaskProvider.flatMap { it.outputFile })
task.sourceDsym.fileProvider(dsymFile(task.sourceFramework.mapToFile()))
task.dependsOn(framework.linkTaskProvider) task.dependsOn(framework.linkTaskProvider)
task.destinationDirectory.set(appleFrameworkDir(envFrameworkSearchDir)) task.destinationDirectory.set(appleFrameworkDir(envFrameworkSearchDir))
} }
@@ -223,7 +225,6 @@ private fun Project.appleFrameworkDir(frameworkSearchDir: File) =
* See https://youtrack.jetbrains.com/issue/KT-48594. * See https://youtrack.jetbrains.com/issue/KT-48594.
*/ */
@DisableCachingByDefault @DisableCachingByDefault
@Suppress("LeakingThis") // Should be extended only by Gradle
internal abstract class FrameworkCopy : DefaultTask() { internal abstract class FrameworkCopy : DefaultTask() {
@get:Inject @get:Inject
@@ -235,22 +236,23 @@ internal abstract class FrameworkCopy : DefaultTask() {
@get:PathSensitive(PathSensitivity.ABSOLUTE) @get:PathSensitive(PathSensitivity.ABSOLUTE)
@get:InputFiles @get:InputFiles
@get:Optional
@get:IgnoreEmptyDirectories @get:IgnoreEmptyDirectories
protected val sourceDsym = sourceFramework.mapToFile().map { File(it.path + ".dSYM") } abstract val sourceDsym: DirectoryProperty
@get:OutputDirectory @get:OutputDirectory
abstract val destinationDirectory: DirectoryProperty abstract val destinationDirectory: DirectoryProperty
@TaskAction @TaskAction
open fun copy() { open fun copy() {
copy(sourceFramework.mapToFile()) copy(sourceFramework)
if (sourceDsym.get().exists()) { if (sourceDsym.isPresent && sourceDsym.getFile().exists()) {
copy(sourceDsym) copy(sourceDsym)
} }
} }
private fun copy(sourceProvider: Provider<File>) { private fun copy(sourceProperty: DirectoryProperty) {
val source = sourceProvider.get() val source = sourceProperty.getFile()
val destination = destinationDirectory.getFile() val destination = destinationDirectory.getFile()
val destinationFile = File(destination, source.name) 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) } execOperations.exec { it.commandLine("cp", "-R", source.absolutePath, destination.absolutePath) }
} }
companion object {
fun dsymFile(framework: Provider<File>): Provider<File> = framework.map { File(it.path + ".dSYM") }
}
} }
@@ -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.*
import org.jetbrains.kotlin.gradle.plugin.mpp.apple.AppleSdk 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.AppleTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.apple.FrameworkCopy.Companion.dsymFile
import org.jetbrains.kotlin.gradle.plugin.whenEvaluated import org.jetbrains.kotlin.gradle.plugin.whenEvaluated
import org.jetbrains.kotlin.gradle.targets.native.cocoapods.CocoapodsPluginDiagnostics import org.jetbrains.kotlin.gradle.targets.native.cocoapods.CocoapodsPluginDiagnostics
import org.jetbrains.kotlin.gradle.targets.native.cocoapods.KotlinArtifactsPodspecExtension import org.jetbrains.kotlin.gradle.targets.native.cocoapods.KotlinArtifactsPodspecExtension
@@ -177,13 +178,14 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
private fun Project.createCopyFrameworkTask( private fun Project.createCopyFrameworkTask(
frameworkFile: Provider<File>, frameworkFile: Provider<File>,
buildingTask: TaskProvider<*> buildingTask: TaskProvider<*>
) = registerTask<FrameworkCopy>(SYNC_TASK_NAME) { ) = registerTask<FrameworkCopy>(SYNC_TASK_NAME) { task ->
it.group = TASK_GROUP task.group = TASK_GROUP
it.description = "Copies a framework for given platform and build type into the CocoaPods build directory" task.description = "Copies a framework for given platform and build type into the CocoaPods build directory"
it.sourceFramework.fileProvider(frameworkFile) task.sourceFramework.fileProvider(frameworkFile)
it.dependsOn(buildingTask) task.sourceDsym.fileProvider(dsymFile(frameworkFile))
it.destinationDirectory.set(layout.cocoapodsBuildDirs.framework) task.dependsOn(buildingTask)
task.destinationDirectory.set(layout.cocoapodsBuildDirs.framework)
} }
private fun createSyncForFatFramework( private fun createSyncForFatFramework(