Commit 3793d3b2 authored by Luite Stegeman's avatar Luite Stegeman Committed by Austin Seipp

Export more Packages functions

Summary:
This patch exports functions for finding the active package
databases and their locations from the Packages module. This
allows GHC API clients to use other tools, like Cabal, to gather
package information that's not directly available from the
binary package db.

Reviewers: duncan, austin

Reviewed By: austin

Subscribers: thomie, carter

Differential Revision: https://phabricator.haskell.org/D514
parent 3e4f49b0
......@@ -11,6 +11,10 @@ module Packages (
-- * Reading the package config, and processing cmdline args
PackageState(preloadPackages),
initPackages,
readPackageConfigs,
getPackageConfRefs,
resolvePackageConfig,
readPackageConfig,
-- * Querying the package config
lookupPackage,
......@@ -328,6 +332,12 @@ initPackages dflags = do
readPackageConfigs :: DynFlags -> IO [PackageConfig]
readPackageConfigs dflags = do
conf_refs <- getPackageConfRefs dflags
confs <- liftM catMaybes $ mapM (resolvePackageConfig dflags) conf_refs
liftM concat $ mapM (readPackageConfig dflags) confs
getPackageConfRefs :: DynFlags -> IO [PkgConfRef]
getPackageConfRefs dflags = do
let system_conf_refs = [UserPkgConf, GlobalPkgConf]
e_pkg_path <- tryIO (getEnv "GHC_PACKAGE_PATH")
......@@ -339,13 +349,10 @@ readPackageConfigs dflags = do
| otherwise
-> map PkgConfFile (splitSearchPath path)
let conf_refs = reverse (extraPkgConfs dflags base_conf_refs)
return $ reverse (extraPkgConfs dflags base_conf_refs)
-- later packages shadow earlier ones. extraPkgConfs
-- is in the opposite order to the flags on the
-- command line.
confs <- liftM catMaybes $ mapM (resolvePackageConfig dflags) conf_refs
liftM concat $ mapM (readPackageConfig dflags) confs
resolvePackageConfig :: DynFlags -> PkgConfRef -> IO (Maybe FilePath)
resolvePackageConfig dflags GlobalPkgConf = return $ Just (systemPackageConfig dflags)
......
Markdown is supported
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