on master help sign in
Added `--sourcepath` option
769301bAhmad Salim Al-Sibahi
CHANGELOG.md+2
@@ -34,6 +34,8 @@
34 implicits in the output of `:doc`. This is tested for in `docs005`.
34 implicits in the output of `:doc`. This is tested for in `docs005`.
35
35
36* New command line flag `--info` that displays information about the installation.
36* 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.
37## Miscellaneous updates
39## Miscellaneous updates
38
40
39* 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`.
41* 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
97generator. The format of `<ARG>` is dependent on the selected backend.
97generator. The format of `<ARG>` is dependent on the selected backend.
98
98
99Further, Idris does support multiple include paths. The CLI option
99Further, 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
101option can be used multiple times. This is a cleaner option when you
101option can be used multiple times. This is a cleaner option when you
102wish to add single directories to the `IDRIS_LIBRARY_PATH` than
102wish to add single directories to the `IDRIS_LIBRARY_PATH` than
103ammending `IDRIS_LIBRARY_PATH` directly.
103ammending `IDRIS_LIBRARY_PATH` directly.
104+To add directories to the source search path, use the `--sourcepath <dir>` option.
104
105
105Moreover, rather than using `TARGET` the CLI option `--ibcsubdir` can
106Moreover, rather than using `TARGET` the CLI option `--ibcsubdir` can
106be used to direct where built IBC files are placed.
107be 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.
59 -V,--verbose Loud verbosity
59 -V,--verbose Loud verbosity
60 --ibcsubdir FILE Write IBC files into sub directory
60 --ibcsubdir FILE Write IBC files into sub directory
61 -i,--idrispath ARG Add directory to the list of import paths
61 -i,--idrispath ARG Add directory to the list of import paths
62+ --sourcepath ARG Add directory to the list of source search paths
62 -p,--package ARG Add package as a dependency
63 -p,--package ARG Add package as a dependency
63 --port PORT REPL TCP port
64 --port PORT REPL TCP port
64 --build IPKG Build package
65 --build IPKG Build package
src/Idris/AbsSyntax.hs+21
@@ -1064,6 +1064,23 @@ allImportDirs = do i <- getIState
1064 let optdirs = opt_importdirs (idris_options i)
1064 let optdirs = opt_importdirs (idris_options i)
1065 return ("." : reverse optdirs)
1065 return ("." : reverse optdirs)
1066
1066
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+
1067colourise :: Idris Bool
1084colourise :: Idris Bool
1068colourise = do i <- getIState
1085colourise = do i <- getIState
1069 return $ idris_colourRepl i
1086 return $ idris_colourRepl i
@@ -2520,6 +2537,10 @@ getImportDir :: Opt -> Maybe String
2520getImportDir (ImportDir str) = Just str
2537getImportDir (ImportDir str) = Just str
2521getImportDir _ = Nothing
2538getImportDir _ = Nothing
2522
2539
2540+getSourceDir :: Opt -> Maybe String
2541+getSourceDir (SourceDir str) = Just str
2542+getSourceDir _ = Nothing
2543+
2523getPkgDir :: Opt -> Maybe String
2544getPkgDir :: Opt -> Maybe String
2524getPkgDir (Pkg str) = Just str
2545getPkgDir (Pkg str) = Just str
2525getPkgDir _ = Nothing
2546getPkgDir _ = Nothing
src/Idris/AbsSyntaxTree.hs+4
@@ -103,6 +103,7 @@ data IOption = IOption {
103 , opt_outputTy :: OutputType
103 , opt_outputTy :: OutputType
104 , opt_ibcsubdir :: FilePath
104 , opt_ibcsubdir :: FilePath
105 , opt_importdirs :: [FilePath]
105 , opt_importdirs :: [FilePath]
106+ , opt_sourcedirs :: [FilePath]
106 , opt_triple :: String
107 , opt_triple :: String
107 , opt_cpu :: String
108 , opt_cpu :: String
108 , opt_cmdline :: [Opt] -- ^ remember whole command line
109 , opt_cmdline :: [Opt] -- ^ remember whole command line
@@ -131,6 +132,7 @@ defaultOpts = IOption { opt_logLevel = 0
131 , opt_outputTy = Executable
132 , opt_outputTy = Executable
132 , opt_ibcsubdir = ""
133 , opt_ibcsubdir = ""
133 , opt_importdirs = []
134 , opt_importdirs = []
135+ , opt_sourcedirs = []
134 , opt_triple = ""
136 , opt_triple = ""
135 , opt_cpu = ""
137 , opt_cpu = ""
136 , opt_cmdline = []
138 , opt_cmdline = []
@@ -356,6 +358,7 @@ data IBCWrite = IBCFix FixDecl
356 | IBCKeyword String
358 | IBCKeyword String
357 | IBCImport (Bool, FilePath) -- ^ True = import public
359 | IBCImport (Bool, FilePath) -- ^ True = import public
358 | IBCImportDir FilePath
360 | IBCImportDir FilePath
361+ | IBCSourceDir FilePath
359 | IBCObj Codegen FilePath
362 | IBCObj Codegen FilePath
360 | IBCLib Codegen String
363 | IBCLib Codegen String
361 | IBCCGFlag Codegen String
364 | IBCCGFlag Codegen String
@@ -519,6 +522,7 @@ data Opt = Filename String
519 | Port String -- ^ REPL TCP port
522 | Port String -- ^ REPL TCP port
520 | IBCSubDir String
523 | IBCSubDir String
521 | ImportDir String
524 | ImportDir String
525+ | SourceDir String
522 | PkgBuild String
526 | PkgBuild String
523 | PkgInstall String
527 | PkgInstall String
524 | PkgClean String
528 | PkgClean String
src/Idris/Chaser.hs+2−2
@@ -98,9 +98,9 @@ getImports acc (f : fs) = do
98 i <- getIState
98 i <- getIState
99 let file = extractFileName f
99 let file = extractFileName f
100 ibcsd <- valIBCSubDir i
100 ibcsd <- valIBCSubDir i
101− ids <- allImportDirs
102 idrisCatch (do
101 idrisCatch (do
102+ srcds <- allSourceDirs
103− fp <- findImport ["."] ibcsd file
103+ fp <- findImport srcds ibcsd file
104 let parsef = fname fp
104 let parsef = fname fp
105 case lookup parsef acc of
105 case lookup parsef acc of
106 Just _ -> getImports acc fs
106 Just _ -> getImports acc fs
src/Idris/CmdOptions.hs+1
@@ -132,6 +132,7 @@ parseFlags = many $
132
132
133 <|> (IBCSubDir <$> strOption (long "ibcsubdir" <> metavar "FILE" <> help "Write IBC files into sub directory"))
133 <|> (IBCSubDir <$> strOption (long "ibcsubdir" <> metavar "FILE" <> help "Write IBC files into sub directory"))
134 <|> (ImportDir <$> strOption (short 'i' <> long "idrispath" <> help "Add directory to the list of import paths"))
134 <|> (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"))
135
136
136 <|> flag' WarnOnly (long "warn")
137 <|> flag' WarnOnly (long "warn")
137
138
src/Idris/IBC.hs+11−2
@@ -49,7 +49,7 @@ import Codec.Archive.Zip
49import Debug.Trace
49import Debug.Trace
50
50
51ibcVersion :: Word16
51ibcVersion :: Word16
52−ibcVersion = 146
52+ibcVersion = 147
53
53
54-- | When IBC is being loaded - we'll load different things (and omit
54-- | When IBC is being loaded - we'll load different things (and omit
55-- different structures/definitions) depending on which phase we're in.
55-- different structures/definitions) depending on which phase we're in.
@@ -63,6 +63,7 @@ data IBCFile = IBCFile {
63 , ibc_reachablenames :: ![Name]
63 , ibc_reachablenames :: ![Name]
64 , ibc_imports :: ![(Bool, FilePath)]
64 , ibc_imports :: ![(Bool, FilePath)]
65 , ibc_importdirs :: ![FilePath]
65 , ibc_importdirs :: ![FilePath]
66+ , ibc_sourcedirs :: ![FilePath]
66 , ibc_implicits :: ![(Name, [PArg])]
67 , ibc_implicits :: ![(Name, [PArg])]
67 , ibc_fixes :: ![FixDecl]
68 , ibc_fixes :: ![FixDecl]
68 , ibc_statics :: ![(Name, [Bool])]
69 , ibc_statics :: ![(Name, [Bool])]
@@ -115,7 +116,7 @@ deriving instance Binary IBCFile
115!-}
116!-}
116
117
117initIBC :: IBCFile
118initIBC :: IBCFile
118−initIBC = IBCFile ibcVersion "" [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] Nothing [] [] [] [] [] [] [] [] [] []
119+initIBC = IBCFile ibcVersion "" [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] Nothing [] [] [] [] [] [] [] [] [] []
119
120
120hasValidIBCVersion :: FilePath -> Idris Bool
121hasValidIBCVersion :: FilePath -> Idris Bool
121hasValidIBCVersion fp = do
122hasValidIBCVersion fp = do
@@ -167,6 +168,7 @@ entries i = catMaybes [Just $ toEntry "ver" 0 (encode $ ver i),
167 makeEntry "sourcefile" (sourcefile i),
168 makeEntry "sourcefile" (sourcefile i),
168 makeEntry "ibc_imports" (ibc_imports i),
169 makeEntry "ibc_imports" (ibc_imports i),
169 makeEntry "ibc_importdirs" (ibc_importdirs i),
170 makeEntry "ibc_importdirs" (ibc_importdirs i),
171+ makeEntry "ibc_sourcedirs" (ibc_sourcedirs i),
170 makeEntry "ibc_implicits" (ibc_implicits i),
172 makeEntry "ibc_implicits" (ibc_implicits i),
171 makeEntry "ibc_fixes" (ibc_fixes i),
173 makeEntry "ibc_fixes" (ibc_fixes i),
172 makeEntry "ibc_statics" (ibc_statics i),
174 makeEntry "ibc_statics" (ibc_statics i),
@@ -291,6 +293,7 @@ ibc i (IBCSyntax n) f = return f { ibc_syntax = n : ibc_syntax f }
291ibc i (IBCKeyword n) f = return f { ibc_keywords = n : ibc_keywords f }
293ibc i (IBCKeyword n) f = return f { ibc_keywords = n : ibc_keywords f }
292ibc i (IBCImport n) f = return f { ibc_imports = n : ibc_imports f }
294ibc i (IBCImport n) f = return f { ibc_imports = n : ibc_imports f }
293ibc i (IBCImportDir n) f = return f { ibc_importdirs = n : ibc_importdirs f }
295ibc 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 }
294ibc i (IBCObj tgt n) f = return f { ibc_objs = (tgt, n) : ibc_objs f }
297ibc i (IBCObj tgt n) f = return f { ibc_objs = (tgt, n) : ibc_objs f }
295ibc i (IBCLib tgt n) f = return f { ibc_libs = (tgt, n) : ibc_libs f }
298ibc i (IBCLib tgt n) f = return f { ibc_libs = (tgt, n) : ibc_libs f }
296ibc i (IBCCGFlag tgt n) f = return f { ibc_cgflags = (tgt, n) : ibc_cgflags f }
299ibc i (IBCCGFlag tgt n) f = return f { ibc_cgflags = (tgt, n) : ibc_cgflags f }
@@ -382,6 +385,7 @@ process reexp phase archive fn = do
382 srcok <- runIO $ doesFileExist source
385 srcok <- runIO $ doesFileExist source
383 when srcok $ timestampOlder source fn
386 when srcok $ timestampOlder source fn
384 processImportDirs archive
387 processImportDirs archive
388+ processSourceDirs archive
385 processImports reexp phase archive
389 processImports reexp phase archive
386 processImplicits archive
390 processImplicits archive
387 processInfix archive
391 processInfix archive
@@ -492,6 +496,11 @@ processImportDirs ar = do
492 fs <- getEntry [] "ibc_importdirs" ar
496 fs <- getEntry [] "ibc_importdirs" ar
493 mapM_ addImportDir fs
497 mapM_ addImportDir fs
494
498
499+processSourceDirs :: Archive -> Idris ()
500+processSourceDirs ar = do
501+ fs <- getEntry [] "ibc_sourcedirs" ar
502+ mapM_ addSourceDir fs
503+
495processImports :: Bool -> IBCPhase -> Archive -> Idris ()
504processImports :: Bool -> IBCPhase -> Archive -> Idris ()
496processImports reexp phase ar = do
505processImports reexp phase ar = do
497 fs <- getEntry [] "ibc_imports" ar
506 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
71 ibc <- runIO $ doesFileExist' ibcp
71 ibc <- runIO $ doesFileExist' ibcp
72 idr <- runIO $ doesFileExist' idrp
72 idr <- runIO $ doesFileExist' idrp
73 lidr <- runIO $ doesFileExist' lidrp
73 lidr <- runIO $ doesFileExist' lidrp
74−-- when idr $ putStrLn $ idrp ++ " ok"
75−-- when lidr $ putStrLn $ lidrp ++ " ok"
76−-- when ibc $ putStrLn $ ibcp ++ " ok"
77 let isrc = if lidr
74 let isrc = if lidr
78 then LIDR lidrp
75 then LIDR lidrp
79 else IDR idrp
76 else IDR idrp
src/Idris/REPL.hs+2
@@ -1692,6 +1692,7 @@ idrisMain opts =
1692 let output = opt getOutput opts
1692 let output = opt getOutput opts
1693 let ibcsubdir = opt getIBCSubDir opts
1693 let ibcsubdir = opt getIBCSubDir opts
1694 let importdirs = opt getImportDir opts
1694 let importdirs = opt getImportDir opts
1695+ let sourcedirs = opt getSourceDir opts
1695 let bcs = opt getBC opts
1696 let bcs = opt getBC opts
1696 let pkgdirs = opt getPkgDir opts
1697 let pkgdirs = opt getPkgDir opts
1697 -- Set default optimisations
1698 -- Set default optimisations
@@ -1749,6 +1750,7 @@ idrisMain opts =
1749 [] -> setIBCSubDir ""
1750 [] -> setIBCSubDir ""
1750 (d:_) -> setIBCSubDir d
1751 (d:_) -> setIBCSubDir d
1751 setImportDirs importdirs
1752 setImportDirs importdirs
1753+ setSourceDirs sourcedirs
1752
1754
1753 setNoBanner nobanner
1755 setNoBanner nobanner
1754
1756