From 1955e0f32430ddcead458779ef8c3e83f2c573cf Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Thu, 25 Apr 2024 22:46:07 +0200 Subject: [PATCH] fix(cargo): Treat projects outside the analyer root as packages E.g. when analyzing a single Cargo project in a sub-directory with a `cargo.toml` file that points to "path dependencies" in a parent directory, these dependencies should not be seen as projects but as packages. This restores the behavior from before 7522a0c. Resolves #8571. Signed-off-by: Sebastian Schuberth --- plugins/package-managers/cargo/src/main/kotlin/Cargo.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/package-managers/cargo/src/main/kotlin/Cargo.kt b/plugins/package-managers/cargo/src/main/kotlin/Cargo.kt index 0c60ebd6eeded..13ab6a5b2718b 100644 --- a/plugins/package-managers/cargo/src/main/kotlin/Cargo.kt +++ b/plugins/package-managers/cargo/src/main/kotlin/Cargo.kt @@ -191,14 +191,18 @@ class Cargo( ) val nonProjectPackages = packageById.values.mapNotNullTo(mutableSetOf()) { cargoPkg -> - cargoPkg.takeUnless { it.isProject() }?.toPackage(hashes) + cargoPkg.takeUnless { it.isProject(workingDir) }?.toPackage(hashes) } return listOf(ProjectAnalyzerResult(project, nonProjectPackages)) } } -private fun CargoMetadata.Package.isProject() = source == null +private fun CargoMetadata.Package.isProject(root: File? = null): Boolean { + val path = id.substringAfter("path+file://", "").removeSuffix(")").ifEmpty { null } + val isWithinRoot = root != null && path != null && File(path).startsWith(root) + return source == null && isWithinRoot +} private fun CargoMetadata.Package.toPackage(hashes: Map): Package { val declaredLicenses = parseDeclaredLicenses()