adding options: --package-conf and --no-user-package-conf

These command line options work just like the similar-named GHC flags.
They are useful when working with non-standard package databases.
This commit is contained in:
Takano Akio
2011-05-28 05:43:52 +09:00
parent 92777ed539
commit ad55168265
7 changed files with 55 additions and 32 deletions

View File

@@ -12,6 +12,8 @@ data Options = Options {
convert :: [String] -> String
, hlintOpts :: [String]
, operators :: Bool
, packageConfs :: [FilePath]
, useUserPackageConf :: Bool
}
withGHC :: (MonadPlus m) => Ghc (m a) -> IO (m a)
@@ -22,15 +24,16 @@ withGHC body = ghandle ignore $ runGhc (Just libdir) body
----------------------------------------------------------------
initSession0 :: Ghc [PackageId]
initSession0 = getSessionDynFlags >>= setSessionDynFlags
initSession0 :: Options -> Ghc [PackageId]
initSession0 opt = getSessionDynFlags >>=
setSessionDynFlags . setPackageConfFlags opt
initSession :: [String] -> Maybe [FilePath] -> Ghc [PackageId]
initSession cmdOpts midirs = do
initSession :: Options -> [String] -> Maybe [FilePath] -> Ghc [PackageId]
initSession opt cmdOpts midirs = do
dflags <- getSessionDynFlags
let opts = map noLoc cmdOpts
(dflags',_,_) <- parseDynamicFlags dflags opts
setSessionDynFlags $ setFlags dflags' midirs
setSessionDynFlags $ setPackageConfFlags opt $ setFlags dflags' midirs
----------------------------------------------------------------
@@ -46,6 +49,17 @@ setFlags d midirs = maybe d' (\x -> d' { importPaths = x }) midirs
ghcPackage :: PackageFlag
ghcPackage = ExposePackage "ghc"
setPackageConfFlags :: Options -> DynFlags -> DynFlags
setPackageConfFlags
Options { packageConfs = confs, useUserPackageConf = useUser }
flagset@DynFlags { extraPkgConfs = extra, flags = origFlags }
= flagset { extraPkgConfs = extra', flags = flags' }
where
extra' = confs ++ extra
flags' = if useUser
then origFlags
else filter (/=Opt_ReadUserPackageConf) origFlags
----------------------------------------------------------------
setTargetFile :: (GhcMonad m) => String -> m ()