aboutsummaryrefslogtreecommitdiff
path: root/src/Main.hs
diff options
context:
space:
mode:
authorSimon Hengel <simon.hengel@wiktory.org>2010-08-08 10:12:45 +0000
committerSimon Hengel <simon.hengel@wiktory.org>2010-08-08 10:12:45 +0000
commita127473902c8d833f15ad7fd83f29cc786827f14 (patch)
treebcbfdb58d951ed3f0ca8ef0a17262da952d539e3 /src/Main.hs
parent5df4e529147ebec3d11b6c8e318c50383077afe3 (diff)
Add createInterfaces' (a more high-level alternative to createInterfaces) to Haddock API
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs72
1 files changed, 47 insertions, 25 deletions
diff --git a/src/Main.hs b/src/Main.hs
index 159cb48d..5c0d0174 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -15,7 +15,7 @@
--
-- Program entry point and top-level code.
-----------------------------------------------------------------------------
-module Main (main) where
+module Main (main, createInterfaces') where
import Haddock.Backends.Xhtml
@@ -115,6 +115,48 @@ handleGhcExceptions =
-------------------------------------------------------------------------------
+-- | Create 'Interface' structures from a given list of Haddock command-line
+-- flags and file or module names (as accepted by 'haddock' executable). Flags
+-- that control documentation generation or show help or version information
+-- are ignored.
+--
+-- This is a more high-level alternative to 'createInterfaces'.
+createInterfaces'
+ :: [String] -- ^ A list of command-line flags and file or module names
+ -> IO [Interface] -- ^ Resulting list of interfaces
+createInterfaces' args = do
+ (flags, fileArgs) <- parseHaddockOpts args
+ (_, ifaces) <- readPackagesAndCreateInterfaces flags fileArgs
+ return ifaces
+
+
+readPackagesAndCreateInterfaces :: [Flag] -> [String] -> IO ([(InterfaceFile, FilePath)], [Interface])
+readPackagesAndCreateInterfaces flags fileArgs = do
+ libDir <- getGhcLibDir flags
+
+ -- Catches all GHC source errors, then prints and re-throws them.
+ let handleSrcErrors action' = flip handleSourceError action' $ \err -> do
+ printExceptionAndWarnings err
+ liftIO exitFailure
+
+ -- Initialize GHC.
+ withGhc libDir (ghcFlags flags) $ \_ -> handleSrcErrors $ do
+
+ -- Get packages supplied with --read-interface.
+ packages <- readInterfaceFiles nameCacheFromGhc (ifacePairs flags)
+
+ -- Create the interfaces -- this is the core part of Haddock.
+ (ifaces, homeLinks) <- createInterfaces (verbosity flags) fileArgs flags
+ (map fst packages)
+
+ -- Dump an "interface file" (.haddock file), if requested.
+ liftIO $ case optDumpInterfaceFile flags of
+ Just f -> dumpInterfaceFile f (map toInstalledIface ifaces) homeLinks
+ Nothing -> return ()
+
+ return (packages, ifaces)
+
+
main :: IO ()
main = handleTopExceptions $ do
@@ -125,30 +167,10 @@ main = handleTopExceptions $ do
if not (null fileArgs)
then do
- libDir <- getGhcLibDir flags
-
- -- Catches all GHC source errors, then prints and re-throws them.
- let handleSrcErrors action = flip handleSourceError action $ \err -> do
- printExceptionAndWarnings err
- liftIO exitFailure
-
- -- Initialize GHC.
- withGhc libDir (ghcFlags flags) $ \_ -> handleSrcErrors $ do
-
- -- Get packages supplied with --read-interface.
- packages <- readInterfaceFiles nameCacheFromGhc (ifacePairs flags)
-
- -- Create the interfaces -- this is the core part of Haddock.
- (ifaces, homeLinks) <- createInterfaces (verbosity flags) fileArgs flags
- (map fst packages)
- liftIO $ do
- -- Render the interfaces.
- renderStep flags packages ifaces
-
- -- Dump an "interface file" (.haddock file), if requested.
- case optDumpInterfaceFile flags of
- Just f -> dumpInterfaceFile f (map toInstalledIface ifaces) homeLinks
- Nothing -> return ()
+ (packages, ifaces) <- readPackagesAndCreateInterfaces flags fileArgs
+
+ -- Render the interfaces.
+ renderStep flags packages ifaces
else do
when (any (`elem` [Flag_Html, Flag_Hoogle, Flag_LaTeX]) flags) $