@@ -27,34 +27,53 @@ import Distribution.Solver.Modular.ConfiguredConversion
27
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
39
( convPIs )
34
40
import Distribution.Solver.Modular.Log
35
41
( SolverFailure (.. ), displayLogMessages )
36
42
import Distribution.Solver.Modular.Package
37
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
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
63
( PkgConfigDb )
48
64
import Distribution.Solver.Types.Progress
49
- import Distribution.Solver.Types.Variable
65
+ ( Progress (.. ), foldProgress )
66
+ import Distribution.Solver.Types.SummarizedMessage
67
+ ( SummarizedMessage (StringMsg ) )
68
+ import Distribution.Solver.Types.Variable ( Variable (.. ) )
50
69
import Distribution.System
51
70
( Platform (.. ) )
52
71
import Distribution.Simple.Setup
53
72
( BooleanFlag (.. ) )
54
73
import Distribution.Simple.Utils
55
- ( ordNubBy )
56
- import Distribution.Verbosity
57
-
74
+ ( ordNubBy )
75
+ import Distribution.Verbosity ( normal , verbose )
76
+ import Distribution.Solver.Modular.Message ( renderSummarizedMessage )
58
77
59
78
-- | Ties the two worlds together: classic cabal-install vs. the modular
60
79
-- solver. Performs the necessary translations before and after.
@@ -120,21 +139,21 @@ solve' :: SolverConfig
120
139
-> (PN -> PackagePreferences )
121
140
-> Map PN [LabeledPackageConstraint ]
122
141
-> Set PN
123
- -> Progress String String (Assignment , RevDepMap )
142
+ -> Progress SummarizedMessage String (Assignment , RevDepMap )
124
143
solve' sc cinfo idx pkgConfigDB pprefs gcs pns =
125
144
toProgress $ retry (runSolver printFullLog sc) createErrorMsg
126
145
where
127
146
runSolver :: Bool -> SolverConfig
128
- -> RetryLog String SolverFailure (Assignment , RevDepMap )
147
+ -> RetryLog SummarizedMessage SolverFailure (Assignment , RevDepMap )
129
148
runSolver keepLog sc' =
130
149
displayLogMessages keepLog $
131
150
solve sc' cinfo idx pkgConfigDB pprefs gcs pns
132
151
133
152
createErrorMsg :: SolverFailure
134
- -> RetryLog String String (Assignment , RevDepMap )
153
+ -> RetryLog SummarizedMessage String (Assignment , RevDepMap )
135
154
createErrorMsg failure@ (ExhaustiveSearch cs cm) =
136
155
if asBool $ minimizeConflictSet sc
137
- then continueWith (" Found no solution after exhaustively searching the "
156
+ then continueWith (mkStringMsg $ " Found no solution after exhaustively searching the "
138
157
++ " dependency tree. Rerunning the dependency solver "
139
158
++ " to minimize the conflict set ({"
140
159
++ showConflictSet cs ++ " })." ) $
@@ -155,7 +174,7 @@ solve' sc cinfo idx pkgConfigDB pprefs gcs pns =
155
174
rerunSolverForErrorMsg cs ++ finalErrorMsg sc failure
156
175
createErrorMsg failure@ BackjumpLimitReached =
157
176
continueWith
158
- (" Backjump limit reached. Rerunning dependency solver to generate "
177
+ (mkStringMsg $ " Backjump limit reached. Rerunning dependency solver to generate "
159
178
++ " a final conflict set for the search tree containing the "
160
179
++ " first backjump." ) $
161
180
retry (runSolver printFullLog sc { pruneAfterFirstSuccess = PruneAfterFirstSuccess True }) $
@@ -181,13 +200,16 @@ solve' sc cinfo idx pkgConfigDB pprefs gcs pns =
181
200
-- original goal order.
182
201
goalOrder' = preferGoalsFromConflictSet cs <> fromMaybe mempty (goalOrder sc)
183
202
184
- in unlines (" Could not resolve dependencies:" : messages (toProgress (runSolver True sc')))
203
+ in unlines (" Could not resolve dependencies:" : map renderSummarizedMessage ( messages (toProgress (runSolver True sc') )))
185
204
186
205
printFullLog = solverVerbosity sc >= verbose
187
206
188
207
messages :: Progress step fail done -> [step ]
189
208
messages = foldProgress (:) (const [] ) (const [] )
190
209
210
+ mkStringMsg :: String -> SummarizedMessage
211
+ mkStringMsg msg = StringMsg msg
212
+
191
213
-- | Try to remove variables from the given conflict set to create a minimal
192
214
-- conflict set.
193
215
--
@@ -219,11 +241,11 @@ solve' sc cinfo idx pkgConfigDB pprefs gcs pns =
219
241
-- solver to add new unnecessary variables to the conflict set. This function
220
242
-- discards the result from any run that adds new variables to the conflict
221
243
-- set, but the end result may not be completely minimized.
222
- tryToMinimizeConflictSet :: forall a . (SolverConfig -> RetryLog String SolverFailure a )
244
+ tryToMinimizeConflictSet :: forall a . (SolverConfig -> RetryLog SummarizedMessage SolverFailure a )
223
245
-> SolverConfig
224
246
-> ConflictSet
225
247
-> ConflictMap
226
- -> RetryLog String SolverFailure a
248
+ -> RetryLog SummarizedMessage SolverFailure a
227
249
tryToMinimizeConflictSet runSolver sc cs cm =
228
250
foldl (\ r v -> retryNoSolution r $ tryToRemoveOneVar v)
229
251
(fromProgress $ Fail $ ExhaustiveSearch cs cm)
@@ -249,14 +271,14 @@ tryToMinimizeConflictSet runSolver sc cs cm =
249
271
tryToRemoveOneVar :: Var QPN
250
272
-> ConflictSet
251
273
-> ConflictMap
252
- -> RetryLog String SolverFailure a
274
+ -> RetryLog SummarizedMessage SolverFailure a
253
275
tryToRemoveOneVar v smallestKnownCS smallestKnownCM
254
276
-- Check whether v is still present, because it may have already been
255
277
-- removed in a previous solver rerun.
256
278
| not (v `CS.member` smallestKnownCS) =
257
279
fromProgress $ Fail $ ExhaustiveSearch smallestKnownCS smallestKnownCM
258
280
| otherwise =
259
- continueWith (" Trying to remove variable " ++ varStr ++ " from the "
281
+ continueWith (mkStringMsg $ " Trying to remove variable " ++ varStr ++ " from the "
260
282
++ " conflict set." ) $
261
283
retry (runSolver sc') $ \ case
262
284
err@ (ExhaustiveSearch cs' _)
@@ -268,14 +290,14 @@ tryToMinimizeConflictSet runSolver sc cs cm =
268
290
++ " conflict set."
269
291
in -- Use the new conflict set, even if v wasn't removed,
270
292
-- because other variables may have been removed.
271
- failWith (msg ++ " Continuing with " ++ showCS cs' ++ " ." ) err
293
+ failWith (mkStringMsg $ msg ++ " Continuing with " ++ showCS cs' ++ " ." ) err
272
294
| otherwise ->
273
- failWith (" Failed to find a smaller conflict set. The new "
295
+ failWith (mkStringMsg $ " Failed to find a smaller conflict set. The new "
274
296
++ " conflict set is not a subset of the previous "
275
297
++ " conflict set: " ++ showCS cs') $
276
298
ExhaustiveSearch smallestKnownCS smallestKnownCM
277
299
BackjumpLimitReached ->
278
- failWith " Reached backjump limit while minimizing conflict set."
300
+ failWith (mkStringMsg " Reached backjump limit while minimizing conflict set." )
279
301
BackjumpLimitReached
280
302
where
281
303
varStr = " \" " ++ showVar v ++ " \" "
0 commit comments