- getDanglingDeps pkgs p = (p, filter dangling (depends p))
- where dangling pid = pid `notElem` all_pids
- all_pids = map package pkgs
- --
- pkgs <- elimDanglingDeps pkgs4
- let pkg_db = extendPackageConfigMap emptyPackageConfigMap pkgs
- --
- -- Find the transitive closure of dependencies of exposed
- --
- let exposed_pkgids = [ packageConfigId p | p <- pkgs, exposed p ]
- dep_exposed <- closeDeps pkg_db exposed_pkgids
- let
- -- add base & rts to the explicit packages
- basicLinkedPackages = filter (flip elemUFM pkg_db)
- [basePackageId,rtsPackageId]
- explicit2 = addListToUniqSet (mkUniqSet (map mkPackageId explicit1))
- basicLinkedPackages
- --
- -- Close the explicit packages with their dependencies
+-- ----------------------------------------------------------------------------
+--
+-- Detect any packages that have missing dependencies, and also any
+-- mutually-recursive groups of packages (loops in the package graph
+-- are not allowed). We do this by taking the least fixpoint of the
+-- dependency graph, repeatedly adding packages whose dependencies are
+-- satisfied until no more can be added.
+--
+elimDanglingDeps
+ :: DynFlags
+ -> [PackageConfig]
+ -> [PackageId] -- ignored packages
+ -> IO [PackageConfig]
+
+elimDanglingDeps dflags pkgs ignored = go [] pkgs'
+ where
+ pkgs' = filter (\p -> packageConfigId p `notElem` ignored) pkgs
+
+ go avail not_avail =
+ case partitionWith (depsAvailable avail) not_avail of
+ ([], not_avail) -> do mapM_ reportElim not_avail; return avail
+ (new_avail, not_avail) -> go (new_avail ++ avail) (map fst not_avail)
+
+ depsAvailable :: [PackageConfig] -> PackageConfig
+ -> Either PackageConfig (PackageConfig, [PackageIdentifier])
+ depsAvailable pkgs_ok pkg
+ | null dangling = Left pkg
+ | otherwise = Right (pkg, dangling)
+ where dangling = filter (`notElem` pids) (depends pkg)
+ pids = map package pkgs_ok
+
+ reportElim (p, deps) =
+ debugTraceMsg dflags 2 $
+ (ptext SLIT("package") <+> pprPkg p <+>
+ ptext SLIT("will be ignored due to missing or recursive dependencies:") $$
+ nest 2 (hsep (map (text.showPackageId) deps)))
+
+-- -----------------------------------------------------------------------------
+-- When all the command-line options are in, we can process our package
+-- settings and populate the package state.
+
+mkPackageState
+ :: DynFlags
+ -> PackageConfigMap -- initial database
+ -> [PackageId] -- preloaded packages
+ -> PackageId -- this package
+ -> IO (PackageState,
+ [PackageId], -- new packages to preload
+ PackageId) -- this package, might be modified if the current
+
+ -- package is a wired-in package.
+
+mkPackageState dflags orig_pkg_db preload0 this_package = do