summaryrefslogtreecommitdiff
path: root/src/GF/Infra
diff options
context:
space:
mode:
authorkrasimir <krasimir@chalmers.se>2009-04-30 07:56:22 +0000
committerkrasimir <krasimir@chalmers.se>2009-04-30 07:56:22 +0000
commitae6e8ee401e170224312d78cf43e0e51e49e9976 (patch)
treedea18f1c83277fae2387d236b864458a7e14c774 /src/GF/Infra
parentc6ac4801ad271ac2b7c093ce77172930529a1fb1 (diff)
added -gf-lib-path option which overides the value of GF_LIB_PATH
Diffstat (limited to 'src/GF/Infra')
-rw-r--r--src/GF/Infra/Option.hs7
-rw-r--r--src/GF/Infra/UseIO.hs18
2 files changed, 16 insertions, 9 deletions
diff --git a/src/GF/Infra/Option.hs b/src/GF/Infra/Option.hs
index a26237f3f..b312dbd66 100644
--- a/src/GF/Infra/Option.hs
+++ b/src/GF/Infra/Option.hs
@@ -153,6 +153,7 @@ data Flags = Flags {
optLexicalCats :: Set String,
optOutputFile :: Maybe FilePath,
optOutputDir :: Maybe FilePath,
+ optGFLibPath :: Maybe FilePath,
optRecomp :: Recomp,
optPrinter :: [Printer],
optProb :: Bool,
@@ -245,6 +246,7 @@ defaultFlags = Flags {
optLexicalCats = Set.empty,
optOutputFile = Nothing,
optOutputDir = Nothing,
+ optGFLibPath = Nothing,
optRecomp = RecompIfNewer,
optPrinter = [],
optProb = False,
@@ -307,7 +309,9 @@ optDescr =
Option ['o'] ["output-file"] (ReqArg outFile "FILE")
"Save output in FILE (default is out.X, where X depends on output format.",
Option ['D'] ["output-dir"] (ReqArg outDir "DIR")
- "Save output files (other than .gfc files) in DIR.",
+ "Save output files (other than .gfo files) in DIR.",
+ Option [] ["gf-lib-path"] (ReqArg gfLibPath "DIR")
+ "Overides the value of GF_LIB_PATH.",
Option [] ["src","force-recomp"] (NoArg (recomp AlwaysRecomp))
"Always recompile from source.",
Option [] ["gfo","recomp-if-newer"] (NoArg (recomp RecompIfNewer))
@@ -383,6 +387,7 @@ optDescr =
lexicalCat x = set $ \o -> o { optLexicalCats = foldr Set.insert (optLexicalCats o) (splitBy (==',') x) }
outFile x = set $ \o -> o { optOutputFile = Just x }
outDir x = set $ \o -> o { optOutputDir = Just x }
+ gfLibPath x = set $ \o -> o { optGFLibPath = Just x }
recomp x = set $ \o -> o { optRecomp = x }
printer x = set $ \o -> o { optPrinter = x : optPrinter o }
prob x = set $ \o -> o { optProb = x }
diff --git a/src/GF/Infra/UseIO.hs b/src/GF/Infra/UseIO.hs
index 550554459..ea1ebf53d 100644
--- a/src/GF/Infra/UseIO.hs
+++ b/src/GF/Infra/UseIO.hs
@@ -56,18 +56,20 @@ type FullPath = String
gfLibraryPath = "GF_LIB_PATH"
gfGrammarPathVar = "GF_GRAMMAR_PATH"
-getLibraryPath :: IO FilePath
-getLibraryPath =
- catch
- (getEnv gfLibraryPath)
- (\ex -> getDataDir >>= \path -> return (path </> "lib"))
+getLibraryPath :: Options -> IO FilePath
+getLibraryPath opts =
+ case flag optGFLibPath opts of
+ Just path -> return path
+ Nothing -> catch
+ (getEnv gfLibraryPath)
+ (\ex -> getDataDir >>= \path -> return (path </> "lib"))
-- | extends the search path with the
-- 'gfLibraryPath' and 'gfGrammarPathVar'
-- environment variables. Returns only existing paths.
-extendPathEnv :: [FilePath] -> IO [FilePath]
-extendPathEnv ps = do
- b <- getLibraryPath -- e.g. GF_LIB_PATH
+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"]]