2 % (c) The University of Glasgow, 2006
8 -- The above warning supression flag is a temporary kludge.
9 -- While working on this module you are encouraged to remove it and fix
10 -- any warnings in the module. See
11 -- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
17 -- * The PackageConfigMap
18 PackageConfigMap, emptyPackageConfigMap, lookupPackage,
19 extendPackageConfigMap, dumpPackages,
21 -- * Reading the package config, and processing cmdline args
25 lookupModuleInAllPackages,
27 -- * Inspecting the set of packages in scope
28 getPackageIncludePath,
30 getPackageLibraryPath,
32 getPackageExtraCcOpts,
33 getPackageFrameworkPath,
35 getPreloadPackagesAnd,
42 #include "HsVersions.h"
45 import ParsePkgConf ( loadPackageConfig )
46 import DynFlags ( dopt, DynFlag(..), DynFlags(..), PackageFlag(..) )
47 import StaticFlags ( opt_Static )
48 import Config ( cProjectVersion )
49 import Name ( Name, nameModule_maybe )
53 import Maybes ( expectJust, MaybeErr(..) )
57 import System.Environment ( getEnv )
58 import Distribution.InstalledPackageInfo
59 import Distribution.Package
60 import Distribution.Version
62 import ErrUtils ( debugTraceMsg, putMsg, Message )
64 import System.Directory
65 import System.FilePath
69 import Control.Exception ( throwDyn )
71 -- ---------------------------------------------------------------------------
74 -- Package state is all stored in DynFlags, including the details of
75 -- all packages, which packages are exposed, and which modules they
78 -- The package state is computed by initPackages, and kept in DynFlags.
80 -- * -package <pkg> causes <pkg> to become exposed, and all other packages
81 -- with the same name to become hidden.
83 -- * -hide-package <pkg> causes <pkg> to become hidden.
85 -- * Let exposedPackages be the set of packages thus exposed.
86 -- Let depExposedPackages be the transitive closure from exposedPackages of
87 -- their dependencies.
89 -- * When searching for a module from an preload import declaration,
90 -- only the exposed modules in exposedPackages are valid.
92 -- * When searching for a module from an implicit import, all modules
93 -- from depExposedPackages are valid.
95 -- * When linking in a comp manager mode, we link in packages the
96 -- program depends on (the compiler knows this list by the
97 -- time it gets to the link step). Also, we link in all packages
98 -- which were mentioned with preload -package flags on the command-line,
99 -- or are a transitive dependency of same, or are "base"/"rts".
100 -- The reason for (b) is that we might need packages which don't
101 -- contain any Haskell modules, and therefore won't be discovered
102 -- by the normal mechanism of dependency tracking.
106 -- When compiling module A, which imports module B, we need to
107 -- know whether B will be in the same DLL as A.
108 -- If it's in the same DLL, we refer to B_f_closure
109 -- If it isn't, we refer to _imp__B_f_closure
110 -- When compiling A, we record in B's Module value whether it's
111 -- in a different DLL, by setting the DLL flag.
113 data PackageState = PackageState {
114 pkgIdMap :: PackageConfigMap, -- PackageId -> PackageConfig
115 -- The exposed flags are adjusted according to -package and
116 -- -hide-package flags, and -ignore-package removes packages.
118 preloadPackages :: [PackageId],
119 -- The packages we're going to link in eagerly. This list
120 -- should be in reverse dependency order; that is, a package
121 -- is always mentioned before the packages it depends on.
123 moduleToPkgConfAll :: UniqFM [(PackageConfig,Bool)] -- ModuleEnv mapping
124 -- Derived from pkgIdMap.
125 -- Maps Module to (pkgconf,exposed), where pkgconf is the
126 -- PackageConfig for the package containing the module, and
127 -- exposed is True if the package exposes that module.
130 -- A PackageConfigMap maps a PackageId to a PackageConfig
131 type PackageConfigMap = UniqFM PackageConfig
133 emptyPackageConfigMap :: PackageConfigMap
134 emptyPackageConfigMap = emptyUFM
136 lookupPackage :: PackageConfigMap -> PackageId -> Maybe PackageConfig
137 lookupPackage = lookupUFM
139 extendPackageConfigMap
140 :: PackageConfigMap -> [PackageConfig] -> PackageConfigMap
141 extendPackageConfigMap pkg_map new_pkgs
142 = foldl add pkg_map new_pkgs
143 where add pkg_map p = addToUFM pkg_map (packageConfigId p) p
145 getPackageDetails :: PackageState -> PackageId -> PackageConfig
146 getPackageDetails dflags ps = expectJust "getPackageDetails" (lookupPackage (pkgIdMap dflags) ps)
148 -- ----------------------------------------------------------------------------
149 -- Loading the package config files and building up the package state
151 -- | Call this after 'DynFlags.parseDynFlags'. It reads the package
152 -- configuration files, and sets up various internal tables of package
153 -- information, according to the package-related flags on the
154 -- command-line (@-package@, @-hide-package@ etc.)
156 -- Returns a list of packages to link in if we're doing dynamic linking.
157 -- This list contains the packages that the user explicitly mentioned with
160 -- 'initPackages' can be called again subsequently after updating the
161 -- 'packageFlags' field of the 'DynFlags', and it will update the
162 -- 'packageState' in 'DynFlags' and return a list of packages to
164 initPackages :: DynFlags -> IO (DynFlags, [PackageId])
165 initPackages dflags = do
166 pkg_db <- case pkgDatabase dflags of
167 Nothing -> readPackageConfigs dflags
169 (pkg_state, preload, this_pkg)
170 <- mkPackageState dflags pkg_db [] (thisPackage dflags)
171 return (dflags{ pkgDatabase = Just pkg_db,
172 pkgState = pkg_state,
173 thisPackage = this_pkg },
176 -- -----------------------------------------------------------------------------
177 -- Reading the package database(s)
179 readPackageConfigs :: DynFlags -> IO PackageConfigMap
180 readPackageConfigs dflags = do
181 e_pkg_path <- try (getEnv "GHC_PACKAGE_PATH")
182 system_pkgconfs <- getSystemPackageConfigs dflags
184 let pkgconfs = case e_pkg_path of
185 Left _ -> system_pkgconfs
187 | last cs == "" -> init cs ++ system_pkgconfs
189 where cs = parseSearchPath path
190 -- if the path ends in a separator (eg. "/foo/bar:")
191 -- the we tack on the system paths.
193 -- Read all the ones mentioned in -package-conf flags
194 pkg_map <- foldM (readPackageConfig dflags) emptyPackageConfigMap
195 (reverse pkgconfs ++ extraPkgConfs dflags)
200 getSystemPackageConfigs :: DynFlags -> IO [FilePath]
201 getSystemPackageConfigs dflags = do
202 -- System one always comes first
203 let system_pkgconf = systemPackageConfig dflags
205 -- allow package.conf.d to contain a bunch of .conf files
206 -- containing package specifications. This is an easier way
207 -- to maintain the package database on systems with a package
208 -- management system, or systems that don't want to run ghc-pkg
209 -- to register or unregister packages. Undocumented feature for now.
210 let system_pkgconf_dir = system_pkgconf <.> "d"
211 system_pkgconf_dir_exists <- doesDirectoryExist system_pkgconf_dir
213 if system_pkgconf_dir_exists
214 then do files <- getDirectoryContents system_pkgconf_dir
215 return [ system_pkgconf_dir </> file
217 , takeExtension file == ".conf" ]
220 -- Read user's package conf (eg. ~/.ghc/i386-linux-6.3/package.conf)
221 -- unless the -no-user-package-conf flag was given.
222 -- We only do this when getAppUserDataDirectory is available
224 user_pkgconf <- handle (\_ -> return []) $ do
225 appdir <- getAppUserDataDirectory "ghc"
228 </> (TARGET_ARCH ++ '-':TARGET_OS ++ '-':cProjectVersion)
230 flg <- doesFileExist pkgconf
231 if (flg && dopt Opt_ReadUserPackageConf dflags)
232 then return [pkgconf]
235 return (user_pkgconf ++ system_pkgconfs ++ [system_pkgconf])
239 :: DynFlags -> PackageConfigMap -> FilePath -> IO PackageConfigMap
240 readPackageConfig dflags pkg_map conf_file = do
241 debugTraceMsg dflags 2 (text "Using package config file:" <+> text conf_file)
242 proto_pkg_configs <- loadPackageConfig conf_file
243 let top_dir = topDir dflags
244 pkg_configs1 = mungePackagePaths top_dir proto_pkg_configs
245 pkg_configs2 = maybeHidePackages dflags pkg_configs1
246 return (extendPackageConfigMap pkg_map pkg_configs2)
248 maybeHidePackages :: DynFlags -> [PackageConfig] -> [PackageConfig]
249 maybeHidePackages dflags pkgs
250 | dopt Opt_HideAllPackages dflags = map hide pkgs
253 hide pkg = pkg{ exposed = False }
255 mungePackagePaths :: String -> [PackageConfig] -> [PackageConfig]
256 -- Replace the string "$topdir" at the beginning of a path
257 -- with the current topdir (obtained from the -B option).
258 mungePackagePaths top_dir ps = map munge_pkg ps
260 munge_pkg p = p{ importDirs = munge_paths (importDirs p),
261 includeDirs = munge_paths (includeDirs p),
262 libraryDirs = munge_paths (libraryDirs p),
263 frameworkDirs = munge_paths (frameworkDirs p),
264 haddockInterfaces = munge_paths (haddockInterfaces p),
265 haddockHTMLs = munge_paths (haddockHTMLs p)
268 munge_paths = map munge_path
271 | Just p' <- maybePrefixMatch "$topdir" p = top_dir ++ p'
272 | Just p' <- maybePrefixMatch "$httptopdir" p = toHttpPath top_dir ++ p'
275 toHttpPath p = "file:///" ++ p
278 -- -----------------------------------------------------------------------------
279 -- Modify our copy of the package database based on a package flag
280 -- (-package, -hide-package, -ignore-package).
283 :: [PackageConfig] -- Initial database
284 -> PackageFlag -- flag to apply
285 -> IO [PackageConfig] -- new database
287 applyPackageFlag pkgs flag =
290 case matchingPackages str pkgs of
291 Nothing -> missingPackageErr str
292 Just (p:ps,qs) -> return (p':ps')
293 where p' = p {exposed=True}
294 ps' = hideAll (pkgName (package p)) (ps++qs)
297 case matchingPackages str pkgs of
298 Nothing -> missingPackageErr str
299 Just (ps,qs) -> return (map hide ps ++ qs)
300 where hide p = p {exposed=False}
303 case matchingPackages str pkgs of
304 Nothing -> return pkgs
305 Just (ps,qs) -> return qs
306 -- missing package is not an error for -ignore-package,
307 -- because a common usage is to -ignore-package P as
308 -- a preventative measure just in case P exists.
310 -- When a package is requested to be exposed, we hide all other
311 -- packages with the same name.
312 hideAll name ps = map maybe_hide ps
313 where maybe_hide p | pkgName (package p) == name = p {exposed=False}
317 matchingPackages :: String -> [PackageConfig]
318 -> Maybe ([PackageConfig], [PackageConfig])
319 matchingPackages str pkgs
320 = case partition (matches str) pkgs of
322 (ps,rest) -> Just (sortByVersion ps, rest)
324 -- A package named on the command line can either include the
325 -- version, or just the name if it is unambiguous.
327 = str == showPackageId (package p)
328 || str == pkgName (package p)
331 pickPackages pkgs strs =
332 [ p | p <- strs, Just (p:ps,_) <- [matchingPackages p pkgs] ]
334 sortByVersion = sortBy (flip (comparing (pkgVersion.package)))
335 comparing f a b = f a `compare` f b
337 -- -----------------------------------------------------------------------------
338 -- Hide old versions of packages
341 -- hide all packages for which there is also a later version
342 -- that is already exposed. This just makes it non-fatal to have two
343 -- versions of a package exposed, which can happen if you install a
344 -- later version of a package in the user database, for example.
346 hideOldPackages :: DynFlags -> [PackageConfig] -> IO [PackageConfig]
347 hideOldPackages dflags pkgs = mapM maybe_hide pkgs
349 | not (exposed p) = return p
350 | (p' : _) <- later_versions = do
351 debugTraceMsg dflags 2 $
352 (ptext SLIT("hiding package") <+>
353 text (showPackageId (package p)) <+>
354 ptext SLIT("to avoid conflict with later version") <+>
355 text (showPackageId (package p')))
356 return (p {exposed=False})
357 | otherwise = return p
358 where myname = pkgName (package p)
359 myversion = pkgVersion (package p)
360 later_versions = [ p | p <- pkgs, exposed p,
362 pkgName pkg == myname,
363 pkgVersion pkg > myversion ]
365 -- -----------------------------------------------------------------------------
370 -> [PackageConfig] -- database
371 -> [PackageIdentifier] -- preload packages
372 -> PackageId -- this package
373 -> IO ([PackageConfig],
377 findWiredInPackages dflags pkgs preload this_package = do
379 -- Now we must find our wired-in packages, and rename them to
380 -- their canonical names (eg. base-1.0 ==> base).
383 wired_in_pkgids = [ basePackageId,
389 wired_in_names = map packageIdString wired_in_pkgids
391 -- find which package corresponds to each wired-in package
392 -- delete any other packages with the same name
393 -- update the package and any dependencies to point to the new
396 -- When choosing which package to map to a wired-in package
397 -- name, we prefer exposed packages, and pick the latest
398 -- version. To override the default choice, -hide-package
399 -- could be used to hide newer versions.
401 findWiredInPackage :: [PackageConfig] -> String
402 -> IO (Maybe PackageIdentifier)
403 findWiredInPackage pkgs wired_pkg =
404 let all_ps = [ p | p <- pkgs, pkgName (package p) == wired_pkg ] in
405 case filter exposed all_ps of
408 many -> pick (head (sortByVersion many))
409 many -> pick (head (sortByVersion many))
412 debugTraceMsg dflags 2 $
413 ptext SLIT("wired-in package ")
415 <> ptext SLIT(" not found.")
418 debugTraceMsg dflags 2 $
419 ptext SLIT("wired-in package ")
421 <> ptext SLIT(" mapped to ")
422 <> text (showPackageId (package pkg))
423 return (Just (package pkg))
426 mb_wired_in_ids <- mapM (findWiredInPackage pkgs) wired_in_names
428 wired_in_ids = catMaybes mb_wired_in_ids
430 deleteOtherWiredInPackages pkgs = filter ok pkgs
431 where ok p = pkgName (package p) `notElem` wired_in_names
432 || package p `elem` wired_in_ids
434 updateWiredInDependencies pkgs = map upd_pkg pkgs
435 where upd_pkg p = p{ package = upd_pid (package p),
436 depends = map upd_pid (depends p) }
438 upd_pid pid = case filter (== pid) wired_in_ids of
440 (x:_) -> x{ pkgVersion = Version [] [] }
442 pkgs1 = deleteOtherWiredInPackages pkgs
444 pkgs2 = updateWiredInDependencies pkgs1
446 preload1 = map upd_pid preload
448 -- we must return an updated thisPackage, just in case we
449 -- are actually compiling one of the wired-in packages
450 Just old_this_pkg = unpackPackageId this_package
451 new_this_pkg = mkPackageId (upd_pid old_this_pkg)
453 return (pkgs2, preload1, new_this_pkg)
455 -- ----------------------------------------------------------------------------
457 -- Detect any packages that have missing dependencies, and also any
458 -- mutually-recursive groups of packages (loops in the package graph
459 -- are not allowed). We do this by taking the least fixpoint of the
460 -- dependency graph, repeatedly adding packages whose dependencies are
461 -- satisfied until no more can be added.
466 -> [PackageId] -- ignored packages
467 -> IO [PackageConfig]
469 elimDanglingDeps dflags pkgs ignored = go [] pkgs'
471 pkgs' = filter (\p -> packageConfigId p `notElem` ignored) pkgs
474 case partitionWith (depsAvailable avail) not_avail of
475 ([], not_avail) -> do mapM_ reportElim not_avail; return avail
476 (new_avail, not_avail) -> go (new_avail ++ avail) (map fst not_avail)
478 depsAvailable :: [PackageConfig] -> PackageConfig
479 -> Either PackageConfig (PackageConfig, [PackageIdentifier])
480 depsAvailable pkgs_ok pkg
481 | null dangling = Left pkg
482 | otherwise = Right (pkg, dangling)
483 where dangling = filter (`notElem` pids) (depends pkg)
484 pids = map package pkgs_ok
486 reportElim (p, deps) =
487 debugTraceMsg dflags 2 $
488 (ptext SLIT("package") <+> pprPkg p <+>
489 ptext SLIT("will be ignored due to missing or recursive dependencies:") $$
490 nest 2 (hsep (map (text.showPackageId) deps)))
492 -- -----------------------------------------------------------------------------
493 -- When all the command-line options are in, we can process our package
494 -- settings and populate the package state.
498 -> PackageConfigMap -- initial database
499 -> [PackageId] -- preloaded packages
500 -> PackageId -- this package
502 [PackageId], -- new packages to preload
503 PackageId) -- this package, might be modified if the current
505 -- package is a wired-in package.
507 mkPackageState dflags orig_pkg_db preload0 this_package = do
509 -- Modify the package database according to the command-line flags
510 -- (-package, -hide-package, -ignore-package, -hide-all-packages).
512 let flags = reverse (packageFlags dflags)
513 let pkgs0 = eltsUFM orig_pkg_db
514 pkgs1 <- foldM applyPackageFlag pkgs0 flags
516 -- Here we build up a set of the packages mentioned in -package
517 -- flags on the command line; these are called the "preload"
518 -- packages. we link these packages in eagerly. The preload set
519 -- should contain at least rts & base, which is why we pretend that
520 -- the command line contains -package rts & -package base.
522 let new_preload_packages =
523 map package (pickPackages pkgs0 [ p | ExposePackage p <- flags ])
525 -- hide packages that are subsumed by later versions
526 pkgs2 <- hideOldPackages dflags pkgs1
528 -- sort out which packages are wired in
529 (pkgs3, preload1, new_this_pkg)
530 <- findWiredInPackages dflags pkgs2 new_preload_packages this_package
532 let ignored = map packageConfigId $
533 pickPackages pkgs0 [ p | IgnorePackage p <- flags ]
534 pkgs <- elimDanglingDeps dflags pkgs3 ignored
536 let pkg_db = extendPackageConfigMap emptyPackageConfigMap pkgs
537 pkgids = map packageConfigId pkgs
539 -- add base & rts to the preload packages
540 basicLinkedPackages = filter (flip elemUFM pkg_db)
541 [basePackageId,rtsPackageId]
542 -- but in any case remove the current package from the set of
543 -- preloaded packages so that base/rts does not end up in the
544 -- set up preloaded package when we are just building it
545 preload2 = nub (filter (/= new_this_pkg)
546 (basicLinkedPackages ++ map mkPackageId preload1))
548 -- Close the preload packages with their dependencies
549 dep_preload <- closeDeps pkg_db (zip preload2 (repeat Nothing))
550 let new_dep_preload = filter (`notElem` preload0) dep_preload
552 let pstate = PackageState{ preloadPackages = dep_preload,
554 moduleToPkgConfAll = mkModuleMap pkg_db
557 return (pstate, new_dep_preload, new_this_pkg)
560 -- -----------------------------------------------------------------------------
561 -- Make the mapping from module to package info
565 -> UniqFM [(PackageConfig, Bool)]
566 mkModuleMap pkg_db = foldr extend_modmap emptyUFM pkgids
568 pkgids = map packageConfigId (eltsUFM pkg_db)
570 extend_modmap pkgid modmap =
571 addListToUFM_C (++) modmap
572 ([(m, [(pkg, True)]) | m <- exposed_mods] ++
573 [(m, [(pkg, False)]) | m <- hidden_mods])
575 pkg = expectJust "mkModuleMap" (lookupPackage pkg_db pkgid)
576 exposed_mods = exposedModules pkg
577 hidden_mods = hiddenModules pkg
579 pprPkg :: PackageConfig -> SDoc
580 pprPkg p = text (showPackageId (package p))
582 -- -----------------------------------------------------------------------------
583 -- Extracting information from the packages in scope
585 -- Many of these functions take a list of packages: in those cases,
586 -- the list is expected to contain the "dependent packages",
587 -- i.e. those packages that were found to be depended on by the
588 -- current module/program. These can be auto or non-auto packages, it
589 -- doesn't really matter. The list is always combined with the list
590 -- of preload (command-line) packages to determine which packages to
593 getPackageIncludePath :: DynFlags -> [PackageId] -> IO [String]
594 getPackageIncludePath dflags pkgs = do
595 ps <- getPreloadPackagesAnd dflags pkgs
596 return (nub (filter notNull (concatMap includeDirs ps)))
598 -- includes are in reverse dependency order (i.e. rts first)
599 getPackageCIncludes :: [PackageConfig] -> IO [String]
600 getPackageCIncludes pkg_configs = do
601 return (reverse (nub (filter notNull (concatMap includes pkg_configs))))
603 getPackageLibraryPath :: DynFlags -> [PackageId] -> IO [String]
604 getPackageLibraryPath dflags pkgs = do
605 ps <- getPreloadPackagesAnd dflags pkgs
606 return (nub (filter notNull (concatMap libraryDirs ps)))
608 getPackageLinkOpts :: DynFlags -> [PackageId] -> IO [String]
609 getPackageLinkOpts dflags pkgs = do
610 ps <- getPreloadPackagesAnd dflags pkgs
611 let tag = buildTag dflags
612 rts_tag = rtsBuildTag dflags
614 mkDynName | opt_Static = id
615 | otherwise = (++ ("-ghc" ++ cProjectVersion))
616 libs p = map (mkDynName . addSuffix) (hsLibraries p)
618 all_opts p = map ("-l" ++) (libs p) ++ ldOptions p
620 addSuffix rts@"HSrts" = rts ++ (expandTag rts_tag)
621 addSuffix other_lib = other_lib ++ (expandTag tag)
623 expandTag t | null t = ""
626 return (concat (map all_opts ps))
628 getPackageExtraCcOpts :: DynFlags -> [PackageId] -> IO [String]
629 getPackageExtraCcOpts dflags pkgs = do
630 ps <- getPreloadPackagesAnd dflags pkgs
631 return (concatMap ccOptions ps)
633 getPackageFrameworkPath :: DynFlags -> [PackageId] -> IO [String]
634 getPackageFrameworkPath dflags pkgs = do
635 ps <- getPreloadPackagesAnd dflags pkgs
636 return (nub (filter notNull (concatMap frameworkDirs ps)))
638 getPackageFrameworks :: DynFlags -> [PackageId] -> IO [String]
639 getPackageFrameworks dflags pkgs = do
640 ps <- getPreloadPackagesAnd dflags pkgs
641 return (concatMap frameworks ps)
643 -- -----------------------------------------------------------------------------
646 -- | Takes a Module, and if the module is in a package returns
647 -- @(pkgconf,exposed)@ where pkgconf is the PackageConfig for that package,
648 -- and exposed is True if the package exposes the module.
649 lookupModuleInAllPackages :: DynFlags -> ModuleName -> [(PackageConfig,Bool)]
650 lookupModuleInAllPackages dflags m =
651 case lookupUFM (moduleToPkgConfAll (pkgState dflags)) m of
655 getPreloadPackagesAnd :: DynFlags -> [PackageId] -> IO [PackageConfig]
656 getPreloadPackagesAnd dflags pkgids =
658 state = pkgState dflags
659 pkg_map = pkgIdMap state
660 preload = preloadPackages state
661 pairs = zip pkgids (repeat Nothing)
663 all_pkgs <- throwErr (foldM (add_package pkg_map) preload pairs)
664 return (map (getPackageDetails state) all_pkgs)
666 -- Takes a list of packages, and returns the list with dependencies included,
667 -- in reverse dependency order (a package appears before those it depends on).
668 closeDeps :: PackageConfigMap -> [(PackageId, Maybe PackageId)]
670 closeDeps pkg_map ps = throwErr (closeDepsErr pkg_map ps)
672 throwErr :: MaybeErr Message a -> IO a
673 throwErr m = case m of
674 Failed e -> throwDyn (CmdLineError (showSDoc e))
675 Succeeded r -> return r
677 closeDepsErr :: PackageConfigMap -> [(PackageId,Maybe PackageId)]
678 -> MaybeErr Message [PackageId]
679 closeDepsErr pkg_map ps = foldM (add_package pkg_map) [] ps
682 add_package :: PackageConfigMap -> [PackageId] -> (PackageId,Maybe PackageId)
683 -> MaybeErr Message [PackageId]
684 add_package pkg_db ps (p, mb_parent)
685 | p `elem` ps = return ps -- Check if we've already added this package
687 case lookupPackage pkg_db p of
688 Nothing -> Failed (missingPackageMsg (packageIdString p) <>
689 missingDependencyMsg mb_parent)
691 -- Add the package's dependents also
692 let deps = map mkPackageId (depends pkg)
693 ps' <- foldM (add_package pkg_db) ps (zip deps (repeat (Just p)))
696 missingPackageErr p = throwDyn (CmdLineError (showSDoc (missingPackageMsg p)))
697 missingPackageMsg p = ptext SLIT("unknown package:") <+> text p
699 missingDependencyMsg Nothing = empty
700 missingDependencyMsg (Just parent)
701 = space <> parens (ptext SLIT("dependency of") <+> ftext (packageIdFS parent))
703 -- -----------------------------------------------------------------------------
705 isDllName :: PackageId -> Name -> Bool
706 isDllName this_pkg name
708 | Just mod <- nameModule_maybe name = modulePackageId mod /= this_pkg
709 | otherwise = False -- no, it is not even an external name
711 -- -----------------------------------------------------------------------------
712 -- Displaying packages
714 dumpPackages :: DynFlags -> IO ()
715 -- Show package info on console, if verbosity is >= 3
717 = do let pkg_map = pkgIdMap (pkgState dflags)
719 vcat (map (text.showInstalledPackageInfo.to_ipi) (eltsUFM pkg_map))
721 to_ipi pkgconf@InstalledPackageInfo_{ exposedModules = e,
722 hiddenModules = h } =
723 pkgconf{ exposedModules = map moduleNameString e,
724 hiddenModules = map moduleNameString h }