Skip to content

Commit 9830caa

Browse files
bs-ondemsschuberth
authored andcommitted
fix(cocoapods): Correctly resolve react_native_pods.rb script path
Replace the upward search for the nearest `node_modules` directory by traversing up the directory tree and checking for the full path to the `react_native_pods.rb` script at each level. The previous logic stopped at the first `node_modules` directory found, which could incorrectly resolve to a nested one inside another package (e.g. `node_modules/ react-native/node_modules`) leading to a broken path. Signed-off-by: Onur Demirci <[email protected]>
1 parent dcec0ab commit 9830caa

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import org.ossreviewtoolkit.model.VcsType
3636
import org.ossreviewtoolkit.model.orEmpty
3737
import org.ossreviewtoolkit.model.utils.DependencyHandler
3838
import org.ossreviewtoolkit.model.utils.toPurl
39-
import org.ossreviewtoolkit.utils.common.searchUpwardsForSubdirectory
4039

4140
internal class PodDependencyHandler : DependencyHandler<Lockfile.Pod> {
4241
private val podspecCache = mutableMapOf<String, Podspec>()
@@ -125,15 +124,12 @@ internal class PodDependencyHandler : DependencyHandler<Lockfile.Pod> {
125124
private fun File.convertRubyPodspecFile(content: String): String? {
126125
// The podspec is in Ruby format.
127126
// Because it may depend on React Native functions, an extra require may have to be injected.
128-
val rubyContent = parentFile.searchUpwardsForSubdirectory("node_modules")?.let { nodeModulesParentDir ->
129-
val reactNativePath =
130-
nodeModulesParentDir.resolve("node_modules/react-native/scripts/react_native_pods.rb")
131-
if (reactNativePath.isFile) {
127+
val rubyContent = generateSequence(parentFile) { it.parentFile }
128+
.map { it.resolve("node_modules/react-native/scripts/react_native_pods.rb") }
129+
.find { it.isFile }
130+
?.let { reactNativePath ->
132131
"require '$reactNativePath'\n$content"
133-
} else {
134-
null
135-
}
136-
} ?: content
132+
} ?: content
137133

138134
val patchedPodspecFile = resolveSibling("ort_$name").apply { writeText(rubyContent) }
139135

0 commit comments

Comments
 (0)