[KT-53340] Cocoapods: change default framework linking type to DYNAMIC.

This commit is contained in:
konstantin.tskhovrebov
2022-08-02 21:44:30 +02:00
committed by Space
parent c12318a62e
commit 9bec1a6358
3 changed files with 3 additions and 61 deletions
@@ -716,22 +716,6 @@ class CocoaPodsIT : BaseGradleIT() {
}
}
@Test
fun testWarningOfDefaultLinkingType() {
with(project) {
build("tasks") {
assertSuccessful()
assertContains("Cocoapods Gradle plugin uses default STATIC linking type for frameworks.")
}
gradleBuildScript().appendToCocoapodsBlock("framework { isStatic = true }")
build("tasks") {
assertSuccessful()
assertNotContains("Cocoapods Gradle plugin uses default STATIC linking type for frameworks.")
}
}
}
@Test
fun testSyncFramework() {
with(project) {
@@ -818,8 +802,9 @@ class CocoaPodsIT : BaseGradleIT() {
val framework = fileInWorkingDir("build/cocoapods/framework/$frameworkName.framework/$frameworkName")
with(runProcess(listOf("file", framework.absolutePath), projectDir)) {
assertTrue(isSuccessful)
assertTrue(output.contains("\\(for architecture armv7\\):\\s+current ar archive".toRegex()))
assertTrue(output.contains("\\(for architecture arm64\\):\\s+current ar archive".toRegex()))
assertTrue(output.contains("universal binary with 2 architectures"))
assertTrue(output.contains("(for architecture armv7)"))
assertTrue(output.contains("(for architecture arm64)"))
}
}
@@ -293,24 +293,10 @@ class Framework(
*/
fun embedBitcode(mode: String) = embedBitcode(org.jetbrains.kotlin.gradle.plugin.mpp.BitcodeEmbeddingMode.valueOf(mode.toUpperCase()))
internal var isStaticWasReassigned = false
//Hack: Cocoapods plugin overrides default value, but we want to track user-side reassigning
internal fun setIsStaticSilently(value: Boolean) {
val wasReassigned = isStaticWasReassigned
isStatic = value
isStaticWasReassigned = wasReassigned
}
/**
* Specifies if the framework is linked as a static library (false by default).
* Note: Cocoapods plugin links frameworks as a static library by default!
*/
var isStatic = false
set(value) {
isStaticWasReassigned = true
field = value
}
object BitcodeEmbeddingMode {
val DISABLE = org.jetbrains.kotlin.gradle.plugin.mpp.BitcodeEmbeddingMode.DISABLE
@@ -27,7 +27,6 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFrameworkTask
import org.jetbrains.kotlin.gradle.plugin.whenEvaluated
import org.jetbrains.kotlin.gradle.targets.native.tasks.*
import org.jetbrains.kotlin.gradle.tasks.*
import org.jetbrains.kotlin.gradle.utils.SingleWarningPerBuild
import org.jetbrains.kotlin.gradle.utils.asValidTaskName
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
import org.jetbrains.kotlin.konan.target.Family
@@ -153,7 +152,6 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
kotlinExtension.supportedTargets().all { target ->
target.binaries.framework(POD_FRAMEWORK_PREFIX) {
baseName = project.name.asValidFrameworkName()
setIsStaticSilently(true)
}
}
}
@@ -218,32 +216,6 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
project.createSyncFrameworkTask(frameworkLinkTask.flatMap { it.destinationDirectory.map { it.asFile } }, frameworkLinkTask)
}
private fun checkFrameworkLinkingType(
project: Project,
kotlinExtension: KotlinMultiplatformExtension
) = project.whenEvaluated {
val anyPodTarget = kotlinExtension.supportedTargets().firstOrNull() ?: return@whenEvaluated
val anyPodFramework = anyPodTarget.binaries.firstOrNull { binary ->
binary is Framework && binary.name.startsWith(POD_FRAMEWORK_PREFIX)
} as? Framework ?: return@whenEvaluated
val hasDefaultLinkingType = !anyPodFramework.isStaticWasReassigned
if (hasDefaultLinkingType) SingleWarningPerBuild.show(
project,
"""
|Cocoapods Gradle plugin uses default STATIC linking type for frameworks.
|Set it up explicitly because the default behavior will be changed to DYNAMIC linking in the 1.8 version.
|kotlin {
| cocoapods {
| framework {
| isStatic = true //or false
| }
| }
|}
|""".trimMargin()
)
}
private fun createSyncTask(
project: Project,
kotlinExtension: KotlinMultiplatformExtension,
@@ -718,7 +690,6 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
createDefaultFrameworks(kotlinExtension, cocoapodsExtension)
registerDummyFrameworkTask(project, cocoapodsExtension)
createSyncTask(project, kotlinExtension, cocoapodsExtension)
checkFrameworkLinkingType(project, kotlinExtension)
registerPodspecTask(project, cocoapodsExtension)
registerPodGenTask(project, kotlinExtension, cocoapodsExtension)