summaryrefslogtreecommitdiff
path: root/src/compiler/GF/Compile.hs
diff options
context:
space:
mode:
authormeng wong <mengwong@pobox.com>2017-08-19 14:27:07 +0300
committerMeng Weng Wong <mengwong@pobox.com>2018-07-22 00:04:07 -0700
commit8a14912ee3b692bc578465b6920575f5d7b11b4c (patch)
treee83be5ddaab3f2fed7f96544aa8445f383b4e441 /src/compiler/GF/Compile.hs
parentcd1942a8454d569363b201f2345953e648ec9b53 (diff)
GF_LIB_PATH can now be path1:path2:path3, not just path1
Traditionally, GF_LIB_PATH points to something like `.../share/ghc-8.0.2-x86_64/gf-3.9/lib` and if you want prelude and alltenses and present, you add a `--# -path=.:present` compiler pragma to the top of your .gf file But if you are developing some kind of application grammar library or contrib of your own, you might find yourself repeating your library path at the top of all your .gf files. After painstakingly maintaining the same library path at the top of all your .gf files, you might say, let's factor this out into GF_LIB_PATH. Then you might then find to your surprise that GF_LIB_PATH doesn't accept the usual colon:separated:path notation familiar from, say, unix PATH and MANPATH. This patch allows you to define `GF_LIB_PATH=gf-3.9.lib:$HOME/gf-contrib/whatever/lib` in a more natural way. If you are an RGL hacker and have your own version of the RGL tree sitting somewhere, you should be able to have both paths in the GF_LIB_PATH, for added convenience. This minor convenience will probably lead to obscure bugs and great frustration when you find that your changes are mysteriously not being picked up by GF; so keep this in mind and use it cautiously. This caution should probably sit in the documentation somewhere. A subsequent commit will do that. If you use zsh, you can do this to quickly build up a big GF_LIB_PATH: % gf_lib_path=( $HOME/src/GF/lib/src/{api,abstract,common,english,api/libraryBrowser,prelude,..} ) % typeset -xT GF_LIB_PATH gf_lib_path
Diffstat (limited to 'src/compiler/GF/Compile.hs')
-rw-r--r--src/compiler/GF/Compile.hs28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/compiler/GF/Compile.hs b/src/compiler/GF/Compile.hs
index 964165148..95a05dc09 100644
--- a/src/compiler/GF/Compile.hs
+++ b/src/compiler/GF/Compile.hs
@@ -14,7 +14,7 @@ import GF.Infra.UseIO(IOE,FullPath,liftIO,getLibraryDirectory,putIfVerb,
justModuleName,extendPathEnv,putStrE,putPointE)
import GF.Data.Operations(raise,(+++),err)
-import Control.Monad(foldM,when,(<=<))
+import Control.Monad(foldM,when,(<=<),filterM,liftM)
import GF.System.Directory(doesFileExist,getModificationTime)
import System.FilePath((</>),isRelative,dropFileName)
import qualified Data.Map as Map(empty,insert,elems) --lookup
@@ -78,10 +78,14 @@ compileModule opts1 env@(_,rfs) file =
do file <- getRealFile file
opts0 <- getOptionsFromFile file
let curr_dir = dropFileName file
- lib_dir <- getLibraryDirectory (addOptions opts0 opts1)
- let opts = addOptions (fixRelativeLibPaths curr_dir lib_dir opts0) opts1
+ lib_dirs <- getLibraryDirectory (addOptions opts0 opts1)
+ let opts = addOptions (fixRelativeLibPaths curr_dir lib_dirs opts0) opts1
+-- putIfVerb opts $ "curr_dir:" +++ show curr_dir ----
+-- putIfVerb opts $ "lib_dir:" +++ show lib_dirs ----
ps0 <- extendPathEnv opts
let ps = nub (curr_dir : ps0)
+-- putIfVerb opts $ "options from file: " ++ show opts0
+-- putIfVerb opts $ "augmented options: " ++ show opts
putIfVerb opts $ "module search path:" +++ show ps ----
files <- getAllFiles opts ps rfs file
putIfVerb opts $ "files to read:" +++ show files ----
@@ -94,13 +98,17 @@ compileModule opts1 env@(_,rfs) file =
if exists
then return file
else if isRelative file
- then do lib_dir <- getLibraryDirectory opts1
- let file1 = lib_dir </> file
- exists <- doesFileExist file1
- if exists
- then return file1
- else raise (render ("None of these files exists:" $$ nest 2 (file $$ file1)))
- else raise (render ("File" <+> file <+> "does not exist."))
+ then do
+ lib_dirs <- getLibraryDirectory opts1
+ let candidates = [ lib_dir </> file | lib_dir <- lib_dirs ]
+ putIfVerb opts1 (render ("looking for: " $$ nest 2 candidates))
+ file1s <- filterM doesFileExist candidates
+ case length file1s of
+ 0 -> raise (render ("Unable to find: " $$ nest 2 candidates))
+ 1 -> do return $ head file1s
+ _ -> do putIfVerb opts1 ("matched multiple candidates: " +++ show file1s)
+ return $ head file1s
+ else raise (render ("File" <+> file <+> "does not exist"))
compileOne' :: Options -> CompileEnv -> FullPath -> IOE CompileEnv
compileOne' opts env@(gr,_) = extendCompileEnv env <=< compileOne opts gr