From 92671395bad3646cc416883a5e990a511d451381 Mon Sep 17 00:00:00 2001 From: ksg97031 Date: Fri, 22 Sep 2023 01:15:42 +0900 Subject: [PATCH] fix(CocoaPods): Added Sub Dependency Tracking for CocoaPods Signed-off-by: ksg97031 --- .../cocoapods/src/main/kotlin/CocoaPods.kt | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/plugins/package-managers/cocoapods/src/main/kotlin/CocoaPods.kt b/plugins/package-managers/cocoapods/src/main/kotlin/CocoaPods.kt index 325ac1444a7e9..d882764a0769d 100644 --- a/plugins/package-managers/cocoapods/src/main/kotlin/CocoaPods.kt +++ b/plugins/package-managers/cocoapods/src/main/kotlin/CocoaPods.kt @@ -194,7 +194,7 @@ class CocoaPods( val podspecCommand = runCatching { run( - "spec", "which", podspecName, + "spec", "which", "^$podspecName$", "--version=${id.version}", "--allow-root", "--regex", @@ -233,9 +233,6 @@ private val NAME_AND_VERSION_REGEX = "(\\S+)\\s+(.*)".toRegex() private fun getPackageReferences(podfileLock: File): Set { val versionForName = mutableMapOf() - val dependenciesForName = mutableMapOf>() - val root = yamlMapper.readTree(podfileLock) - root.get("PODS").asIterable().forEach { node -> val entry = when (node) { is ObjectNode -> node.fieldNames().asSequence().first() @@ -247,8 +244,29 @@ private fun getPackageReferences(podfileLock: File): Set { } versionForName[name] = version - val dependencies = node[entry]?.map { it.textValue().substringBefore(" ") }.orEmpty() + val dependencies = node[entry]?.map { it.textValue().substringBefore(" ") }.orEmpty() dependenciesForName.getOrPut(name) { mutableSetOf() } += dependencies + + // If this node has sub dependencies, append them to the dependency tracking. + // Sub dependencies are additional dependencies that are required. + // For more details, refer to issue #7523. + if (node is ObjectNode) { + val subEntries = node[entry].map { it.textValue() } + subEntries.filter { it.contains("(= ") }.forEach { subEntry -> + val (subDependencyName, subDependencyVersion) = NAME_AND_VERSION_REGEX.find(subEntry)!!.groups.let { + it[1]!!.value to it[2]!!.value.removeSurrounding("(= ", ")") + } + + // Add sub dependency if it's not already tracked + if (!versionForName.containsKey(subDependencyName)) { + versionForName[subDependencyName] = subDependencyVersion + + val subDependencies = node[subEntry]?.map { it.textValue().substringBefore(" ") }.orEmpty() + dependenciesForName.getOrPut(subDependencyName) { mutableSetOf() } += subDependencies + } + } + } + } } fun createPackageReference(name: String): PackageReference =