summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkrasimir <krasimir@chalmers.se>2009-05-20 13:23:34 +0000
committerkrasimir <krasimir@chalmers.se>2009-05-20 13:23:34 +0000
commitb45bdaefec1778f1557a8b8ba3e2602d033621bf (patch)
tree0a7c52cf192c62ab4cda989fffbf6632529d46fa
parent878ad278b5c6a5f168c6588d154e4dd4ce3fe862 (diff)
simpler algorithm for file searching in the compiler. should be equivalent to the previous one
-rw-r--r--src/GF/Compile.hs5
-rw-r--r--src/GF/Infra/UseIO.hs19
2 files changed, 14 insertions, 10 deletions
diff --git a/src/GF/Compile.hs b/src/GF/Compile.hs
index 4e16e9121..4b63c5c2e 100644
--- a/src/GF/Compile.hs
+++ b/src/GF/Compile.hs
@@ -118,10 +118,7 @@ compileModule opts1 env file = do
opts0 <- getOptionsFromFile file
let opts = addOptions opts0 opts1
let fdir = dropFileName file
- let ps0 = flag optLibraryPath opts
- ps1 <- ioeIO $ extendPathEnv opts $ fdir : ps0
- let ps2 = ps1 ++ map (fdir </>) ps0
- ps <- ioeIO $ fmap nub $ mapM canonicalizePath ps2
+ ps <- ioeIO $ extendPathEnv opts fdir
ioeIO $ putIfVerb opts $ "module search path:" +++ show ps ----
let (_,sgr,rfs) = env
files <- getAllFiles opts ps rfs file
diff --git a/src/GF/Infra/UseIO.hs b/src/GF/Infra/UseIO.hs
index ea1ebf53d..e8528fc3d 100644
--- a/src/GF/Infra/UseIO.hs
+++ b/src/GF/Infra/UseIO.hs
@@ -30,6 +30,7 @@ import Text.Printf
import Control.Monad
import Control.Exception(evaluate)
import qualified Data.ByteString.Char8 as BS
+import Data.List(nub)
putShow' :: Show a => (c -> a) -> c -> IO ()
putShow' f = putStrLn . show . length . show . f
@@ -64,15 +65,21 @@ getLibraryPath opts =
(getEnv gfLibraryPath)
(\ex -> getDataDir >>= \path -> return (path </> "lib"))
+getGrammarPath :: Options -> IO [FilePath]
+getGrammarPath opts = do
+ let ss1 = flag optLibraryPath opts
+ ss2 <- catch (fmap splitSearchPath $ getEnv gfGrammarPathVar) (\_ -> return ["prelude","."]) -- e.g. GF_GRAMMAR_PATH
+ return (ss1 ++ ss2)
+
-- | extends the search path with the
-- 'gfLibraryPath' and 'gfGrammarPathVar'
-- environment variables. Returns only existing paths.
-extendPathEnv :: Options -> [FilePath] -> IO [FilePath]
-extendPathEnv opts ps = do
- b <- getLibraryPath opts -- e.g. GF_LIB_PATH
- s <- catch (getEnv gfGrammarPathVar) (const (return "")) -- e.g. GF_GRAMMAR_PATH
- let ss = ps ++ splitSearchPath s
- liftM concat $ mapM allSubdirs $ ss ++ [b </> s | s <- ss ++ ["prelude"]]
+extendPathEnv :: Options -> FilePath -> IO [FilePath]
+extendPathEnv opts fdir = do
+ b <- getLibraryPath opts -- e.g. GF_LIB_PATH
+ ss <- getGrammarPath opts -- e.g. GF_GRAMMAR_PATH
+ ps <- liftM (nub . concat) $ mapM allSubdirs $ ss ++ [b </> s | s <- ss] ++ [fdir </> s | s <- ss]
+ mapM canonicalizePath ps
where
allSubdirs :: FilePath -> IO [FilePath]
allSubdirs [] = return [[]]