Refactor the way packages databases are handled

- cradle now stores a list of active package databases instead of only
  the user store (if present).

- rename `cradlePackageDb` -> `cradlePkgDbStack` as that`s what the ghc
  documentaion calls this kind of thing

- `getPackageDbPackages` now returns names of all visible packages in
  the given directory. Also the implementation now uses `ghc-pkg`
  instead of manually looking at the package database
This commit is contained in:
Daniel Gröber
2014-04-15 05:13:10 +02:00
parent 998a43ce24
commit 30b8366526
16 changed files with 271 additions and 187 deletions

View File

@@ -9,6 +9,9 @@ module Language.Haskell.GhcMod.CabalApi (
, cabalAllTargets
) where
import Language.Haskell.GhcMod.Types
import Language.Haskell.GhcMod.GhcPkg
import Control.Applicative ((<$>))
import Control.Exception (throwIO)
import Control.Monad (filterM)
@@ -30,8 +33,6 @@ import Distribution.System (buildPlatform)
import Distribution.Text (display)
import Distribution.Verbosity (silent)
import Distribution.Version (Version)
import Language.Haskell.GhcMod.Types
import Language.Haskell.GhcMod.Cradle
import System.Directory (doesFileExist)
import System.FilePath (dropExtension, takeFileName, (</>))
@@ -114,7 +115,7 @@ getGHCOptions ghcopts cradle rdir binfo = do
let cpps = map ("-optP" ++) $ P.cppOptions binfo ++ cabalCpp
return $ ghcopts ++ pkgDb ++ exts ++ [lang] ++ libs ++ libDirs ++ cpps
where
pkgDb = userPackageDbOptsForGhc $ cradlePackageDb cradle
pkgDb = ghcDbStackOpts $ cradlePkgDbStack cradle
lang = maybe "-XHaskell98" (("-X" ++) . display) $ P.defaultLanguage binfo
libDirs = map ("-L" ++) $ P.extraLibDirs binfo
exts = map (("-X" ++) . display) $ P.usedExtensions binfo