Skip to content

Commit b401faa

Browse files
bs-ondemsschuberth
authored andcommitted
fix(cocoapods): Resolve paths for all pods and dependencies
The previous implementation updated only the `externalSources` in the lockfile by copying the Lockfile object and replacing it with resolved paths. However, this shallow update was insufficient because the nested pod dependencies still referened the original unresolved paths. This commit reconstructs the entire lockfile structure using resolved absolute paths for the external sources. This guarantess that all path references within the lockfile are consistent and correctly resolved. Signed-off-by: Onur Demirci <[email protected]>
1 parent d8e2cde commit b401faa

File tree

1 file changed

+42
-9
lines changed
  • plugins/package-managers/cocoapods/src/main/kotlin

1 file changed

+42
-9
lines changed

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

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,10 @@ class CocoaPods(override val descriptor: PluginDescriptor = CocoaPodsFactory.des
134134
val lockfileData = lockfile.readText().parseLockfile()
135135

136136
// Resolve paths of external sources relative to the lockfile.
137-
val lockfileWithResolvedPaths = lockfileData.copy(
138-
externalSources = lockfileData.externalSources.mapValues { entry ->
139-
Lockfile.ExternalSource(
140-
entry.value.path?.let { lockfile.resolveSibling(it).path },
141-
entry.value.podspec?.let { lockfile.resolveSibling(it).path }
142-
)
143-
}
144-
)
137+
val lockfileWithResolvedPaths = lockfileData.withResolvedPaths(lockfile)
145138

146139
// Convert direct dependencies with version constraints to pods with resolved versions.
147-
val dependencies = lockfileData.dependencies.mapNotNull {
140+
val dependencies = lockfileWithResolvedPaths.dependencies.mapNotNull {
148141
it.resolvedPod?.run {
149142
lockfileWithResolvedPaths.Pod(
150143
name,
@@ -169,3 +162,43 @@ class CocoaPods(override val descriptor: PluginDescriptor = CocoaPodsFactory.des
169162
override fun createPackageManagerResult(projectResults: Map<File, List<ProjectAnalyzerResult>>) =
170163
PackageManagerResult(projectResults, graphBuilder.build(), graphBuilder.packages())
171164
}
165+
166+
/**
167+
* Return a new [Lockfile] instance with all external source paths resolved relative to the given [lockfilePath].
168+
*/
169+
internal fun Lockfile.withResolvedPaths(lockfilePath: File): Lockfile {
170+
val resolvedExternalSources = externalSources.mapValues { entry ->
171+
Lockfile.ExternalSource(
172+
entry.value.path?.let { lockfilePath.resolveSibling(it).path },
173+
entry.value.podspec?.let { lockfilePath.resolveSibling(it).path }
174+
)
175+
}
176+
177+
val pods = mutableListOf<Lockfile.Pod>()
178+
val dependencies = mutableListOf<Lockfile.Dependency>()
179+
180+
val lockFile = Lockfile(pods, dependencies, resolvedExternalSources, checkoutOptions)
181+
182+
this.pods.forEach { pod ->
183+
val resolvedPod = lockFile.Pod(
184+
pod.name,
185+
pod.version,
186+
pod.dependencies.map { dependency ->
187+
lockFile.Dependency(
188+
dependency.name,
189+
dependency.versionConstraint
190+
)
191+
}
192+
)
193+
194+
pods += resolvedPod
195+
}
196+
197+
this.dependencies.forEach { dependency ->
198+
val resolvedDependency = lockFile.Dependency(dependency.name, dependency.versionConstraint)
199+
200+
dependencies += resolvedDependency
201+
}
202+
203+
return lockFile
204+
}

0 commit comments

Comments
 (0)