Skip to content

Commit 18f9be2

Browse files
committed
fix(CocoaPods): Correctly parse secondary dependencies with versions
Until now, for secondary lines in the "PODS" section any present version was ignored. However, if a version is present there, then there is no top-level entry for the same package anymore to declare the version, which resulted in a `NoSuchElementException` for the `versionForName` map. Solve that by also parsing the version for such secondary entries, if present. Also, allow the lookup in `dependenciesForName` to fail, which simply means that named package has no dependencies. Fixes #7523. Signed-off-by: Sebastian Schuberth <[email protected]>
1 parent cf295f6 commit 18f9be2

File tree

1 file changed

+13
-3
lines changed
  • plugins/package-managers/cocoapods/src/main/kotlin

1 file changed

+13
-3
lines changed

plugins/package-managers/cocoapods/src/main/kotlin/CocoaPods.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,13 @@ private const val SCOPE_NAME = "dependencies"
231231

232232
private fun parseNameAndVersion(entry: String): Pair<String, String?> {
233233
val info = entry.split(' ', limit = 2)
234-
return info[0] to info.getOrNull(1)?.removeSurrounding("(", ")")
234+
val name = info[0]
235+
236+
// A version entry could look something like "(6.3.0)", "(= 2021.06.28.00-v2)", "(~> 8.15.0)", etc. Also see
237+
// https://guides.cocoapods.org/syntax/podfile.html#pod.
238+
val version = info.getOrNull(1)?.removeSurrounding("(", ")")?.substringAfterLast(' ')
239+
240+
return name to version
235241
}
236242

237243
private fun getPackageReferences(podfileLock: File): Set<PackageReference> {
@@ -251,14 +257,18 @@ private fun getPackageReferences(podfileLock: File): Set<PackageReference> {
251257
val (name, version) = parseNameAndVersion(entry)
252258
versionForName[name] = checkNotNull(version)
253259

254-
val dependencies = node[entry]?.map { it.textValue().substringBefore(" ") }.orEmpty()
260+
val dependencies = node[entry]?.map { depNode ->
261+
val (depName, depVersion) = parseNameAndVersion(depNode.textValue())
262+
depName.also { if (depVersion != null) versionForName[it] = depVersion }
263+
}.orEmpty()
264+
255265
dependenciesForName.getOrPut(name) { mutableSetOf() } += dependencies
256266
}
257267

258268
fun createPackageReference(name: String): PackageReference =
259269
PackageReference(
260270
id = Identifier("Pod", "", name, versionForName.getValue(name)),
261-
dependencies = dependenciesForName.getValue(name).mapTo(mutableSetOf()) { createPackageReference(it) }
271+
dependencies = dependenciesForName[name].orEmpty().mapTo(mutableSetOf()) { createPackageReference(it) }
262272
)
263273

264274
return root.get("DEPENDENCIES").mapTo(mutableSetOf()) { node ->

0 commit comments

Comments
 (0)