[KT-53337] Cocoapods: warn if cocoapods plugin uses default framework linking type.
This commit is contained in:
committed by
Space
parent
8a7b399dbe
commit
8c2a2b8569
+16
@@ -831,6 +831,22 @@ 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) {
|
||||
|
||||
+14
@@ -293,10 +293,24 @@ 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
|
||||
|
||||
+33
-3
@@ -32,6 +32,7 @@ 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
|
||||
@@ -168,7 +169,7 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
|
||||
kotlinExtension.supportedTargets().all { target ->
|
||||
target.binaries.framework(POD_FRAMEWORK_PREFIX) {
|
||||
baseName = cocoapodsExtension.frameworkNameInternal
|
||||
isStatic = true
|
||||
setIsStaticSilently(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -195,7 +196,7 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
|
||||
"The project must have a target for at least one of the following platforms: " +
|
||||
"${requestedPlatforms.joinToString { it.visibleName }}."
|
||||
}
|
||||
fatTargets.forEach { platform, targets ->
|
||||
fatTargets.forEach { (platform, targets) ->
|
||||
check(targets.size <= 1) {
|
||||
"The project has more than one target for the requested platform: `${platform.visibleName}`"
|
||||
}
|
||||
@@ -230,7 +231,33 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
|
||||
check(targets.size == 1) { "The project has more than one target for the requested platform: `${requestedPlatform.visibleName}`" }
|
||||
|
||||
val frameworkLinkTask = targets.single().binaries.getFramework(POD_FRAMEWORK_PREFIX, requestedBuildType).linkTaskProvider
|
||||
project.createSyncFrameworkTask(frameworkLinkTask.flatMap { it.destinationDirectory.map { it.asFile }}, frameworkLinkTask)
|
||||
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(
|
||||
@@ -431,10 +458,12 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
|
||||
it.podName = project.provider { pod.name.asValidTaskName() }
|
||||
it.podSource = project.provider<Git> { podSource }
|
||||
}
|
||||
|
||||
is Url -> project.tasks.register(pod.toPodDownloadTaskName, PodDownloadUrlTask::class.java) {
|
||||
it.podName = project.provider { pod.name.asValidTaskName() }
|
||||
it.podSource = project.provider<Url> { podSource }
|
||||
}
|
||||
|
||||
else -> return@all
|
||||
}
|
||||
|
||||
@@ -702,6 +731,7 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
|
||||
createDefaultFrameworks(kotlinExtension, cocoapodsExtension)
|
||||
registerDummyFrameworkTask(project, cocoapodsExtension)
|
||||
createSyncTask(project, kotlinExtension, cocoapodsExtension)
|
||||
checkFrameworkLinkingType(project, kotlinExtension)
|
||||
registerPodspecTask(project, cocoapodsExtension)
|
||||
|
||||
registerPodDownloadTask(project, cocoapodsExtension)
|
||||
|
||||
Reference in New Issue
Block a user