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 8be95f73ae6..bffcfb2bd40 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 @@ -29,6 +29,7 @@ import java.io.File import java.io.IOException import java.util.* import java.util.concurrent.TimeUnit +import kotlin.test.assertContentEquals import kotlin.test.assertEquals import kotlin.test.assertTrue import kotlin.test.fail @@ -235,6 +236,27 @@ class CocoaPodsIT : BaseGradleIT() { project.testImportWithAsserts(listOf(podRepo)) } + @Test + fun testSyntheticProjectPodspecGeneration() { + val gradleProject = transformProjectWithPluginsDsl(cocoapodsSingleKtPod, gradleVersion) + gradleProject.gradleBuildScript().appendToCocoapodsBlock(""" + pod("SSZipArchive") + pod("AFNetworking", "~> 4.0.1") + pod("Alamofire") { + source = git("https://github.com/Alamofire/Alamofire.git") { + tag = "5.6.1" + } + } + """.trimIndent()) + gradleProject.build("podGenIOS", "-Pkotlin.native.cocoapods.generate.wrapper=true") { + assertSuccessful() + val podfileText = gradleProject.projectDir.resolve("build/cocoapods/synthetic/IOS/Podfile").readText().trim() + assertTrue(podfileText.contains("pod 'SSZipArchive'")) + assertTrue(podfileText.contains("pod 'AFNetworking', '~> 4.0.1'")) + assertTrue(podfileText.contains("pod 'Alamofire', :git => '${gradleProject.projectDir.absolutePath}/build/cocoapods/externalSources/git/Alamofire', :tag => '5.6.1'")) + } + } + @Test fun testPodDownloadGitNoTagNorCommit() { doTestGit() diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/AdvancedCocoapodsTasks.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/AdvancedCocoapodsTasks.kt index 99346762591..873c792e4eb 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/AdvancedCocoapodsTasks.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/AdvancedCocoapodsTasks.kt @@ -478,17 +478,27 @@ open class PodGenTask : CocoapodsTask() { buildString { append("pod '${it.name}'") - val pathType = when (it.source) { - is Path -> "path" - is Url -> "path" - is Git -> "git" - else -> null - } + val version = it.version + val source = it.source - val path = it.source?.getLocalPath(project, it.name) + if (source != null) { + val path = source.getLocalPath(project, it.name) + when (source) { + is Path, is Url -> { + append(", :path => '$path'") + } - if (path != null && pathType != null) { - append(", :$pathType => '$path'") + is Git -> { + append(", :git => '$path'") + when { + source.branch != null -> append(", :branch => '${source.branch}'") + source.tag != null -> append(", :tag => '${source.tag}'") + source.commit != null -> append(", :commit => '${source.commit}'") + } + } + } + } else if (version != null) { + append(", '$version'") } }