Commit df947224 authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Fix improvePlan so the index is updated incrementally

It's important since later packages can depend on earlier ones having
been changed from configured to pre-existing. That is afterall the
whole point of considering them in reverse toplogical order.
Also, remove duplicates in the dependencies list of installed
packages since ghc-pkg does not currently prevent duplicates in (eg
multiple depends on the same version of base). See ghc bug #2230.
parent 6835d7f6
......@@ -345,23 +345,24 @@ improvePlan installed selected = foldl' improve selected
$ reverseTopologicalOrder selected
improve selected' = maybe selected' (flip PackageIndex.insert selected')
. improvePkg
. improvePkg selected'
-- The idea is to improve the plan by swapping a configured package for
-- an equivalent installed one. For a particular package the condition is
-- that the package be in a configured state, that a the same version be
-- already installed with the exact same dependencies and all the packages
-- in the plan that it depends on are in the installed state
improvePkg pkgid = do
Configured pkg <- PackageIndex.lookupPackageId selected pkgid
improvePkg selected' pkgid = do
Configured pkg <- PackageIndex.lookupPackageId selected' pkgid
ipkg <- PackageIndex.lookupPackageId installed pkgid
guard $ sort (depends pkg) == sort (depends ipkg)
guard $ all isInstalled (depends pkg)
guard $ sort (depends pkg) == nub (sort (depends ipkg))
guard $ all (isInstalled selected') (depends pkg)
return (PreExisting ipkg)
isInstalled pkgid = case PackageIndex.lookupPackageId selected pkgid of
Just (PreExisting _) -> True
_ -> False
isInstalled selected' pkgid =
case PackageIndex.lookupPackageId selected' pkgid of
Just (PreExisting _) -> True
_ -> False
reverseTopologicalOrder :: PackageFixedDeps pkg => PackageIndex pkg
-> [PackageIdentifier]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment