Added support of custom Xcode configurations to cocoapods plugin

#KT-42023
This commit is contained in:
Viacheslav Kormushkin
2021-05-20 15:18:12 +03:00
committed by TeamCityServer
parent a801eccf66
commit d10910e553
3 changed files with 40 additions and 8 deletions
@@ -781,6 +781,18 @@ class CocoaPodsIT : BaseGradleIT() {
} }
} }
@Test
fun testCustomXcodeConfiguration() {
with(project) {
gradleBuildScript().appendToCocoapodsBlock("xcodeConfigurationToNativeBuildType[\"CUSTOM\"] = org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType.DEBUG\n")
test(
"syncFramework",
"-Pkotlin.native.cocoapods.target=ios_x64",
"-Pkotlin.native.cocoapods.configuration=CUSTOM"
)
}
}
// paths // paths
private fun CompiledProject.url() = externalSources().resolve("url") private fun CompiledProject.url() = externalSources().resolve("url")
@@ -13,6 +13,7 @@ import org.gradle.api.Project
import org.gradle.api.tasks.* import org.gradle.api.tasks.*
import org.gradle.util.ConfigureUtil import org.gradle.util.ConfigureUtil
import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension.CocoapodsDependency.PodLocation.* import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension.CocoapodsDependency.PodLocation.*
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
import java.io.File import java.io.File
import java.net.URI import java.net.URI
@@ -102,6 +103,15 @@ open class CocoapodsExtension(private val project: Project) {
@Input @Input
var frameworkName: String = project.name.asValidFrameworkName() var frameworkName: String = project.name.asValidFrameworkName()
/**
* Configure custom Xcode Configurations to Native Build Types mapping
*/
@Input
val xcodeConfigurationToNativeBuildType: MutableMap<String, NativeBuildType> = mutableMapOf(
"Debug" to NativeBuildType.DEBUG,
"Release" to NativeBuildType.RELEASE
)
@get:Nested @get:Nested
internal val specRepos = SpecRepos() internal val specRepos = SpecRepos()
@@ -19,6 +19,7 @@ import org.jetbrains.kotlin.gradle.plugin.addExtension
import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension.CocoapodsDependency import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension.CocoapodsDependency
import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension.CocoapodsDependency.PodLocation.* import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension.CocoapodsDependency.PodLocation.*
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
import org.jetbrains.kotlin.gradle.plugin.whenEvaluated import org.jetbrains.kotlin.gradle.plugin.whenEvaluated
import org.jetbrains.kotlin.gradle.targets.native.tasks.* import org.jetbrains.kotlin.gradle.targets.native.tasks.*
import org.jetbrains.kotlin.gradle.tasks.* import org.jetbrains.kotlin.gradle.tasks.*
@@ -29,7 +30,6 @@ import org.jetbrains.kotlin.konan.target.HostManager
import org.jetbrains.kotlin.konan.target.KonanTarget import org.jetbrains.kotlin.konan.target.KonanTarget
import org.jetbrains.kotlin.konan.target.KonanTarget.* import org.jetbrains.kotlin.konan.target.KonanTarget.*
import java.io.File import java.io.File
import java.util.*
internal val Project.cocoapodsBuildDirs: CocoapodsBuildDirs internal val Project.cocoapodsBuildDirs: CocoapodsBuildDirs
get() = CocoapodsBuildDirs(this) get() = CocoapodsBuildDirs(this)
@@ -57,8 +57,8 @@ internal class CocoapodsBuildDirs(val project: Project) {
fun externalSources(fileName: String) = externalSources.resolve(fileName) fun externalSources(fileName: String) = externalSources.resolve(fileName)
fun fatFramework(buildType: String) = fun fatFramework(buildType: NativeBuildType) =
root.resolve("fat-frameworks/${buildType.toLowerCase()}") root.resolve("fat-frameworks/${buildType.toString().toLowerCase()}")
} }
internal fun String.asValidFrameworkName() = replace('-', '_') internal fun String.asValidFrameworkName() = replace('-', '_')
@@ -139,7 +139,7 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
private fun createSyncForFatFramework( private fun createSyncForFatFramework(
project: Project, project: Project,
kotlinExtension: KotlinMultiplatformExtension, kotlinExtension: KotlinMultiplatformExtension,
requestedBuildType: String, requestedBuildType: NativeBuildType,
requestedPlatforms: List<KonanTarget> requestedPlatforms: List<KonanTarget>
) { ) {
val fatTargets = requestedPlatforms.associate { it to kotlinExtension.targetsForPlatform(it) } val fatTargets = requestedPlatforms.associate { it to kotlinExtension.targetsForPlatform(it) }
@@ -172,7 +172,7 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
private fun createSyncForRegularFramework( private fun createSyncForRegularFramework(
project: Project, project: Project,
kotlinExtension: KotlinMultiplatformExtension, kotlinExtension: KotlinMultiplatformExtension,
requestedBuildType: String, requestedBuildType: NativeBuildType,
requestedPlatform: KonanTarget requestedPlatform: KonanTarget
) { ) {
val targets = kotlinExtension.targetsForPlatform(requestedPlatform) val targets = kotlinExtension.targetsForPlatform(requestedPlatform)
@@ -186,10 +186,20 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
private fun createSyncTask( private fun createSyncTask(
project: Project, project: Project,
kotlinExtension: KotlinMultiplatformExtension kotlinExtension: KotlinMultiplatformExtension,
cocoapodsExtension: CocoapodsExtension
) = project.whenEvaluated { ) = project.whenEvaluated {
val requestedTargetName = project.findProperty(TARGET_PROPERTY)?.toString() ?: return@whenEvaluated val requestedTargetName = project.findProperty(TARGET_PROPERTY)?.toString() ?: return@whenEvaluated
val requestedBuildType = project.findProperty(CONFIGURATION_PROPERTY)?.toString()?.toUpperCase() ?: return@whenEvaluated val xcodeConfiguration = project.findProperty(CONFIGURATION_PROPERTY)?.toString() ?: return@whenEvaluated
val requestedBuildType = cocoapodsExtension.xcodeConfigurationToNativeBuildType[xcodeConfiguration]
check(requestedBuildType != null) {
"""
Could not identify build type for Kotlin framework '${cocoapodsExtension.frameworkName}' built via cocoapods plugin with CONFIGURATION=$xcodeConfiguration.
Add xcodeConfigurationToNativeBuildType["$xcodeConfiguration"]=NativeBuildType.DEBUG or xcodeConfigurationToNativeBuildType["$xcodeConfiguration"]=NativeBuildType.RELEASE to cocoapods plugin configuration
""".trimIndent()
}
// We create a fat framework only for device platforms which have several // We create a fat framework only for device platforms which have several
// device architectures: iosArm64, iosArm32, watchosArm32 and watchosArm64. // device architectures: iosArm64, iosArm32, watchosArm32 and watchosArm64.
@@ -524,7 +534,7 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
kotlinExtension.addExtension(COCOAPODS_EXTENSION_NAME, cocoapodsExtension) kotlinExtension.addExtension(COCOAPODS_EXTENSION_NAME, cocoapodsExtension)
createDefaultFrameworks(kotlinExtension, cocoapodsExtension) createDefaultFrameworks(kotlinExtension, cocoapodsExtension)
registerDummyFrameworkTask(project, cocoapodsExtension) registerDummyFrameworkTask(project, cocoapodsExtension)
createSyncTask(project, kotlinExtension) createSyncTask(project, kotlinExtension, cocoapodsExtension)
registerPodspecTask(project, cocoapodsExtension) registerPodspecTask(project, cocoapodsExtension)
registerPodDownloadTask(project, cocoapodsExtension) registerPodDownloadTask(project, cocoapodsExtension)