on master help sign in
Make command line options accessible to package parser.
3eacf1cJan de Muijnck-Hughes
main/Main.hs+6−6
@@ -56,26 +56,26 @@ runIdris opts = do
56 runIO exitSuccess
56 runIO exitSuccess
57 case opt getPkgCheck opts of
57 case opt getPkgCheck opts of
58 [] -> return ()
58 [] -> return ()
59− fs -> do runIO $ mapM_ (checkPkg (WarnOnly `elem` opts) True) fs
59+ fs -> do runIO $ mapM_ (checkPkg opts (WarnOnly `elem` opts) True) fs
60 runIO exitSuccess
60 runIO exitSuccess
61 case opt getPkgClean opts of
61 case opt getPkgClean opts of
62 [] -> return ()
62 [] -> return ()
63− fs -> do runIO $ mapM_ cleanPkg fs
63+ fs -> do runIO $ mapM_ (cleanPkg opts) fs
64 runIO exitSuccess
64 runIO exitSuccess
65 case opt getPkgMkDoc opts of -- IdrisDoc
65 case opt getPkgMkDoc opts of -- IdrisDoc
66 [] -> return ()
66 [] -> return ()
67− fs -> do runIO $ mapM_ documentPkg fs
67+ fs -> do runIO $ mapM_ (documentPkg opts) fs
68 runIO exitSuccess
68 runIO exitSuccess
69 case opt getPkgTest opts of
69 case opt getPkgTest opts of
70 [] -> return ()
70 [] -> return ()
71− fs -> do runIO $ mapM_ testPkg fs
71+ fs -> do runIO $ mapM_ (testPkg opts) fs
72 runIO exitSuccess
72 runIO exitSuccess
73 case opt getPkg opts of
73 case opt getPkg opts of
74 [] -> case opt getPkgREPL opts of
74 [] -> case opt getPkgREPL opts of
75 [] -> idrisMain opts
75 [] -> idrisMain opts
76− [f] -> replPkg f
76+ [f] -> replPkg opts f
77 _ -> ifail "Too many packages"
77 _ -> ifail "Too many packages"
78− fs -> runIO $ mapM_ (buildPkg (WarnOnly `elem` opts)) fs
78+ fs -> runIO $ mapM_ (buildPkg opts (WarnOnly `elem` opts)) fs
79
79
80showver :: IO b
80showver :: IO b
81showver = do putStrLn $ "Idris version " ++ ver
81showver = do putStrLn $ "Idris version " ++ ver
src/Pkg/Package.hs+60−31
@@ -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
41
41
42+-- --------------------------------------------------------- [ Build Packages ]
43+
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)
48+ -> IO ()
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
67
72
73+-- --------------------------------------------------------- [ Check Packages ]
74+
68-- | Type check packages only
75-- | Type check packages only
69--
76--
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.
75− -> IO ()
83+ -> IO ()
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 ()
90
98
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)
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
107
100
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+
108− where toPath n = foldl1' (</>) $ splitOn "." n
124+ where toPath n = foldl1' (</>) $ splitOn "." n
125+
126+-- --------------------------------------------------------------- [ Cleaning ]
109
127
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.
112 -> IO ()
131 -> IO ()
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
123
142
143+-- ------------------------------------------------------ [ Generate IdrisDoc ]
144+
145+
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
127--
149--
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.
131 -> IO ()
154 -> IO ()
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)
157
180
181+-- ------------------------------------------------------------------- [ Test ]
182+
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.
186+ -> IO ()
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 ()
190
217
218+-- ----------------------------------------------------------- [ Installation ]
219+
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)