Skip to content

Commit 94e60c4

Browse files
committed
refactor(cabal-install): refactor InstallPlan.problems
Split the function into multiple ones.
1 parent f0bbf0b commit 94e60c4

File tree

1 file changed

+59
-19
lines changed

1 file changed

+59
-19
lines changed

cabal-install/src/Distribution/Client/InstallPlan.hs

Lines changed: 59 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,11 +1044,19 @@ valid loc graph =
10441044
ps -> internalError loc ('\n' : unlines (map showPlanProblem ps))
10451045

10461046
data PlanProblem ipkg srcpkg
1047-
= PackageMissingDeps (GenericPlanPackage ipkg srcpkg) [GraphKey ipkg srcpkg]
1048-
| PackageCycle [GenericPlanPackage ipkg srcpkg]
1047+
= PackageMissingDeps
1048+
(GenericPlanPackage ipkg srcpkg)
1049+
-- ^ The package that is missing dependencies
1050+
[GraphKey ipkg srcpkg]
1051+
-- ^ The missing dependencies
1052+
| -- | The packages involved in a dependency cycle
1053+
PackageCycle
1054+
[GenericPlanPackage ipkg srcpkg]
10491055
| PackageStateInvalid
10501056
(GenericPlanPackage ipkg srcpkg)
1057+
-- ^ The package that is in an invalid state
10511058
(GenericPlanPackage ipkg srcpkg)
1059+
-- ^ The package that it depends on which is in an invalid state
10521060

10531061
showPlanProblem
10541062
:: ( IsGraph ipkg srcpkg
@@ -1083,6 +1091,18 @@ problems
10831091
=> Graph (GenericPlanPackage ipkg srcpkg)
10841092
-> [PlanProblem ipkg srcpkg]
10851093
problems graph =
1094+
concat
1095+
[ checkForMissingDeps graph
1096+
, checkForCycles graph
1097+
, -- , checkForDependencyInconsistencies graph
1098+
checkForPackageStateInconsistencies graph
1099+
]
1100+
1101+
checkForMissingDeps
1102+
:: IsGraph ipkg srcpkg
1103+
=> Graph (GenericPlanPackage ipkg srcpkg)
1104+
-> [PlanProblem ipkg srcpkg]
1105+
checkForMissingDeps graph =
10861106
[ PackageMissingDeps
10871107
pkg
10881108
( mapMaybe
@@ -1091,23 +1111,43 @@ problems graph =
10911111
)
10921112
| (pkg, missingDeps) <- Graph.broken graph
10931113
]
1094-
++ [ PackageCycle cycleGroup
1095-
| cycleGroup <- Graph.cycles graph
1096-
]
1097-
{-
1098-
++ [ PackageInconsistency name inconsistencies
1099-
| (name, inconsistencies) <-
1100-
dependencyInconsistencies indepGoals graph ]
1101-
--TODO: consider re-enabling this one, see SolverInstallPlan
1102-
-}
1103-
++ [ PackageStateInvalid pkg pkg'
1104-
| pkg <- Foldable.toList graph
1105-
, Just pkg' <-
1106-
map
1107-
(flip Graph.lookup graph)
1108-
(nodeNeighbors pkg)
1109-
, not (stateDependencyRelation pkg pkg')
1110-
]
1114+
1115+
checkForCycles
1116+
:: IsGraph ipkg srcpkg
1117+
=> Graph (GenericPlanPackage ipkg srcpkg)
1118+
-> [PlanProblem ipkg srcpkg]
1119+
checkForCycles graph =
1120+
[PackageCycle cycleGroup | cycleGroup <- Graph.cycles graph]
1121+
1122+
-- TODO: consider re-enabling this one, see SolverInstallPlan
1123+
--
1124+
-- checkForDependencyInconsistencies
1125+
-- :: ( IsGraph ipkg srcpkg
1126+
-- , Pretty (GraphKey ipkg srcpkg)
1127+
-- , Key srcpkg ~ PlanProblem ipkg srcpkg
1128+
-- , Key ipkg ~ GraphKey ipkg srcpkg
1129+
-- )
1130+
-- => Graph (GenericPlanPackage ipkg srcpkg)
1131+
-- -> [PlanProblem ipkg srcpkg]
1132+
-- checkForDependencyInconsistencies graph =
1133+
-- [ PackageInconsistency name inconsistencies
1134+
-- | (name, inconsistencies) <-
1135+
-- dependencyInconsistencies indepGoals graph
1136+
-- ]
1137+
1138+
checkForPackageStateInconsistencies
1139+
:: IsGraph ipkg srcpkg
1140+
=> Graph (GenericPlanPackage ipkg srcpkg)
1141+
-> [PlanProblem ipkg srcpkg]
1142+
checkForPackageStateInconsistencies graph =
1143+
[ PackageStateInvalid pkg pkg'
1144+
| pkg <- Foldable.toList graph
1145+
, Just pkg' <-
1146+
map
1147+
(flip Graph.lookup graph)
1148+
(nodeNeighbors pkg)
1149+
, not (stateDependencyRelation pkg pkg')
1150+
]
11111151

11121152
-- | The states of packages have that depend on each other must respect
11131153
-- this relation. That is for very case where package @a@ depends on

0 commit comments

Comments
 (0)