on master help sign in
Added `--sourcepath` option

Allows adding more directories to the search path when the chaser searches for source files.

commit769301b1a02534e653542e009feb0cb7cb0e6c1c authorAhmad Salim Al-Sibahi <asal@itu.dk> dateFri 26 Aug 2016, 08:21 (10 years ago) parent8d42e43
10 files changed+46−8
CHANGELOG.md+2 docs/reference/compilation.rst+2−1 man/idris.1+1 src/Idris/AbsSyntax.hs+21 src/Idris/AbsSyntaxTree.hs+4 src/Idris/Chaser.hs+2−2 src/Idris/CmdOptions.hs+1 src/Idris/IBC.hs+11−2 src/Idris/Imports.hs−3 src/Idris/REPL.hs+2
CHANGELOG.md+2
@@ -34,6 +34,8 @@
3434 implicits in the output of `:doc`. This is tested for in `docs005`.
3535
3636* New command line flag `--info` that displays information about the installation.
37+
38+* New command line flag `--sourcepath <dir>` that allows adding directories to the source search path.
3739## Miscellaneous updates
3840
3941* The test suite now uses [tasty-golden](https://hackage.haskell.org/package/tasty-golden). New tests must be registered in `test/TestData.hs`, as explained in the relevant `README.md`.
docs/reference/compilation.rst+2−1
@@ -97,10 +97,11 @@ The option `--cg-opt <ARG>` can be used to pass options to the code
9797generator. The format of `<ARG>` is dependent on the selected backend.
9898
9999Further, Idris does support multiple include paths. The CLI option
100−`-i <dir>` allows you to add a directory to the search path; this
100+`-i <dir>` allows you to add a directory to the library search path; this
101101option can be used multiple times. This is a cleaner option when you
102102wish to add single directories to the `IDRIS_LIBRARY_PATH` than
103103ammending `IDRIS_LIBRARY_PATH` directly.
104+To add directories to the source search path, use the `--sourcepath <dir>` option.
104105
105106Moreover, rather than using `TARGET` the CLI option `--ibcsubdir` can
106107be used to direct where built IBC files are placed.
man/idris.1+1
@@ -59,6 +59,7 @@ should not necessarily be seen as production ready nor for industrial use.
5959 -V,--verbose Loud verbosity
6060 --ibcsubdir FILE Write IBC files into sub directory
6161 -i,--idrispath ARG Add directory to the list of import paths
62+ --sourcepath ARG Add directory to the list of source search paths
6263 -p,--package ARG Add package as a dependency
6364 --port PORT REPL TCP port
6465 --build IPKG Build package
src/Idris/AbsSyntax.hs+21
@@ -1064,6 +1064,23 @@ allImportDirs = do i <- getIState
10641064 let optdirs = opt_importdirs (idris_options i)
10651065 return ("." : reverse optdirs)
10661066
1067+addSourceDir :: FilePath -> Idris ()
1068+addSourceDir fp = do i <- getIState
1069+ let opts = idris_options i
1070+ let opts' = opts { opt_sourcedirs = nub $ fp : opt_sourcedirs opts }
1071+ putIState $ i { idris_options = opts' }
1072+
1073+setSourceDirs :: [FilePath] -> Idris ()
1074+setSourceDirs fps = do i <- getIState
1075+ let opts = idris_options i
1076+ let opts' = opts { opt_sourcedirs = nub $ fps }
1077+ putIState $ i { idris_options = opts' }
1078+
1079+allSourceDirs :: Idris [FilePath]
1080+allSourceDirs = do i <- getIState
1081+ let optdirs = opt_sourcedirs (idris_options i)
1082+ return ("." : reverse optdirs)
1083+
10671084colourise :: Idris Bool
10681085colourise = do i <- getIState
10691086 return $ idris_colourRepl i
@@ -2520,6 +2537,10 @@ getImportDir :: Opt -> Maybe String
25202537getImportDir (ImportDir str) = Just str
25212538getImportDir _ = Nothing
25222539
2540+getSourceDir :: Opt -> Maybe String
2541+getSourceDir (SourceDir str) = Just str
2542+getSourceDir _ = Nothing
2543+
25232544getPkgDir :: Opt -> Maybe String
25242545getPkgDir (Pkg str) = Just str
25252546getPkgDir _ = Nothing
src/Idris/AbsSyntaxTree.hs+4
@@ -103,6 +103,7 @@ data IOption = IOption {
103103 , opt_outputTy :: OutputType
104104 , opt_ibcsubdir :: FilePath
105105 , opt_importdirs :: [FilePath]
106+ , opt_sourcedirs :: [FilePath]
106107 , opt_triple :: String
107108 , opt_cpu :: String
108109 , opt_cmdline :: [Opt] -- ^ remember whole command line
@@ -131,6 +132,7 @@ defaultOpts = IOption { opt_logLevel = 0
131132 , opt_outputTy = Executable
132133 , opt_ibcsubdir = ""
133134 , opt_importdirs = []
135+ , opt_sourcedirs = []
134136 , opt_triple = ""
135137 , opt_cpu = ""
136138 , opt_cmdline = []
@@ -356,6 +358,7 @@ data IBCWrite = IBCFix FixDecl
356358 | IBCKeyword String
357359 | IBCImport (Bool, FilePath) -- ^ True = import public
358360 | IBCImportDir FilePath
361+ | IBCSourceDir FilePath
359362 | IBCObj Codegen FilePath
360363 | IBCLib Codegen String
361364 | IBCCGFlag Codegen String
@@ -519,6 +522,7 @@ data Opt = Filename String
519522 | Port String -- ^ REPL TCP port
520523 | IBCSubDir String
521524 | ImportDir String
525+ | SourceDir String
522526 | PkgBuild String
523527 | PkgInstall String
524528 | PkgClean String
src/Idris/Chaser.hs+2−2
@@ -98,9 +98,9 @@ getImports acc (f : fs) = do
9898 i <- getIState
9999 let file = extractFileName f
100100 ibcsd <- valIBCSubDir i
101− ids <- allImportDirs
102101 idrisCatch (do
103− fp <- findImport ["."] ibcsd file
102+ srcds <- allSourceDirs
103+ fp <- findImport srcds ibcsd file
104104 let parsef = fname fp
105105 case lookup parsef acc of
106106 Just _ -> getImports acc fs
src/Idris/CmdOptions.hs+1
@@ -132,6 +132,7 @@ parseFlags = many $
132132
133133 <|> (IBCSubDir <$> strOption (long "ibcsubdir" <> metavar "FILE" <> help "Write IBC files into sub directory"))
134134 <|> (ImportDir <$> strOption (short 'i' <> long "idrispath" <> help "Add directory to the list of import paths"))
135+ <|> (SourceDir <$> strOption (long "sourcepath" <> help "Add directory to the list of source search paths"))
135136
136137 <|> flag' WarnOnly (long "warn")
137138
src/Idris/IBC.hs+11−2
@@ -49,7 +49,7 @@ import Codec.Archive.Zip
4949import Debug.Trace
5050
5151ibcVersion :: Word16
52−ibcVersion = 146
52+ibcVersion = 147
5353
5454-- | When IBC is being loaded - we'll load different things (and omit
5555-- different structures/definitions) depending on which phase we're in.
@@ -63,6 +63,7 @@ data IBCFile = IBCFile {
6363 , ibc_reachablenames :: ![Name]
6464 , ibc_imports :: ![(Bool, FilePath)]
6565 , ibc_importdirs :: ![FilePath]
66+ , ibc_sourcedirs :: ![FilePath]
6667 , ibc_implicits :: ![(Name, [PArg])]
6768 , ibc_fixes :: ![FixDecl]
6869 , ibc_statics :: ![(Name, [Bool])]
@@ -115,7 +116,7 @@ deriving instance Binary IBCFile
115116!-}
116117
117118initIBC :: IBCFile
118−initIBC = IBCFile ibcVersion "" [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] Nothing [] [] [] [] [] [] [] [] [] []
119+initIBC = IBCFile ibcVersion "" [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] Nothing [] [] [] [] [] [] [] [] [] []
119120
120121hasValidIBCVersion :: FilePath -> Idris Bool
121122hasValidIBCVersion fp = do
@@ -167,6 +168,7 @@ entries i = catMaybes [Just $ toEntry "ver" 0 (encode $ ver i),
167168 makeEntry "sourcefile" (sourcefile i),
168169 makeEntry "ibc_imports" (ibc_imports i),
169170 makeEntry "ibc_importdirs" (ibc_importdirs i),
171+ makeEntry "ibc_sourcedirs" (ibc_sourcedirs i),
170172 makeEntry "ibc_implicits" (ibc_implicits i),
171173 makeEntry "ibc_fixes" (ibc_fixes i),
172174 makeEntry "ibc_statics" (ibc_statics i),
@@ -291,6 +293,7 @@ ibc i (IBCSyntax n) f = return f { ibc_syntax = n : ibc_syntax f }
291293ibc i (IBCKeyword n) f = return f { ibc_keywords = n : ibc_keywords f }
292294ibc i (IBCImport n) f = return f { ibc_imports = n : ibc_imports f }
293295ibc i (IBCImportDir n) f = return f { ibc_importdirs = n : ibc_importdirs f }
296+ibc i (IBCSourceDir n) f = return f { ibc_sourcedirs = n : ibc_sourcedirs f }
294297ibc i (IBCObj tgt n) f = return f { ibc_objs = (tgt, n) : ibc_objs f }
295298ibc i (IBCLib tgt n) f = return f { ibc_libs = (tgt, n) : ibc_libs f }
296299ibc i (IBCCGFlag tgt n) f = return f { ibc_cgflags = (tgt, n) : ibc_cgflags f }
@@ -382,6 +385,7 @@ process reexp phase archive fn = do
382385 srcok <- runIO $ doesFileExist source
383386 when srcok $ timestampOlder source fn
384387 processImportDirs archive
388+ processSourceDirs archive
385389 processImports reexp phase archive
386390 processImplicits archive
387391 processInfix archive
@@ -492,6 +496,11 @@ processImportDirs ar = do
492496 fs <- getEntry [] "ibc_importdirs" ar
493497 mapM_ addImportDir fs
494498
499+processSourceDirs :: Archive -> Idris ()
500+processSourceDirs ar = do
501+ fs <- getEntry [] "ibc_sourcedirs" ar
502+ mapM_ addSourceDir fs
503+
495504processImports :: Bool -> IBCPhase -> Archive -> Idris ()
496505processImports reexp phase ar = do
497506 fs <- getEntry [] "ibc_imports" ar
src/Idris/Imports.hs−3
@@ -71,9 +71,6 @@ findImport (d:ds) ibcsd fp = do let fp_full = d </> fp
7171 ibc <- runIO $ doesFileExist' ibcp
7272 idr <- runIO $ doesFileExist' idrp
7373 lidr <- runIO $ doesFileExist' lidrp
74−-- when idr $ putStrLn $ idrp ++ " ok"
75−-- when lidr $ putStrLn $ lidrp ++ " ok"
76−-- when ibc $ putStrLn $ ibcp ++ " ok"
7774 let isrc = if lidr
7875 then LIDR lidrp
7976 else IDR idrp
src/Idris/REPL.hs+2
@@ -1692,6 +1692,7 @@ idrisMain opts =
16921692 let output = opt getOutput opts
16931693 let ibcsubdir = opt getIBCSubDir opts
16941694 let importdirs = opt getImportDir opts
1695+ let sourcedirs = opt getSourceDir opts
16951696 let bcs = opt getBC opts
16961697 let pkgdirs = opt getPkgDir opts
16971698 -- Set default optimisations
@@ -1749,6 +1750,7 @@ idrisMain opts =
17491750 [] -> setIBCSubDir ""
17501751 (d:_) -> setIBCSubDir d
17511752 setImportDirs importdirs
1753+ setSourceDirs sourcedirs
17521754
17531755 setNoBanner nobanner
17541756