@@ -56,12 +56,13 @@ import Distribution.System
56
56
import Distribution.Types.Component
57
57
import Distribution.Types.ComponentRequestedSpec
58
58
import Distribution.Types.DependencyMap
59
+ import Distribution.Types.DependencySatisfaction (DependencySatisfaction (.. ))
60
+ import Distribution.Types.MissingDependency (MissingDependency (.. ))
59
61
import Distribution.Types.PackageVersionConstraint
60
62
import Distribution.Utils.Generic
61
63
import Distribution.Utils.Path (sameDirectory )
62
64
import Distribution.Version
63
65
64
- import qualified Data.Map.Lazy as Map
65
66
import Data.Tree (Tree (Node ))
66
67
67
68
------------------------------------------------------------------------------
@@ -144,15 +145,17 @@ parseCondition = condOr
144
145
145
146
------------------------------------------------------------------------------
146
147
147
- -- | Result of dependency test. Isomorphic to @Maybe d @ but renamed for
148
+ -- | Result of dependency test. Isomorphic to @Maybe@ but renamed for
148
149
-- clarity.
149
- data DepTestRslt d = DepOk | MissingDeps d
150
+ data DepTestRslt
151
+ = DepOk
152
+ | MissingDeps [MissingDependency ]
150
153
151
- instance Semigroup d => Monoid ( DepTestRslt d ) where
154
+ instance Monoid DepTestRslt where
152
155
mempty = DepOk
153
156
mappend = (<>)
154
157
155
- instance Semigroup d => Semigroup ( DepTestRslt d ) where
158
+ instance Semigroup DepTestRslt where
156
159
DepOk <> x = x
157
160
x <> DepOk = x
158
161
(MissingDeps d) <> (MissingDeps d') = MissingDeps (d <> d')
@@ -190,13 +193,13 @@ resolveWithFlags
190
193
-> [PackageVersionConstraint ]
191
194
-- ^ Additional constraints
192
195
-> [CondTree ConfVar [Dependency ] PDTagged ]
193
- -> ([Dependency ] -> DepTestRslt [ Dependency ] )
196
+ -> ([Dependency ] -> DepTestRslt )
194
197
-- ^ Dependency test function.
195
- -> Either [Dependency ] (TargetSet PDTagged , FlagAssignment )
198
+ -> Either [MissingDependency ] (TargetSet PDTagged , FlagAssignment )
196
199
-- ^ Either the missing dependencies (error case), or a pair of
197
200
-- (set of build targets with dependencies, chosen flag assignments)
198
201
resolveWithFlags dom enabled os arch impl constrs trees checkDeps =
199
- either ( Left . fromDepMapUnion) Right $ explore (build mempty dom)
202
+ explore (build mempty dom)
200
203
where
201
204
-- simplify trees by (partially) evaluating all conditions and converting
202
205
-- dependencies to dependency maps.
@@ -216,7 +219,7 @@ resolveWithFlags dom enabled os arch impl constrs trees checkDeps =
216
219
-- computation overhead in the successful case.
217
220
explore
218
221
:: Tree FlagAssignment
219
- -> Either DepMapUnion (TargetSet PDTagged , FlagAssignment )
222
+ -> Either [ MissingDependency ] (TargetSet PDTagged , FlagAssignment )
220
223
explore (Node flags ts) =
221
224
let targetSet =
222
225
TargetSet $
@@ -229,7 +232,7 @@ resolveWithFlags dom enabled os arch impl constrs trees checkDeps =
229
232
DepOk
230
233
| null ts -> Right (targetSet, flags)
231
234
| otherwise -> tryAll $ map explore ts
232
- MissingDeps mds -> Left (toDepMapUnion mds)
235
+ MissingDeps mds -> Left mds
233
236
234
237
-- Builds a tree of all possible flag assignments. Internal nodes
235
238
-- have only partial assignments.
@@ -238,18 +241,18 @@ resolveWithFlags dom enabled os arch impl constrs trees checkDeps =
238
241
build assigned ((fn, vals) : unassigned) =
239
242
Node assigned $ map (\ v -> build (insertFlagAssignment fn v assigned) unassigned) vals
240
243
241
- tryAll :: [Either DepMapUnion a ] -> Either DepMapUnion a
244
+ tryAll :: Monoid a => [Either a b ] -> Either a b
242
245
tryAll = foldr mp mz
243
246
244
247
-- special version of `mplus' for our local purposes
245
- mp :: Either DepMapUnion a -> Either DepMapUnion a -> Either DepMapUnion a
248
+ mp :: Monoid a => Either a b -> Either a b -> Either a b
246
249
mp m@ (Right _) _ = m
247
250
mp _ m@ (Right _) = m
248
251
mp (Left xs) (Left ys) = Left (xs <> ys)
249
252
250
253
-- `mzero'
251
- mz :: Either DepMapUnion a
252
- mz = Left ( DepMapUnion Map. empty)
254
+ mz :: Monoid a => Either a b
255
+ mz = Left mempty
253
256
254
257
env :: FlagAssignment -> FlagName -> Either FlagName Bool
255
258
env flags flag = (maybe (Left flag) Right . lookupFlagAssignment flag) flags
@@ -323,27 +326,6 @@ extractConditions f gpkg =
323
326
, extractCondition (f . benchmarkBuildInfo) . snd <$> condBenchmarks gpkg
324
327
]
325
328
326
- -- | A map of package constraints that combines version ranges using 'unionVersionRanges'.
327
- newtype DepMapUnion = DepMapUnion { unDepMapUnion :: Map PackageName (VersionRange , NonEmptySet LibraryName )}
328
-
329
- instance Semigroup DepMapUnion where
330
- DepMapUnion x <> DepMapUnion y =
331
- DepMapUnion $
332
- Map. unionWith unionVersionRanges' x y
333
-
334
- unionVersionRanges'
335
- :: (VersionRange , NonEmptySet LibraryName )
336
- -> (VersionRange , NonEmptySet LibraryName )
337
- -> (VersionRange , NonEmptySet LibraryName )
338
- unionVersionRanges' (vr, cs) (vr', cs') = (unionVersionRanges vr vr', cs <> cs')
339
-
340
- toDepMapUnion :: [Dependency ] -> DepMapUnion
341
- toDepMapUnion ds =
342
- DepMapUnion $ Map. fromListWith unionVersionRanges' [(p, (vr, cs)) | Dependency p vr cs <- ds]
343
-
344
- fromDepMapUnion :: DepMapUnion -> [Dependency ]
345
- fromDepMapUnion m = [Dependency p vr cs | (p, (vr, cs)) <- Map. toList (unDepMapUnion m)]
346
-
347
329
freeVars :: CondTree ConfVar c a -> [FlagName ]
348
330
freeVars t = [f | PackageFlag f <- freeVars' t]
349
331
where
@@ -453,7 +435,7 @@ finalizePD
453
435
:: FlagAssignment
454
436
-- ^ Explicitly specified flag assignments
455
437
-> ComponentRequestedSpec
456
- -> (Dependency -> Bool )
438
+ -> (Dependency -> DependencySatisfaction )
457
439
-- ^ Is a given dependency satisfiable from the set of
458
440
-- available packages? If this is unknown then use
459
441
-- True.
@@ -465,7 +447,7 @@ finalizePD
465
447
-- ^ Additional constraints
466
448
-> GenericPackageDescription
467
449
-> Either
468
- [Dependency ]
450
+ [MissingDependency ]
469
451
(PackageDescription , FlagAssignment )
470
452
-- ^ Either missing dependencies or the resolved package
471
453
-- description along with the flag assignments chosen.
@@ -526,7 +508,11 @@ finalizePD
526
508
| otherwise -> [b, not b]
527
509
-- flagDefaults = map (\(n,x:_) -> (n,x)) flagChoices
528
510
check ds =
529
- let missingDeps = filter (not . satisfyDep) ds
511
+ let missingDeps =
512
+ [ MissingDependency dependency reason
513
+ | (dependency, Unsatisfied reason) <-
514
+ map (\ dependency -> (dependency, satisfyDep dependency)) ds
515
+ ]
530
516
in if null missingDeps
531
517
then DepOk
532
518
else MissingDeps missingDeps
0 commit comments