@@ -39,9 +39,14 @@ import IRTS.System
39-- * invoke idris on each module, with idris_opts
39-- * invoke idris on each module, with idris_opts
40-- * install everything into datadir/pname, if install flag is set
40-- * install everything into datadir/pname, if install flag is set
42+-- --------------------------------------------------------- [ Build Packages ]
42-- | Run the package through the idris compiler.
44-- | Run the package through the idris compiler.
43−buildPkg :: Bool -> (Bool, FilePath) -> IO ()
45+buildPkg :: [Opt] -- ^ Command line options
46+ -> Bool -- ^ Provide Warnings
47+ -> (Bool, FilePath) -- ^ (Should we install, Location of iPKG file)
44−buildPkg warnonly (install, fp)
49+buildPkg copts warnonly (install, fp)
45 = do pkgdesc <- parseDesc fp
50 = do pkgdesc <- parseDesc fp
46 dir <- getCurrentDirectory
51 dir <- getCurrentDirectory
47 let idx = PkgIndex (pkgIndex (pkgname pkgdesc))
52 let idx = PkgIndex (pkgIndex (pkgname pkgdesc))
@@ -65,15 +70,18 @@ buildPkg warnonly (install, fp)
65 _ -> return ()
70 _ -> return ()
66 when install $ installPkg pkgdesc
71 when install $ installPkg pkgdesc
73+-- --------------------------------------------------------- [ Check Packages ]
68-- | Type check packages only
75-- | Type check packages only
70-- This differs from build in that executables are not built, if the
77-- This differs from build in that executables are not built, if the
71-- package contains an executable.
78-- package contains an executable.
79+checkPkg :: [Opt] -- ^ Command line Options
72−checkPkg :: Bool -- ^ Show Warnings
80+ -> Bool -- ^ Show Warnings
73− -> Bool -- ^ quit on failure
81+ -> Bool -- ^ quit on failure
74− -> FilePath -- ^ Path to ipkg file.
82+ -> FilePath -- ^ Path to ipkg file.
76−checkPkg warnonly quit fpath
84+checkPkg copts warnonly quit fpath
77 = do pkgdesc <- parseDesc fpath
85 = do pkgdesc <- parseDesc fpath
78 ok <- mapM (testLib warnonly (pkgname pkgdesc)) (libdeps pkgdesc)
86 ok <- mapM (testLib warnonly (pkgname pkgdesc)) (libdeps pkgdesc)
79 when (and ok) $
87 when (and ok) $
@@ -88,29 +96,40 @@ checkPkg warnonly quit fpath
88 Just _ -> exitWith (ExitFailure 1)
96 Just _ -> exitWith (ExitFailure 1)
89 _ -> return ()
97 _ -> return ()
91−-- | Check a package and start a REPL
99+-- ------------------------------------------------------------------- [ REPL ]
92−replPkg :: FilePath -> Idris ()
93−replPkg fp = do orig <- getIState
94− runIO $ checkPkg False False fp
95− pkgdesc <- runIO $ parseDesc fp -- bzzt, repetition!
96− let opts = idris_opts pkgdesc
97− let mod = idris_main pkgdesc
98− let f = toPath (showCG mod)
100− dir <- runIO $ getCurrentDirectory
101− runIO $ setCurrentDirectory $ dir </> sourcedir pkgdesc
104− then idrisMain ((Filename f) : opts)
105− else iputStrLn "Can't start REPL: no main module given"
106− runIO $ setCurrentDirectory dir
101+-- | Check a package and start a REPL.
103+-- This function only works with packages that have a main module.
105+replPkg :: [Opt] -- ^ Command line Options
106+ -> FilePath -- ^ Path to ipkg file.
108+replPkg copts fp = do
110+ runIO $ checkPkg copts False False fp
111+ pkgdesc <- runIO $ parseDesc fp -- bzzt, repetition!
112+ let opts = idris_opts pkgdesc
113+ let mod = idris_main pkgdesc
114+ let f = toPath (showCG mod)
116+ dir <- runIO $ getCurrentDirectory
117+ runIO $ setCurrentDirectory $ dir </> sourcedir pkgdesc
120+ then idrisMain ((Filename f) : opts)
121+ else iputStrLn "Can't start REPL: no main module given"
122+ runIO $ setCurrentDirectory dir
108− where toPath n = foldl1' (</>) $ splitOn "." n
124+ where toPath n = foldl1' (</>) $ splitOn "." n
126+-- --------------------------------------------------------------- [ Cleaning ]
110-- | Clean Package build files
128-- | Clean Package build files
129+cleanPkg :: [Opt] -- ^ Command line options.
111−cleanPkg :: FilePath -- ^ Path to ipkg file.
130+ -> FilePath -- ^ Path to ipkg file.
113−cleanPkg fp
132+cleanPkg copts fp
114 = do pkgdesc <- parseDesc fp
133 = do pkgdesc <- parseDesc fp
115 dir <- getCurrentDirectory
134 dir <- getCurrentDirectory
116 inPkgDir pkgdesc $
135 inPkgDir pkgdesc $
@@ -121,15 +140,19 @@ cleanPkg fp
121 Nothing -> return ()
140 Nothing -> return ()
122 Just s -> rmExe $ dir </> s
141 Just s -> rmExe $ dir </> s
143+-- ------------------------------------------------------ [ Generate IdrisDoc ]
124-- | Generate IdrisDoc for package
146-- | Generate IdrisDoc for package
125-- TODO: Handle case where module does not contain a matching namespace
147-- TODO: Handle case where module does not contain a matching namespace
126-- E.g. from prelude.ipkg: IO, Prelude.Chars, Builtins
148-- E.g. from prelude.ipkg: IO, Prelude.Chars, Builtins
128-- Issue number #1572 on the issue tracker
150-- Issue number #1572 on the issue tracker
129-- https://github.com/idris-lang/Idris-dev/issues/1572
151-- https://github.com/idris-lang/Idris-dev/issues/1572
152+documentPkg :: [Opt] -- ^ Command line options.
130−documentPkg :: FilePath -- ^ Path to .ipkg file.
153+ -> FilePath -- ^ Path to ipkg file.
132−documentPkg fp =
155+documentPkg copts fp =
133 do pkgdesc <- parseDesc fp
156 do pkgdesc <- parseDesc fp
134 cd <- getCurrentDirectory
157 cd <- getCurrentDirectory
135 let pkgDir = cd </> takeDirectory fp
158 let pkgDir = cd </> takeDirectory fp
@@ -155,9 +178,13 @@ documentPkg fp =
155 Left msg -> do putStrLn msg
178 Left msg -> do putStrLn msg
156 exitWith (ExitFailure 1)
179 exitWith (ExitFailure 1)
181+-- ------------------------------------------------------------------- [ Test ]
158-- | Build a package with a sythesized main function that runs the tests
183-- | Build a package with a sythesized main function that runs the tests
184+testPkg :: [Opt] -- ^ Command line options.
159−testPkg :: FilePath -> IO ()
185+ -> FilePath -- ^ Path to ipkg file.
160−testPkg fp
187+testPkg copts fp
161 = do pkgdesc <- parseDesc fp
188 = do pkgdesc <- parseDesc fp
162 ok <- mapM (testLib True (pkgname pkgdesc)) (libdeps pkgdesc)
189 ok <- mapM (testLib True (pkgname pkgdesc)) (libdeps pkgdesc)
163 when (and ok) $
190 when (and ok) $
@@ -188,6 +215,8 @@ testPkg fp
188 Just _ -> exitWith (ExitFailure 1)
215 Just _ -> exitWith (ExitFailure 1)
189 _ -> return ()
216 _ -> return ()
218+-- ----------------------------------------------------------- [ Installation ]
191-- | Install package
220-- | Install package
192installPkg :: PkgDesc -> IO ()
221installPkg :: PkgDesc -> IO ()
193installPkg pkgdesc
222installPkg pkgdesc
@@ -254,7 +283,7 @@ installIBC p m = do let f = toIBCFile m
254installIdx :: String -> IO ()
283installIdx :: String -> IO ()
255installIdx p = do d <- getTargetDir
284installIdx p = do d <- getTargetDir
256 let f = pkgIndex p
285 let f = pkgIndex p
257− let destdir = d </> p
286+ let destdir = d </> p
258 putStrLn $ "Installing " ++ f ++ " to " ++ destdir
287 putStrLn $ "Installing " ++ f ++ " to " ++ destdir
259 createDirectoryIfMissing True destdir
288 createDirectoryIfMissing True destdir
260 copyFile f (destdir </> takeFileName f)
289 copyFile f (destdir </> takeFileName f)