@@ -39,9 +39,14 @@ import IRTS.System
3939-- * invoke idris on each module, with idris_opts
4040-- * install everything into datadir/pname, if install flag is set
4141
42+-- --------------------------------------------------------- [ Build Packages ]
43+
4244-- | Run the package through the idris compiler.
43−buildPkg :: Bool -> (Bool, FilePath) -> IO ()
44−buildPkg warnonly (install, fp)
45+buildPkg :: [Opt] -- ^ Command line options
46+ -> Bool -- ^ Provide Warnings
47+ -> (Bool, FilePath) -- ^ (Should we install, Location of iPKG file)
48+ -> IO ()
49+buildPkg copts warnonly (install, fp)
4550 = do pkgdesc <- parseDesc fp
4651 dir <- getCurrentDirectory
4752 let idx = PkgIndex (pkgIndex (pkgname pkgdesc))
@@ -65,15 +70,18 @@ buildPkg warnonly (install, fp)
6570 _ -> return ()
6671 when install $ installPkg pkgdesc
6772
73+-- --------------------------------------------------------- [ Check Packages ]
74+
6875-- | Type check packages only
6976--
7077-- This differs from build in that executables are not built, if the
7178-- package contains an executable.
72−checkPkg :: Bool -- ^ Show Warnings
73− -> Bool -- ^ quit on failure
74− -> FilePath -- ^ Path to ipkg file.
75− -> IO ()
76−checkPkg warnonly quit fpath
79+checkPkg :: [Opt] -- ^ Command line Options
80+ -> Bool -- ^ Show Warnings
81+ -> Bool -- ^ quit on failure
82+ -> FilePath -- ^ Path to ipkg file.
83+ -> IO ()
84+checkPkg copts warnonly quit fpath
7785 = do pkgdesc <- parseDesc fpath
7886 ok <- mapM (testLib warnonly (pkgname pkgdesc)) (libdeps pkgdesc)
7987 when (and ok) $
@@ -88,29 +96,40 @@ checkPkg warnonly quit fpath
8896 Just _ -> exitWith (ExitFailure 1)
8997 _ -> return ()
9098
91−-- | Check a package and start a 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)
99− putIState orig
100− dir <- runIO $ getCurrentDirectory
101− runIO $ setCurrentDirectory $ dir </> sourcedir pkgdesc
102−
103− if (f /= "")
104− then idrisMain ((Filename f) : opts)
105− else iputStrLn "Can't start REPL: no main module given"
106− runIO $ setCurrentDirectory dir
99+-- ------------------------------------------------------------------- [ REPL ]
107100
108− where toPath n = foldl1' (</>) $ splitOn "." n
101+-- | Check a package and start a REPL.
102+--
103+-- This function only works with packages that have a main module.
104+--
105+replPkg :: [Opt] -- ^ Command line Options
106+ -> FilePath -- ^ Path to ipkg file.
107+ -> Idris ()
108+replPkg copts fp = do
109+ orig <- getIState
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)
115+ putIState orig
116+ dir <- runIO $ getCurrentDirectory
117+ runIO $ setCurrentDirectory $ dir </> sourcedir pkgdesc
118+
119+ if (f /= "")
120+ then idrisMain ((Filename f) : opts)
121+ else iputStrLn "Can't start REPL: no main module given"
122+ runIO $ setCurrentDirectory dir
123+
124+ where toPath n = foldl1' (</>) $ splitOn "." n
125+
126+-- --------------------------------------------------------------- [ Cleaning ]
109127
110128-- | Clean Package build files
111−cleanPkg :: FilePath -- ^ Path to ipkg file.
129+cleanPkg :: [Opt] -- ^ Command line options.
130+ -> FilePath -- ^ Path to ipkg file.
112131 -> IO ()
113−cleanPkg fp
132+cleanPkg copts fp
114133 = do pkgdesc <- parseDesc fp
115134 dir <- getCurrentDirectory
116135 inPkgDir pkgdesc $
@@ -121,15 +140,19 @@ cleanPkg fp
121140 Nothing -> return ()
122141 Just s -> rmExe $ dir </> s
123142
143+-- ------------------------------------------------------ [ Generate IdrisDoc ]
144+
145+
124146-- | Generate IdrisDoc for package
125147-- TODO: Handle case where module does not contain a matching namespace
126148-- E.g. from prelude.ipkg: IO, Prelude.Chars, Builtins
127149--
128150-- Issue number #1572 on the issue tracker
129151-- https://github.com/idris-lang/Idris-dev/issues/1572
130−documentPkg :: FilePath -- ^ Path to .ipkg file.
152+documentPkg :: [Opt] -- ^ Command line options.
153+ -> FilePath -- ^ Path to ipkg file.
131154 -> IO ()
132−documentPkg fp =
155+documentPkg copts fp =
133156 do pkgdesc <- parseDesc fp
134157 cd <- getCurrentDirectory
135158 let pkgDir = cd </> takeDirectory fp
@@ -155,9 +178,13 @@ documentPkg fp =
155178 Left msg -> do putStrLn msg
156179 exitWith (ExitFailure 1)
157180
181+-- ------------------------------------------------------------------- [ Test ]
182+
158183-- | Build a package with a sythesized main function that runs the tests
159−testPkg :: FilePath -> IO ()
160−testPkg fp
184+testPkg :: [Opt] -- ^ Command line options.
185+ -> FilePath -- ^ Path to ipkg file.
186+ -> IO ()
187+testPkg copts fp
161188 = do pkgdesc <- parseDesc fp
162189 ok <- mapM (testLib True (pkgname pkgdesc)) (libdeps pkgdesc)
163190 when (and ok) $
@@ -188,6 +215,8 @@ testPkg fp
188215 Just _ -> exitWith (ExitFailure 1)
189216 _ -> return ()
190217
218+-- ----------------------------------------------------------- [ Installation ]
219+
191220-- | Install package
192221installPkg :: PkgDesc -> IO ()
193222installPkg pkgdesc
@@ -254,7 +283,7 @@ installIBC p m = do let f = toIBCFile m
254283installIdx :: String -> IO ()
255284installIdx p = do d <- getTargetDir
256285 let f = pkgIndex p
257− let destdir = d </> p
286+ let destdir = d </> p
258287 putStrLn $ "Installing " ++ f ++ " to " ++ destdir
259288 createDirectoryIfMissing True destdir
260289 copyFile f (destdir </> takeFileName f)