- elimDanglingDeps pkgs =
- case partition (not.null.snd) (map (getDanglingDeps pkgs) pkgs) of
- ([],ps) -> return (map fst ps)
- (ps,qs) -> do
- mapM_ reportElim ps
- elimDanglingDeps (map fst qs)
-
- reportElim (p, deps) =
- debugTraceMsg dflags 2 $
- (ptext SLIT("package") <+> pprPkg p <+>
- ptext SLIT("will be ignored due to missing dependencies:") $$
- nest 2 (hsep (map (text.showPackageId) deps)))
+ wired_in_pkgids :: [String]
+ wired_in_pkgids = map packageIdString
+ [ primPackageId,
+ integerPackageId,
+ basePackageId,
+ rtsPackageId,
+ haskell98PackageId,
+ thPackageId,
+ dphSeqPackageId,
+ dphParPackageId ]
+
+ matches :: PackageConfig -> String -> Bool
+ pc `matches` pid = display (pkgName (package pc)) == pid
+
+ -- find which package corresponds to each wired-in package
+ -- delete any other packages with the same name
+ -- update the package and any dependencies to point to the new
+ -- one.
+ --
+ -- When choosing which package to map to a wired-in package
+ -- name, we prefer exposed packages, and pick the latest
+ -- version. To override the default choice, -hide-package
+ -- could be used to hide newer versions.
+ --
+ findWiredInPackage :: [PackageConfig] -> String
+ -> IO (Maybe InstalledPackageId)
+ findWiredInPackage pkgs wired_pkg =
+ let all_ps = [ p | p <- pkgs, p `matches` wired_pkg ] in
+ case all_ps of
+ [] -> notfound
+ many -> pick (head (sortByVersion many))
+ where
+ notfound = do
+ debugTraceMsg dflags 2 $
+ ptext (sLit "wired-in package ")
+ <> text wired_pkg
+ <> ptext (sLit " not found.")
+ return Nothing
+ pick :: InstalledPackageInfo_ ModuleName
+ -> IO (Maybe InstalledPackageId)
+ pick pkg = do
+ debugTraceMsg dflags 2 $
+ ptext (sLit "wired-in package ")
+ <> text wired_pkg
+ <> ptext (sLit " mapped to ")
+ <> text (display (package pkg))
+ return (Just (installedPackageId pkg))
+
+
+ mb_wired_in_ids <- mapM (findWiredInPackage pkgs) wired_in_pkgids
+ let
+ wired_in_ids = catMaybes mb_wired_in_ids
+
+ -- this is old: we used to assume that if there were
+ -- multiple versions of wired-in packages installed that
+ -- they were mutually exclusive. Now we're assuming that
+ -- you have one "main" version of each wired-in package
+ -- (the latest version), and the others are backward-compat
+ -- wrappers that depend on this one. e.g. base-4.0 is the
+ -- latest, base-3.0 is a compat wrapper depending on base-4.0.
+ {-
+ deleteOtherWiredInPackages pkgs = filterOut bad pkgs
+ where bad p = any (p `matches`) wired_in_pkgids
+ && package p `notElem` map fst wired_in_ids
+ -}
+
+ updateWiredInDependencies pkgs = map upd_pkg pkgs
+ where upd_pkg p
+ | installedPackageId p `elem` wired_in_ids
+ = p { package = (package p){ pkgVersion = Version [] [] } }
+ | otherwise
+ = p
+
+ return $ updateWiredInDependencies pkgs