on master help sign in
Added IdrisDoc hooks from the command line.
d4abcb8Philip Rasmussen
main/Main.hs+4
@@ -61,6 +61,10 @@ runIdris opts = do
61 [] -> return ()
61 [] -> return ()
62 fs -> do runIO $ mapM_ cleanPkg fs
62 fs -> do runIO $ mapM_ cleanPkg fs
63 runIO $ exitWith ExitSuccess
63 runIO $ exitWith ExitSuccess
64+ case opt getPkgMkDoc opts of -- IdrisDoc
65+ [] -> return ()
66+ fs -> do runIO $ mapM_ documentPkg fs
67+ runIO $ exitWith ExitSuccess
64 case opt getPkg opts of
68 case opt getPkg opts of
65 [] -> case opt getPkgREPL opts of
69 [] -> case opt getPkgREPL opts of
66 [] -> idrisMain opts
70 [] -> idrisMain opts
src/Pkg/Package.hs+34−2
@@ -11,12 +11,18 @@ import System.Directory (createDirectoryIfMissing, copyFile)
11import Util.System
11import Util.System
12
12
13import Control.Monad
13import Control.Monad
14+import Control.Monad.Trans.State.Strict (execStateT)
15+import Control.Monad.Error (runErrorT)
16+
14import Data.List
17import Data.List
15import Data.List.Split(splitOn)
18import Data.List.Split(splitOn)
16
19
17import Idris.Core.TT
20import Idris.Core.TT
18import Idris.REPL
21import Idris.REPL
22+import Idris.Parser (loadModule)
23+import Idris.Delaborate (pshow)
19import Idris.AbsSyntax
24import Idris.AbsSyntax
25+import Idris.IdrisDoc
20
26
21import IRTS.System
27import IRTS.System
22
28
@@ -73,7 +79,7 @@ checkPkg :: Bool -- ^ Show Warnings
73 -> FilePath -- ^ Path to ipkg file.
79 -> FilePath -- ^ Path to ipkg file.
74 -> IO ()
80 -> IO ()
75checkPkg warnonly quit fpath
81checkPkg warnonly quit fpath
76− = do pkgdesc <-parseDesc fpath
82+ = do pkgdesc <- parseDesc fpath
77 ok <- mapM (testLib warnonly (pkgname pkgdesc)) (libdeps pkgdesc)
83 ok <- mapM (testLib warnonly (pkgname pkgdesc)) (libdeps pkgdesc)
78 when (and ok) $
84 when (and ok) $
79 do dir <- getCurrentDirectory
85 do dir <- getCurrentDirectory
@@ -121,6 +127,33 @@ cleanPkg fp
121 Nothing -> return ()
127 Nothing -> return ()
122 Just s -> rmFile $ dir </> s
128 Just s -> rmFile $ dir </> s
123
129
130+-- | Generate IdrisDoc for package
131+documentPkg :: FilePath -- ^ Path to .ipkg file.
132+ -> IO ()
133+documentPkg fp =
134+ do pkgdesc <- parseDesc fp
135+ cd <- getCurrentDirectory
136+ let outputDir = cd </> (pkgname pkgdesc) ++ "_doc"
137+ mods = modules pkgdesc
138+ fs = map (foldl1' (</>) . splitOn "." . showCG) mods
139+ opts = NoREPL : Verbose : idris_opts pkgdesc
140+ setCurrentDirectory $ cd </> sourcedir pkgdesc
141+ make (makefile pkgdesc)
142+ let run l = runErrorT . (execStateT l)
143+ load [] = return ()
144+ load (f:fs) = do loadModule stdout f; load fs
145+ loader = do idrisMain opts; load fs
146+ idrisInstance <- run loader idrisInit
147+ case idrisInstance of
148+ Left err -> do putStrLn $ pshow idrisInit err; exitWith (ExitFailure 1)
149+ Right ist ->
150+ do docRes <- generateDocs ist mods outputDir
151+ case docRes of
152+ Right _ -> putStrLn "IdrisDoc generated"
153+ Left msg -> do putStrLn msg
154+ exitWith (ExitFailure 1)
155+
156+
124-- | Install package
157-- | Install package
125installPkg :: PkgDesc -> IO ()
158installPkg :: PkgDesc -> IO ()
126installPkg pkgdesc
159installPkg pkgdesc
@@ -131,7 +164,6 @@ installPkg pkgdesc
131 Just o -> return () -- do nothing, keep executable locally, for noe
164 Just o -> return () -- do nothing, keep executable locally, for noe
132 mapM_ (installObj (pkgname pkgdesc)) (objs pkgdesc)
165 mapM_ (installObj (pkgname pkgdesc)) (objs pkgdesc)
133
166
134−
135-- ---------------------------------------------------------- [ Helper Methods ]
167-- ---------------------------------------------------------- [ Helper Methods ]
136-- Methods for building, testing, installing, and removal of idris
168-- Methods for building, testing, installing, and removal of idris
137-- packages.
169-- packages.