Skip to content

Commit

Permalink
feat(Carthage)!: Use the definition file path as fallback project name
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mnonnenmacher committed Feb 23, 2023
1 parent 4e6e29c commit 60eaf71
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions analyzer/src/main/kotlin/managers/Carthage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -96,16 +96,16 @@ 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)

return ProjectInfo(
namespace = vcsHost?.getUserOrOrganization(normalizedVcsUrl),
projectName = vcsHost?.getProject(normalizedVcsUrl)
?: workingDir.relativeTo(analysisRoot).invariantSeparatorsPath,
?: getFallbackProjectName(analysisRoot, definitionFile),
revision = vcsInfo.revision
)
}
Expand Down

0 comments on commit 60eaf71

Please sign in to comment.