on master help sign in
Added IdrisDoc hooks from the command line.
commitd4abcb89141e31b36eaa56ce84b41f05203a99a0 authorPhilip Rasmussen <pjor@itu.dk> dateThu 27 Mar 2014, 15:17 (13 years ago) parente21b167
2 files changed+38−2
main/Main.hs+4 src/Pkg/Package.hs+34−2
main/Main.hs+4
@@ -61,6 +61,10 @@ runIdris opts = do
6161 [] -> return ()
6262 fs -> do runIO $ mapM_ cleanPkg fs
6363 runIO $ exitWith ExitSuccess
64+ case opt getPkgMkDoc opts of -- IdrisDoc
65+ [] -> return ()
66+ fs -> do runIO $ mapM_ documentPkg fs
67+ runIO $ exitWith ExitSuccess
6468 case opt getPkg opts of
6569 [] -> case opt getPkgREPL opts of
6670 [] -> idrisMain opts
src/Pkg/Package.hs+34−2
@@ -11,12 +11,18 @@ import System.Directory (createDirectoryIfMissing, copyFile)
1111import Util.System
1212
1313import Control.Monad
14+import Control.Monad.Trans.State.Strict (execStateT)
15+import Control.Monad.Error (runErrorT)
16+
1417import Data.List
1518import Data.List.Split(splitOn)
1619
1720import Idris.Core.TT
1821import Idris.REPL
22+import Idris.Parser (loadModule)
23+import Idris.Delaborate (pshow)
1924import Idris.AbsSyntax
25+import Idris.IdrisDoc
2026
2127import IRTS.System
2228
@@ -73,7 +79,7 @@ checkPkg :: Bool -- ^ Show Warnings
7379 -> FilePath -- ^ Path to ipkg file.
7480 -> IO ()
7581checkPkg warnonly quit fpath
76− = do pkgdesc <-parseDesc fpath
82+ = do pkgdesc <- parseDesc fpath
7783 ok <- mapM (testLib warnonly (pkgname pkgdesc)) (libdeps pkgdesc)
7884 when (and ok) $
7985 do dir <- getCurrentDirectory
@@ -121,6 +127,33 @@ cleanPkg fp
121127 Nothing -> return ()
122128 Just s -> rmFile $ dir </> s
123129
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+
124157-- | Install package
125158installPkg :: PkgDesc -> IO ()
126159installPkg pkgdesc
@@ -131,7 +164,6 @@ installPkg pkgdesc
131164 Just o -> return () -- do nothing, keep executable locally, for noe
132165 mapM_ (installObj (pkgname pkgdesc)) (objs pkgdesc)
133166
134−
135167-- ---------------------------------------------------------- [ Helper Methods ]
136168-- Methods for building, testing, installing, and removal of idris
137169-- packages.