diff options
author | Simon Hengel <simon.hengel@wiktory.org> | 2010-08-08 10:12:45 +0000 |
---|---|---|
committer | Simon Hengel <simon.hengel@wiktory.org> | 2010-08-08 10:12:45 +0000 |
commit | a127473902c8d833f15ad7fd83f29cc786827f14 (patch) | |
tree | bcbfdb58d951ed3f0ca8ef0a17262da952d539e3 | |
parent | 5df4e529147ebec3d11b6c8e318c50383077afe3 (diff) |
Add createInterfaces' (a more high-level alternative to createInterfaces) to Haddock API
-rw-r--r-- | haddock.cabal | 1 | ||||
-rw-r--r-- | src/Documentation/Haddock.hs | 4 | ||||
-rw-r--r-- | src/Main.hs | 72 |
3 files changed, 52 insertions, 25 deletions
diff --git a/haddock.cabal b/haddock.cabal index 9599310c..e3b11421 100644 --- a/haddock.cabal +++ b/haddock.cabal @@ -167,6 +167,7 @@ library Documentation.Haddock other-modules: + Main Haddock.Interface Haddock.Interface.Rename Haddock.Interface.Create diff --git a/src/Documentation/Haddock.hs b/src/Documentation/Haddock.hs index 21400051..f277bf78 100644 --- a/src/Documentation/Haddock.hs +++ b/src/Documentation/Haddock.hs @@ -17,6 +17,7 @@ module Documentation.Haddock ( Interface(..), InstalledInterface(..), createInterfaces, + createInterfaces', -- * Export items & declarations ExportItem(..), @@ -39,6 +40,7 @@ module Documentation.Haddock ( Example(..), DocMarkup(..), HaddockModInfo(..), + markup, -- * Interface files -- | (.haddock files) @@ -59,3 +61,5 @@ import Haddock.InterfaceFile import Haddock.Interface import Haddock.Types import Haddock.Options +import Haddock.Utils +import Main 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) $ |