[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")
@GradleTest
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.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<File>) {
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<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.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<Project> {
private fun Project.createCopyFrameworkTask(
frameworkFile: Provider<File>,
buildingTask: TaskProvider<*>
) = registerTask<FrameworkCopy>(SYNC_TASK_NAME) {
it.group = TASK_GROUP
it.description = "Copies a framework for given platform and build type into the CocoaPods build directory"
) = registerTask<FrameworkCopy>(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(