Skip to content

Commit

Permalink
refactor(stack): Generalize filtering out the "ghc" package
Browse files Browse the repository at this point in the history
The filtering of the "ghc" package is not covered by tests and it is
unkown whether it is needed with the current tooling versions. It seems
relatively safe to assume that the "ghc" package has not been referenced
by any scope back when the filtering was implemented.

Remove filtering "ghc" explicitly in favor of filtering out all
non-referenced packages, which solves the original problem in a more
general way.

Signed-off-by: Frank Viernau <frank_viernau@epam.com>
  • Loading branch information
fviernau committed Jul 3, 2024
1 parent 4a33f34 commit 34e7e95
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions plugins/package-managers/stack/src/main/kotlin/Stack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,10 @@ class Stack(
val testDependencies = listDependencies(workingDir, TEST_SCOPE_NAME)
val benchDependencies = listDependencies(workingDir, BENCH_SCOPE_NAME)

val dependencyPackageMap = buildMap {
(externalDependencies + testDependencies + benchDependencies).filterNot {
// Do not add the project as a package.
it.isProject()
}.forEach { dependency ->
val pkg = dependency.toPackage()

// Do not add the Glasgow Haskell Compiler (GHC) as a package.
if (pkg.id.name != "ghc") this[dependency] = pkg
}
}
val dependencyPackageMap = (externalDependencies + testDependencies + benchDependencies).filterNot {
// Do not add the project as a package.
it.isProject()
}.associateWith { it.toPackage() }

fun List<String>.toPackageReferences(): Set<PackageReference> =
mapNotNullTo(mutableSetOf()) { name ->
Expand All @@ -138,6 +131,9 @@ class Stack(
Scope(BENCH_SCOPE_NAME, benchDependencies.getProjectDependencies().toPackageReferences())
)

val referencedPackageIds = scopes.flatMapTo(mutableSetOf()) { it.collectDependencies() }
val packages = dependencyPackageMap.values.filterTo(mutableSetOf()) { it.id in referencedPackageIds }

val project = Project(
id = projectId,
definitionFilePath = VersionControlSystem.getPathInfo(definitionFile).path,
Expand All @@ -149,7 +145,7 @@ class Stack(
scopeDependencies = scopes
)

return listOf(ProjectAnalyzerResult(project, dependencyPackageMap.values.toSet()))
return listOf(ProjectAnalyzerResult(project, packages))
}

private fun runStack(workingDir: File, vararg command: String): ProcessCapture {
Expand Down

0 comments on commit 34e7e95

Please sign in to comment.