Skip to content

Commit 8a34d1f

Browse files
daugeldaugeSpace Team
authored and
Space Team
committed
Separate podgen & podinstall tasks
^KT-54161 Verification Pending
1 parent f144f8b commit 8a34d1f

File tree

6 files changed

+254
-247
lines changed

6 files changed

+254
-247
lines changed

libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/CocoaPodsIT.kt

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ class CocoaPodsIT : BaseGradleIT() {
7070
private val defaultPodRepo = "https://github.com/AFNetworking/AFNetworking"
7171
private val defaultPodName = "AFNetworking"
7272
private val defaultTarget = "IOS"
73-
private val defaultFamily = "IOS"
73+
private val defaultFamily = "ios"
7474
private val defaultSDK = "iphonesimulator"
7575
private val defaultPodGenTaskName = podGenFullTaskName()
76+
private val defaultPodInstallSyntheticTaskName = ":podInstallSyntheticIos"
7677
private val defaultBuildTaskName = podBuildFullTaskName()
7778
private val defaultSetupBuildTaskName = podSetupBuildFullTaskName()
7879
private val defaultCinteropTaskName = cinteropTaskName + defaultPodName + defaultTarget
@@ -245,7 +246,7 @@ class CocoaPodsIT : BaseGradleIT() {
245246
}
246247

247248
@Test
248-
fun testSyntheticProjectPodspecGeneration() {
249+
fun testSyntheticProjectPodfileGeneration() {
249250
val gradleProject = transformProjectWithPluginsDsl(cocoapodsSingleKtPod, gradleVersion)
250251
gradleProject.gradleBuildScript().appendToCocoapodsBlock("""
251252
ios.deploymentTarget = "14.1"
@@ -257,9 +258,11 @@ class CocoaPodsIT : BaseGradleIT() {
257258
}
258259
}
259260
""".trimIndent())
260-
gradleProject.build("podGenIOS", "-Pkotlin.native.cocoapods.generate.wrapper=true") {
261+
gradleProject.build("podInstallSyntheticIos", "-Pkotlin.native.cocoapods.generate.wrapper=true") {
261262
assertSuccessful()
262-
val podfileText = gradleProject.projectDir.resolve("build/cocoapods/synthetic/IOS/Podfile").readText().trim()
263+
assertTasksExecuted(":podGenIos")
264+
265+
val podfileText = gradleProject.projectDir.resolve("build/cocoapods/synthetic/ios/Podfile").readText().trim()
263266
assertTrue(podfileText.contains("platform :ios, '14.1'"))
264267
assertTrue(podfileText.contains("pod 'SSZipArchive'"))
265268
assertTrue(podfileText.contains("pod 'AFNetworking', '~> 4.0.1'"))
@@ -270,6 +273,27 @@ class CocoaPodsIT : BaseGradleIT() {
270273
}
271274
}
272275

276+
@Test
277+
fun testSyntheticProjectPodfilePostprocessing() {
278+
project.gradleBuildScript().apply {
279+
appendToCocoapodsBlock("""pod("AWSMobileClient", version = "2.29.1")""")
280+
281+
appendText("""
282+
283+
tasks.withType<org.jetbrains.kotlin.gradle.targets.native.tasks.PodGenTask>().configureEach {
284+
doLast {
285+
podfile.get().appendText("ENV['SWIFT_VERSION'] = '5'")
286+
}
287+
}
288+
""".trimIndent())
289+
}
290+
291+
project.build("podInstallSyntheticIos", "-Pkotlin.native.cocoapods.generate.wrapper=true") {
292+
assertSuccessful()
293+
assertFileContains(path = "build/cocoapods/synthetic/ios/Podfile", "ENV['SWIFT_VERSION'] = '5'")
294+
}
295+
}
296+
273297
@Test
274298
fun testPodDownloadGitNoTagNorCommit() {
275299
doTestGit()
@@ -378,9 +402,10 @@ class CocoaPodsIT : BaseGradleIT() {
378402
val tasks = listOf(
379403
podspecTaskName,
380404
defaultPodGenTaskName,
405+
defaultPodInstallSyntheticTaskName,
381406
defaultSetupBuildTaskName,
382407
defaultBuildTaskName,
383-
defaultCinteropTaskName
408+
defaultCinteropTaskName,
384409
)
385410
with(project.gradleBuildScript()) {
386411
addPod(defaultPodName, produceGitBlock(defaultPodRepo))
@@ -416,21 +441,21 @@ class CocoaPodsIT : BaseGradleIT() {
416441
}
417442

418443
@Test
419-
fun testPodGenInvalidatesUTD() {
444+
fun testPodInstallInvalidatesUTD() {
420445
with(project.gradleBuildScript()) {
421446
addPod("AFNetworking")
422447
}
423448

424449
hooks.addHook {
425-
assertTasksExecuted(defaultPodGenTaskName)
426-
assertTrue { fileInWorkingDir("build/cocoapods/synthetic/IOS/Pods/AFNetworking").deleteRecursively() }
450+
assertTasksExecuted(defaultPodInstallSyntheticTaskName)
451+
assertTrue { fileInWorkingDir("build/cocoapods/synthetic/ios/Pods/AFNetworking").deleteRecursively() }
427452
}
428-
project.testSynthetic(defaultPodGenTaskName)
453+
project.testSynthetic(defaultPodInstallSyntheticTaskName)
429454

430455
hooks.rewriteHooks {
431-
assertTasksExecuted(defaultPodGenTaskName)
456+
assertTasksExecuted(defaultPodInstallSyntheticTaskName)
432457
}
433-
project.testSynthetic(defaultPodGenTaskName)
458+
project.testSynthetic(defaultPodInstallSyntheticTaskName)
434459
}
435460

436461
@Test
@@ -499,7 +524,7 @@ class CocoaPodsIT : BaseGradleIT() {
499524

500525
val anotherTarget = "MacosX64"
501526
val anotherSdk = "macosx"
502-
val anotherFamily = "OSX"
527+
val anotherFamily = "macos"
503528
with(project.gradleBuildScript()) {
504529
appendToKotlinBlock(anotherTarget.replaceFirstChar { it.lowercase(Locale.getDefault()) } + "()")
505530
}

libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/cocoapods/CocoapodsExtension.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,17 @@ import org.gradle.api.Action
1010
import org.gradle.api.Named
1111
import org.gradle.api.NamedDomainObjectSet
1212
import org.gradle.api.Project
13-
import org.gradle.api.provider.Provider
1413
import org.gradle.api.tasks.*
1514
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
1615
import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension.CocoapodsDependency.PodLocation.*
1716
import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin.Companion.POD_FRAMEWORK_PREFIX
1817
import org.jetbrains.kotlin.gradle.plugin.mpp.Framework
19-
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBinary
2018
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
21-
import org.jetbrains.kotlin.gradle.tasks.addArg
22-
import org.jetbrains.kotlin.gradle.tasks.addArgs
23-
import org.jetbrains.kotlin.gradle.utils.relativeToRoot
24-
import org.jetbrains.kotlin.konan.target.HostManager
2519
import java.io.File
2620
import java.net.URI
2721
import javax.inject.Inject
2822

23+
@Suppress("unused") // Public API
2924
abstract class CocoapodsExtension @Inject constructor(private val project: Project) {
3025
/**
3126
* Configure version of the pod

libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/cocoapods/KotlinCocoapodsPlugin.kt

Lines changed: 53 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ internal class CocoapodsBuildDirs(val project: Project) {
6262
val synthetic: File
6363
get() = root.resolve("synthetic")
6464

65-
fun synthetic(family: Family) = synthetic.resolve(family.name)
65+
fun synthetic(family: Family) = synthetic.resolve(family.platformLiteral)
6666

6767
val publish: File = root.resolve("publish")
6868

@@ -72,11 +72,20 @@ internal class CocoapodsBuildDirs(val project: Project) {
7272

7373
internal fun String.asValidFrameworkName() = replace('-', '_')
7474

75+
internal val Family.platformLiteral: String
76+
get() = when (this) {
77+
Family.OSX -> "macos"
78+
Family.IOS -> "ios"
79+
Family.TVOS -> "tvos"
80+
Family.WATCHOS -> "watchos"
81+
else -> throw IllegalArgumentException("Bad family ${this.name}")
82+
}
83+
7584
private val Family.toPodGenTaskName: String
76-
get() = lowerCamelCaseName(
77-
KotlinCocoapodsPlugin.POD_GEN_TASK_NAME,
78-
name
79-
)
85+
get() = lowerCamelCaseName(KotlinCocoapodsPlugin.POD_GEN_TASK_NAME, platformLiteral)
86+
87+
private val Family.toPodInstallSyntheticTaskName: String
88+
get() = lowerCamelCaseName(KotlinCocoapodsPlugin.POD_INSTALL_TASK_NAME, "synthetic", platformLiteral)
8089

8190
private fun String.toSetupBuildTaskName(pod: CocoapodsDependency): String = lowerCamelCaseName(
8291
KotlinCocoapodsPlugin.POD_SETUP_BUILD_TASK_NAME,
@@ -451,23 +460,25 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
451460
project: Project,
452461
cocoapodsExtension: CocoapodsExtension
453462
) {
454-
val podspecTaskProvider = project.tasks.named(POD_SPEC_TASK_NAME, PodspecTask::class.java)
455-
project.tasks.register(POD_INSTALL_TASK_NAME, PodInstallTask::class.java) {
456-
it.group = TASK_GROUP
457-
it.description = "Invokes `pod install` call within Podfile location directory"
458-
it.podfile.set(cocoapodsExtension.podfile)
459-
it.podspec.set(podspecTaskProvider.map { podspecTask -> podspecTask.outputFile })
460-
it.frameworkName = cocoapodsExtension.podFrameworkName
461-
it.dependsOn(podspecTaskProvider)
463+
val podspecTaskProvider = project.tasks.named<PodspecTask>(POD_SPEC_TASK_NAME)
464+
project.registerTask<PodInstallTask>(POD_INSTALL_TASK_NAME) { task ->
465+
task.group = TASK_GROUP
466+
task.description = "Invokes `pod install` call within Podfile location directory"
467+
task.podfile.set(project.provider { cocoapodsExtension.podfile })
468+
task.podspec.set(podspecTaskProvider.map { it.outputFile })
469+
task.frameworkName.set(cocoapodsExtension.podFrameworkName)
470+
task.specRepos.set(project.provider { cocoapodsExtension.specRepos })
471+
task.pods.set(cocoapodsExtension.pods)
472+
task.dependsOn(podspecTaskProvider)
462473
}
463474
}
464475

465-
private fun registerPodGenTask(
476+
private fun registerSyntheticPodTasks(
466477
project: Project, kotlinExtension: KotlinMultiplatformExtension, cocoapodsExtension: CocoapodsExtension
467478
) {
468479
val families = mutableSetOf<Family>()
469480

470-
val podspecTaskProvider = project.tasks.named(POD_SPEC_TASK_NAME, PodspecTask::class.java)
481+
val podspecTaskProvider = project.tasks.named<PodspecTask>(POD_SPEC_TASK_NAME)
471482
kotlinExtension.supportedTargets().all { target ->
472483
val family = target.konanTarget.family
473484
if (family in families) {
@@ -483,15 +494,23 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
483494
else -> error("Unknown cocoapods platform: $family")
484495
}
485496

486-
project.tasks.register(family.toPodGenTaskName, PodGenTask::class.java) {
487-
it.description = "Сreates a synthetic Xcode project to retrieve CocoaPods dependencies"
488-
it.podspec = podspecTaskProvider.map { task -> task.outputFile }
489-
it.podName = project.provider { cocoapodsExtension.name }
490-
it.useLibraries = project.provider { cocoapodsExtension.useLibraries }
491-
it.specRepos = project.provider { cocoapodsExtension.specRepos }
492-
it.family = family
493-
it.platformSettings = platformSettings
494-
it.pods.set(cocoapodsExtension.pods)
497+
val podGenTask = project.registerTask<PodGenTask>(family.toPodGenTaskName) { task ->
498+
task.description = "Сreates a synthetic Xcode project to retrieve CocoaPods dependencies"
499+
task.podspec = podspecTaskProvider.map { it.outputFile }
500+
task.podName = project.provider { cocoapodsExtension.name }
501+
task.useLibraries = project.provider { cocoapodsExtension.useLibraries }
502+
task.specRepos = project.provider { cocoapodsExtension.specRepos }
503+
task.family = family
504+
task.platformSettings = platformSettings
505+
task.pods.set(cocoapodsExtension.pods)
506+
}
507+
508+
project.registerTask<PodInstallSyntheticTask>(family.toPodInstallSyntheticTaskName) { task ->
509+
task.description = "Invokes `pod install` for synthetic project"
510+
task.podfile.set(podGenTask.map { it.podfile.get() })
511+
task.family.set(family)
512+
task.podName.set(cocoapodsExtension.name)
513+
task.dependsOn(podGenTask)
495514
}
496515
}
497516
}
@@ -520,15 +539,15 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
520539
}
521540
sdks += sdk
522541

523-
val podGenTaskProvider = project.tasks.named(target.konanTarget.family.toPodGenTaskName, PodGenTask::class.java)
524-
project.tasks.register(sdk.toSetupBuildTaskName(pod), PodSetupBuildTask::class.java) {
525-
it.group = TASK_GROUP
526-
it.description = "Collect environment variables from .xcworkspace file"
527-
it.pod = project.provider { pod }
528-
it.sdk = project.provider { sdk }
529-
it.podsXcodeProjDir = podGenTaskProvider.map { podGen -> podGen.podsXcodeProjDir.get() }
530-
it.frameworkName = cocoapodsExtension.podFrameworkName
531-
it.dependsOn(podGenTaskProvider)
542+
val podInstallTask = project.tasks.named<PodInstallSyntheticTask>(target.konanTarget.family.toPodInstallSyntheticTaskName)
543+
project.registerTask<PodSetupBuildTask>(sdk.toSetupBuildTaskName(pod)) { task ->
544+
task.group = TASK_GROUP
545+
task.description = "Collect environment variables from .xcworkspace file"
546+
task.pod = project.provider { pod }
547+
task.sdk = project.provider { sdk }
548+
task.podsXcodeProjDir = podInstallTask.map { it.podsXcodeProjDirProvider.get() }
549+
task.frameworkName = cocoapodsExtension.podFrameworkName
550+
task.dependsOn(podInstallTask)
532551
}
533552
}
534553
}
@@ -772,7 +791,7 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
772791
injectPodspecExtensionToArtifacts(project, kotlinArtifactsExtension, cocoapodsExtension)
773792
registerPodspecTask(project, cocoapodsExtension)
774793

775-
registerPodGenTask(project, kotlinExtension, cocoapodsExtension)
794+
registerSyntheticPodTasks(project, kotlinExtension, cocoapodsExtension)
776795
registerPodInstallTask(project, cocoapodsExtension)
777796
registerPodSetupBuildTasks(project, kotlinExtension, cocoapodsExtension)
778797
registerPodBuildTasks(project, kotlinExtension, cocoapodsExtension)

libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/cocoapods/missingPodfileInfoUtils.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
package org.jetbrains.kotlin.gradle.targets.native.cocoapods
77

8-
import org.gradle.api.Project
98
import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension.CocoapodsDependency
109
import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension.SpecRepos
1110

@@ -20,8 +19,7 @@ class MissingSpecReposMessage(override val missingInfo: SpecRepos) : MissingInfo
2019
}
2120

2221
class MissingCocoapodsMessage(
23-
override val missingInfo: CocoapodsDependency,
24-
private val project: Project
22+
override val missingInfo: CocoapodsDependency
2523
) : MissingInfoMessage<CocoapodsDependency> {
2624
override val missingMessage: String
2725
get() = "pod '${missingInfo.name}'${missingInfo.source?.let { ", ${it.getPodSourcePath()}" }.orEmpty()}"

0 commit comments

Comments
 (0)