From c2a442578452392bb40164fd69054787e6fc1255 Mon Sep 17 00:00:00 2001 From: Viacheslav Kormushkin Date: Tue, 7 Dec 2021 13:35:10 +0300 Subject: [PATCH] [Gradle][Cocoapods] Fixed project sync issues when cocoapods are used along with manual framework creation #KT-50105 --- .../kotlin/gradle/native/CocoaPodsIT.kt | 3 +- .../native/cocoapods/KotlinCocoapodsPlugin.kt | 91 ++++++++++--------- 2 files changed, 48 insertions(+), 46 deletions(-) diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/CocoaPodsIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/CocoaPodsIT.kt index 179f2842c7d..b05176b53fd 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/CocoaPodsIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/CocoaPodsIT.kt @@ -942,7 +942,8 @@ class CocoaPodsIT : BaseGradleIT() { assertEquals(publishPodspecContent, actualPodspecContentWithoutBlankLines) } - + //test that manually created frameworks are not included into cocoapods xcframework + project.gradleBuildScript().appendToKotlinBlock("iosX64(\"iOS\") {binaries.framework{}}") project.testWithWrapper(":podPublishXCFramework") } diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/native/cocoapods/KotlinCocoapodsPlugin.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/native/cocoapods/KotlinCocoapodsPlugin.kt index 558274bb092..eb35b863d6c 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/native/cocoapods/KotlinCocoapodsPlugin.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/native/cocoapods/KotlinCocoapodsPlugin.kt @@ -66,7 +66,7 @@ internal class CocoapodsBuildDirs(val project: Project) { fun externalSources(fileName: String) = externalSources.resolve(fileName) fun fatFramework(buildType: NativeBuildType) = - root.resolve("fat-frameworks/${buildType.toString().toLowerCase()}") + root.resolve("fat-frameworks/${buildType.getName()}") } internal fun String.asValidFrameworkName() = replace('-', '_') @@ -241,7 +241,8 @@ open class KotlinCocoapodsPlugin : Plugin { kotlin.native.cocoapods.paths.frameworks kotlin.native.cocoapods.paths.headers are not supported and will be ignored since Cocoapods plugin generates all required properties automatically. - """.trimIndent()) + """.trimIndent() + ) } if (platforms == null || archs == null) { @@ -568,16 +569,17 @@ open class KotlinCocoapodsPlugin : Plugin { buildType: NativeBuildType ): TaskProvider = with(project) { - registerTask("podPublish${buildType.name.toLowerCase().capitalize()}XCFramework") { task -> + registerTask(lowerCamelCaseName(POD_FRAMEWORK_PREFIX, "publish", buildType.getName(), "XCFramework")) { task -> multiplatformExtension.supportedTargets().all { target -> - target.binaries.matching { it.buildType == buildType }.withType(Framework::class.java) { framework -> - task.from(framework) - } + target.binaries.matching { it.buildType == buildType && it.name.startsWith(POD_FRAMEWORK_PREFIX) } + .withType(Framework::class.java) { framework -> + task.from(framework) + } } task.outputDir = cocoapodsExtension.publishDir task.buildType = buildType task.baseName = project.provider { cocoapodsExtension.frameworkNameInternal } - task.description = "Produces ${buildType.name.toLowerCase().capitalize()} XCFramework for all requested targets" + task.description = "Produces ${buildType.getName().capitalize()} XCFramework for all requested targets" task.group = TASK_GROUP } } @@ -589,30 +591,31 @@ open class KotlinCocoapodsPlugin : Plugin { buildType: NativeBuildType ): TaskProvider = with(project) { - val task = tasks.register("podSpec${buildType.name.toLowerCase().capitalize()}", PodspecTask::class.java) { task -> - task.description = "Generates podspec for ${buildType.name.toLowerCase().capitalize()} XCFramework publishing" - task.outputDir.set(xcFrameworkTask.map { it.outputDir.resolve(it.buildType.getName()) }) - task.needPodspec = provider { true } - task.publishing.set(true) - task.pods.set(cocoapodsExtension.pods) - task.specName.set(cocoapodsExtension.name) - task.version.set(cocoapodsExtension.version ?: version.toString()) - task.extraSpecAttributes.set(cocoapodsExtension.extraSpecAttributes) - task.homepage.set(cocoapodsExtension.homepage) - task.license.set(cocoapodsExtension.license) - task.authors.set(cocoapodsExtension.authors) - task.summary.set(cocoapodsExtension.summary) - task.source.set(cocoapodsExtension.source) - task.frameworkName = provider { cocoapodsExtension.frameworkNameInternal } - task.ios = provider { cocoapodsExtension.ios } - task.osx = provider { cocoapodsExtension.osx } - task.tvos = provider { cocoapodsExtension.tvos } - task.watchos = provider { cocoapodsExtension.watchos } - val generateWrapper = project.findProperty(GENERATE_WRAPPER_PROPERTY)?.toString()?.toBoolean() ?: false - if (generateWrapper) { - task.dependsOn(":wrapper") + val task = + tasks.register(lowerCamelCaseName(POD_FRAMEWORK_PREFIX, "spec", buildType.getName()), PodspecTask::class.java) { task -> + task.description = "Generates podspec for ${buildType.getName().capitalize()} XCFramework publishing" + task.outputDir.set(xcFrameworkTask.map { it.outputDir.resolve(it.buildType.getName()) }) + task.needPodspec = provider { true } + task.publishing.set(true) + task.pods.set(cocoapodsExtension.pods) + task.specName.set(cocoapodsExtension.name) + task.version.set(cocoapodsExtension.version ?: version.toString()) + task.extraSpecAttributes.set(cocoapodsExtension.extraSpecAttributes) + task.homepage.set(cocoapodsExtension.homepage) + task.license.set(cocoapodsExtension.license) + task.authors.set(cocoapodsExtension.authors) + task.summary.set(cocoapodsExtension.summary) + task.source.set(cocoapodsExtension.source) + task.frameworkName = provider { cocoapodsExtension.frameworkNameInternal } + task.ios = provider { cocoapodsExtension.ios } + task.osx = provider { cocoapodsExtension.osx } + task.tvos = provider { cocoapodsExtension.tvos } + task.watchos = provider { cocoapodsExtension.watchos } + val generateWrapper = project.findProperty(GENERATE_WRAPPER_PROPERTY)?.toString()?.toBoolean() ?: false + if (generateWrapper) { + task.dependsOn(":wrapper") + } } - } xcFrameworkTask.dependsOn(task) return task } @@ -624,29 +627,27 @@ open class KotlinCocoapodsPlugin : Plugin { ) = with(project) { multiplatformExtension.supportedTargets().all { target -> - target.binaries.matching { it.buildType == buildType }.withType(Framework::class.java) { framework -> + target.binaries.matching { it.buildType == buildType && it.name.startsWith(POD_FRAMEWORK_PREFIX) } + .withType(Framework::class.java) { framework -> - val appleTarget = AppleTarget.values().firstOrNull { it.targets.contains(target.konanTarget) } ?: return@withType - val fatFrameworkTaskName = - "pod${buildType.name.toLowerCase().capitalize()}${appleTarget.targetName.capitalize()}FatFramework" - val fatFrameworkTask = if (fatFrameworkTaskName in tasks.names) { - tasks.named(fatFrameworkTaskName, FatFrameworkTask::class.java) - } else { - tasks.register(fatFrameworkTaskName, FatFrameworkTask::class.java) { fatTask -> + val appleTarget = AppleTarget.values().firstOrNull { it.targets.contains(target.konanTarget) } ?: return@withType + val fatFrameworkTaskName = + lowerCamelCaseName(POD_FRAMEWORK_PREFIX, buildType.getName(), appleTarget.targetName, "FatFramework") + val fatFrameworkTask = locateOrRegisterTask(fatFrameworkTaskName) { fatTask -> fatTask.baseName = framework.baseName - fatTask.destinationDir = XCFrameworkTask.fatFrameworkDir(this, fatTask.fatFrameworkName, buildType, appleTarget) + fatTask.destinationDir = + XCFrameworkTask.fatFrameworkDir(this, fatTask.fatFrameworkName, buildType, appleTarget) fatTask.onlyIf { fatTask.frameworks.size > 1 } } - } - fatFrameworkTask.configure { - it.from(framework) - } + fatFrameworkTask.configure { + it.from(framework) + } - xcFrameworkTask.dependsOn(fatFrameworkTask) - } + xcFrameworkTask.dependsOn(fatFrameworkTask) + } } }