diff options
author | David Waern <david.waern@gmail.com> | 2009-04-05 12:57:21 +0000 |
---|---|---|
committer | David Waern <david.waern@gmail.com> | 2009-04-05 12:57:21 +0000 |
commit | 85d0d7052789ac2f4053d14f81aac86b8a1b866a (patch) | |
tree | 5a8c9ed689508472f75ac88b8bf1e1c9c15b57e6 /src/Main.hs | |
parent | a03f1b96b464b09ce9679bc1bbd45fea221e89b6 (diff) |
Remove Haddock.GHC and move its (small) contents to Main
Diffstat (limited to 'src/Main.hs')
-rw-r--r-- | src/Main.hs | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/src/Main.hs b/src/Main.hs index f80e118b..c97a5b0a 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -21,8 +21,8 @@ import Haddock.Version import Haddock.InterfaceFile import Haddock.Exception import Haddock.Options -import Haddock.GHC import Haddock.Utils +import Haddock.GhcUtils import Paths_haddock import Control.Monad @@ -346,6 +346,57 @@ dumpInterfaceFile ifaces homeLinks flags = ------------------------------------------------------------------------------- +-- Creating a GHC session +------------------------------------------------------------------------------- + +-- | Start a GHC session with the -haddock flag set. Also turn off +-- compilation and linking. +#if __GLASGOW_HASKELL__ >= 609 +startGhc :: String -> [String] -> (DynFlags -> Ghc a) -> IO a +startGhc libDir flags ghcActs = do + -- TODO: handle warnings? + (restFlags, _) <- parseStaticFlags (map noLoc flags) + runGhc (Just libDir) $ do + dynflags <- getSessionDynFlags +#else +startGhc :: String -> [String] -> IO (Session, DynFlags) +startGhc libDir flags = do + restFlags <- parseStaticFlags flags + session <- newSession (Just libDir) + dynflags <- getSessionDynFlags session + do +#endif + let dynflags' = dopt_set dynflags Opt_Haddock + let dynflags'' = dynflags' { + hscTarget = HscNothing, + ghcMode = CompManager, + ghcLink = NoLink + } + dynflags''' <- parseGhcFlags dynflags'' restFlags flags + defaultCleanupHandler dynflags''' $ do +#if __GLASGOW_HASKELL__ >= 609 + setSessionDynFlags dynflags''' + ghcActs dynflags''' +#else + setSessionDynFlags session dynflags''' + return (session, dynflags''') +#endif + where + parseGhcFlags :: Monad m => DynFlags -> [Located String] + -> [String] -> m DynFlags + parseGhcFlags dynflags flags_ origFlags = do + -- TODO: handle warnings? +#if __GLASGOW_HASKELL__ >= 609 + (dynflags', rest, _) <- parseDynamicFlags dynflags flags_ +#else + (dynflags', rest) <- parseDynamicFlags dynflags flags_ +#endif + if not (null rest) + then throwE ("Couldn't parse GHC options: " ++ (unwords origFlags)) + else return dynflags' + + +------------------------------------------------------------------------------- -- Misc ------------------------------------------------------------------------------- |