[KT-53127] Fix paths to local unarchived pod and for git pod.

This commit is contained in:
konstantin.tskhovrebov
2022-07-13 12:15:59 +02:00
committed by Space
parent 6d594d1a08
commit f509a756fd
3 changed files with 19 additions and 9 deletions
@@ -253,7 +253,7 @@ class CocoaPodsIT : BaseGradleIT() {
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'"))
assertTrue(podfileText.contains("pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :tag => '5.6.1'"))
}
}
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension.Cocoapods
import org.jetbrains.kotlin.gradle.plugin.mpp.Framework
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBinary
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
import org.jetbrains.kotlin.gradle.targets.native.tasks.PodDownloadUrlTask
import org.jetbrains.kotlin.gradle.tasks.addArg
import org.jetbrains.kotlin.gradle.tasks.addArgs
import org.jetbrains.kotlin.konan.target.HostManager
@@ -353,7 +354,10 @@ abstract class CocoapodsExtension @Inject constructor(private val project: Proje
@get:Input var isAllowInsecureProtocol: Boolean
) : PodLocation() {
override fun getLocalPath(project: Project, podName: String): String {
return project.cocoapodsBuildDirs.externalSources("url").resolve(podName).absolutePath
val fileName = url.toString().substringAfterLast("/")
val extension = PodDownloadUrlTask.getFileExtension(fileName) ?: error("Unknown file extension: $fileName")
val dirName = fileName.substringBeforeLast(".$extension")
return project.cocoapodsBuildDirs.externalSources("url").resolve(podName).resolve(dirName).absolutePath
}
}
@@ -120,6 +120,16 @@ abstract class DownloadCocoapodsTask : CocoapodsTask() {
}
open class PodDownloadUrlTask : DownloadCocoapodsTask() {
companion object {
private val permittedFileExtensions = listOf("tar.gz", "tar.bz2", "tar.xz", "tar", "tgz", "tbz", "txz", "zip", "gzip", "jar")
internal fun getFileExtension(fileName: String): String? {
val permittedFileNameFormat = Regex(
".*(\\.)(${permittedFileExtensions.joinToString("|") { it.replace(".", "\\.") }})"
)
return permittedFileNameFormat.matchEntire(fileName)?.groups?.lastOrNull()?.value
}
}
@get:Nested
internal lateinit var podSource: Provider<Url>
@@ -133,15 +143,11 @@ open class PodDownloadUrlTask : DownloadCocoapodsTask() {
urlDir.resolve(podName.get())
}
@get:Internal
internal val permittedFileExtensions = listOf("tar.gz", "tar.bz2", "tar.xz", "tar", "tgz", "tbz", "txz", "zip", "gzip", "jar")
@TaskAction
fun download() {
val podLocation = podSource.get()
val fileName = podLocation.url.toString().substringAfterLast("/")
val permittedFileNameFormat = Regex(".*(\\.)(${permittedFileExtensions.joinToString("|") { it.replace(".", "\\.") }})")
val extension = permittedFileNameFormat.matchEntire(fileName)?.groups?.lastOrNull()?.value
val extension = getFileExtension(fileName)
require(extension != null) {
"""
$fileName has an unsupported file extension
@@ -482,14 +488,14 @@ open class PodGenTask : CocoapodsTask() {
val source = it.source
if (source != null) {
val path = source.getLocalPath(project, it.name)
when (source) {
is Path, is Url -> {
val path = source.getLocalPath(project, it.name)
append(", :path => '$path'")
}
is Git -> {
append(", :git => '$path'")
append(", :git => '${source.url}'")
when {
source.branch != null -> append(", :branch => '${source.branch}'")
source.tag != null -> append(", :tag => '${source.tag}'")