@@ -18,43 +18,60 @@ import Distribution.Solver.Compat.Prelude
18
18
import qualified Data.Map as M
19
19
import Data.Set (isSubsetOf )
20
20
import Distribution.Compat.Graph
21
- ( IsNode (.. ) )
21
+ ( IsNode (.. ) )
22
22
import Distribution.Compiler
23
- ( CompilerInfo )
23
+ ( CompilerInfo )
24
24
import Distribution.Solver.Modular.Assignment
25
- ( Assignment , toCPs )
25
+ ( Assignment , toCPs )
26
26
import Distribution.Solver.Modular.ConfiguredConversion
27
- ( convCP )
27
+ ( convCP )
28
28
import qualified Distribution.Solver.Modular.ConflictSet as CS
29
29
import Distribution.Solver.Modular.Dependency
30
- import Distribution.Solver.Modular.Flag
31
- import Distribution.Solver.Modular.Index
30
+ ( Var (.. ),
31
+ showVar ,
32
+ ConflictMap ,
33
+ ConflictSet ,
34
+ showConflictSet ,
35
+ RevDepMap )
36
+ import Distribution.Solver.Modular.Flag ( SN (SN ), FN (FN ) )
37
+ import Distribution.Solver.Modular.Index ( Index )
32
38
import Distribution.Solver.Modular.IndexConversion
33
- ( convPIs )
39
+ ( convPIs )
34
40
import Distribution.Solver.Modular.Log
35
- ( SolverFailure (.. ), displayLogMessages )
41
+ ( SolverFailure (.. ), displayLogMessages )
36
42
import Distribution.Solver.Modular.Package
37
- ( PN )
43
+ ( PN )
38
44
import Distribution.Solver.Modular.RetryLog
45
+ ( RetryLog ,
46
+ toProgress ,
47
+ fromProgress ,
48
+ retry ,
49
+ failWith ,
50
+ continueWith )
39
51
import Distribution.Solver.Modular.Solver
40
- ( SolverConfig (.. ), PruneAfterFirstSuccess (.. ), solve )
52
+ ( SolverConfig (.. ), PruneAfterFirstSuccess (.. ), solve )
41
53
import Distribution.Solver.Types.DependencyResolver
54
+ ( DependencyResolver )
42
55
import Distribution.Solver.Types.LabeledPackageConstraint
56
+ ( LabeledPackageConstraint , unlabelPackageConstraint )
43
57
import Distribution.Solver.Types.PackageConstraint
44
- import Distribution.Solver.Types.PackagePath
58
+ ( PackageConstraint (.. ), scopeToPackageName )
59
+ import Distribution.Solver.Types.PackagePath ( QPN )
45
60
import Distribution.Solver.Types.PackagePreferences
61
+ ( PackagePreferences )
46
62
import Distribution.Solver.Types.PkgConfigDb
47
- ( PkgConfigDb )
63
+ ( PkgConfigDb )
48
64
import Distribution.Solver.Types.Progress
49
- import Distribution.Solver.Types.Variable
65
+ ( Progress (.. ), foldProgress , SummarizedMessage (ErrorMsg ) )
66
+ import Distribution.Solver.Types.Variable ( Variable (.. ) )
50
67
import Distribution.System
51
- ( Platform (.. ) )
68
+ ( Platform (.. ) )
52
69
import Distribution.Simple.Setup
53
- ( BooleanFlag (.. ) )
70
+ ( BooleanFlag (.. ) )
54
71
import Distribution.Simple.Utils
55
- ( ordNubBy )
56
- import Distribution.Verbosity
57
-
72
+ ( ordNubBy )
73
+ import Distribution.Verbosity ( normal , verbose )
74
+ import Distribution.Solver.Modular.Message ( renderSummarizedMessage )
58
75
59
76
-- | Ties the two worlds together: classic cabal-install vs. the modular
60
77
-- solver. Performs the necessary translations before and after.
@@ -120,25 +137,25 @@ solve' :: SolverConfig
120
137
-> (PN -> PackagePreferences )
121
138
-> Map PN [LabeledPackageConstraint ]
122
139
-> Set PN
123
- -> Progress String String (Assignment , RevDepMap )
140
+ -> Progress SummarizedMessage String (Assignment , RevDepMap )
124
141
solve' sc cinfo idx pkgConfigDB pprefs gcs pns =
125
142
toProgress $ retry (runSolver printFullLog sc) createErrorMsg
126
143
where
127
144
runSolver :: Bool -> SolverConfig
128
- -> RetryLog String SolverFailure (Assignment , RevDepMap )
145
+ -> RetryLog SummarizedMessage SolverFailure (Assignment , RevDepMap )
129
146
runSolver keepLog sc' =
130
147
displayLogMessages keepLog $
131
148
solve sc' cinfo idx pkgConfigDB pprefs gcs pns
132
149
133
150
createErrorMsg :: SolverFailure
134
- -> RetryLog String String (Assignment , RevDepMap )
135
- createErrorMsg failure@ (ExhaustiveSearch cs cm ) =
151
+ -> RetryLog SummarizedMessage String (Assignment , RevDepMap )
152
+ createErrorMsg failure@ (ExhaustiveSearch cs _cm ) =
136
153
if asBool $ minimizeConflictSet sc
137
- then continueWith (" Found no solution after exhaustively searching the "
154
+ then continueWith (mkErrorMsg ( " Found no solution after exhaustively searching the "
138
155
++ " dependency tree. Rerunning the dependency solver "
139
156
++ " to minimize the conflict set ({"
140
- ++ showConflictSet cs ++ " })." ) $
141
- retry (tryToMinimizeConflictSet (runSolver printFullLog) sc cs cm ) $
157
+ ++ showConflictSet cs ++ " })." )) $
158
+ retry (tryToMinimizeConflictSet (runSolver printFullLog) sc cs _cm ) $
142
159
\ case
143
160
ExhaustiveSearch cs' cm' ->
144
161
fromProgress $ Fail $
@@ -151,13 +168,13 @@ solve' sc cinfo idx pkgConfigDB pprefs gcs pns =
151
168
++ " Original error message:\n "
152
169
++ rerunSolverForErrorMsg cs
153
170
++ finalErrorMsg sc failure
154
- else fromProgress $ Fail $
155
- rerunSolverForErrorMsg cs ++ finalErrorMsg sc failure
171
+ else
172
+ fromProgress $ Fail $ rerunSolverForErrorMsg cs ++ finalErrorMsg sc failure
156
173
createErrorMsg failure@ BackjumpLimitReached =
157
174
continueWith
158
- (" Backjump limit reached. Rerunning dependency solver to generate "
175
+ (mkErrorMsg ( " Backjump limit reached. Rerunning dependency solver to generate "
159
176
++ " a final conflict set for the search tree containing the "
160
- ++ " first backjump." ) $
177
+ ++ " first backjump." )) $
161
178
retry (runSolver printFullLog sc { pruneAfterFirstSuccess = PruneAfterFirstSuccess True }) $
162
179
\ case
163
180
ExhaustiveSearch cs _ ->
@@ -181,13 +198,16 @@ solve' sc cinfo idx pkgConfigDB pprefs gcs pns =
181
198
-- original goal order.
182
199
goalOrder' = preferGoalsFromConflictSet cs <> fromMaybe mempty (goalOrder sc)
183
200
184
- in unlines (" Could not resolve dependencies:" : messages (toProgress (runSolver True sc')))
201
+ in unlines (" Could not resolve dependencies:" : map renderSummarizedMessage ( messages (toProgress (runSolver True sc') )))
185
202
186
203
printFullLog = solverVerbosity sc >= verbose
187
204
188
205
messages :: Progress step fail done -> [step ]
189
206
messages = foldProgress (:) (const [] ) (const [] )
190
207
208
+ mkErrorMsg :: String -> SummarizedMessage
209
+ mkErrorMsg msg = ErrorMsg msg
210
+
191
211
-- | Try to remove variables from the given conflict set to create a minimal
192
212
-- conflict set.
193
213
--
@@ -219,13 +239,13 @@ solve' sc cinfo idx pkgConfigDB pprefs gcs pns =
219
239
-- solver to add new unnecessary variables to the conflict set. This function
220
240
-- discards the result from any run that adds new variables to the conflict
221
241
-- set, but the end result may not be completely minimized.
222
- tryToMinimizeConflictSet :: forall a . (SolverConfig -> RetryLog String SolverFailure a )
242
+ tryToMinimizeConflictSet :: forall a . (SolverConfig -> RetryLog SummarizedMessage SolverFailure a )
223
243
-> SolverConfig
224
244
-> ConflictSet
225
245
-> ConflictMap
226
- -> RetryLog String SolverFailure a
246
+ -> RetryLog SummarizedMessage SolverFailure a
227
247
tryToMinimizeConflictSet runSolver sc cs cm =
228
- foldl (\ r v -> retryNoSolution r $ tryToRemoveOneVar v)
248
+ foldl (\ r v -> retryMap mkErrorMsg $ retryNoSolution (retryMap renderSummarizedMessage r) $ tryToRemoveOneVar v)
229
249
(fromProgress $ Fail $ ExhaustiveSearch cs cm)
230
250
(CS. toList cs)
231
251
where
@@ -258,7 +278,7 @@ tryToMinimizeConflictSet runSolver sc cs cm =
258
278
| otherwise =
259
279
continueWith (" Trying to remove variable " ++ varStr ++ " from the "
260
280
++ " conflict set." ) $
261
- retry (runSolver sc') $ \ case
281
+ retry (retryMap renderSummarizedMessage $ runSolver sc') $ \ case
262
282
err@ (ExhaustiveSearch cs' _)
263
283
| CS. toSet cs' `isSubsetOf` CS. toSet smallestKnownCS ->
264
284
let msg = if not $ CS. member v cs'
@@ -297,6 +317,9 @@ tryToMinimizeConflictSet runSolver sc cs cm =
297
317
ExhaustiveSearch cs' cm' -> f cs' cm'
298
318
BackjumpLimitReached -> fromProgress (Fail BackjumpLimitReached )
299
319
320
+ retryMap :: (t -> step ) -> RetryLog t fail done -> RetryLog step fail done
321
+ retryMap f l = fromProgress $ (\ p -> foldProgress (\ x xs -> Step (f x) xs) Fail Done p) $ toProgress l
322
+
300
323
-- | Goal ordering that chooses goals contained in the conflict set before
301
324
-- other goals.
302
325
preferGoalsFromConflictSet :: ConflictSet
0 commit comments