From 60eaf71d80cd8e2351f7161dbc0f3e177876c3d1 Mon Sep 17 00:00:00 2001 From: Martin Nonnenmacher Date: Thu, 23 Feb 2023 15:49:26 +0100 Subject: [PATCH] feat(Carthage)!: Use the definition file path as fallback project name If the project name cannot be determined from the VCS, use the path of the definition file relative to the analysis root as fallback project name. This reduces the risk of identifier conflicts if there are Carthage projects in different directories with the same name. Signed-off-by: Martin Nonnenmacher --- analyzer/src/main/kotlin/managers/Carthage.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/analyzer/src/main/kotlin/managers/Carthage.kt b/analyzer/src/main/kotlin/managers/Carthage.kt index ca17bb6907223..715bc4c371a6b 100644 --- a/analyzer/src/main/kotlin/managers/Carthage.kt +++ b/analyzer/src/main/kotlin/managers/Carthage.kt @@ -69,7 +69,7 @@ class Carthage( // Transitive dependencies are only supported if the dependency itself uses Carthage. // See: https://github.com/Carthage/Carthage#nested-dependencies val workingDir = definitionFile.parentFile - val projectInfo = getProjectInfoFromVcs(workingDir) + val projectInfo = getProjectInfoFromVcs(definitionFile) return listOf( ProjectAnalyzerResult( @@ -96,8 +96,8 @@ class Carthage( /** * As the "Carthage.resolved" file does not provide any project information, trying to retrieve some from VCS. */ - private fun getProjectInfoFromVcs(workingDir: File): ProjectInfo { - val workingTree = VersionControlSystem.forDirectory(workingDir) + private fun getProjectInfoFromVcs(definitionFile: File): ProjectInfo { + val workingTree = VersionControlSystem.forDirectory(definitionFile.parentFile) val vcsInfo = workingTree?.getInfo().orEmpty() val normalizedVcsUrl = normalizeVcsUrl(vcsInfo.url) val vcsHost = VcsHost.fromUrl(normalizedVcsUrl) @@ -105,7 +105,7 @@ class Carthage( return ProjectInfo( namespace = vcsHost?.getUserOrOrganization(normalizedVcsUrl), projectName = vcsHost?.getProject(normalizedVcsUrl) - ?: workingDir.relativeTo(analysisRoot).invariantSeparatorsPath, + ?: getFallbackProjectName(analysisRoot, definitionFile), revision = vcsInfo.revision ) }