mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-21 09:02:50 -06:00
added -gf-lib-path option which overides the value of GF_LIB_PATH
This commit is contained in:
@@ -119,7 +119,7 @@ compileModule opts1 env file = do
|
|||||||
let opts = addOptions opts0 opts1
|
let opts = addOptions opts0 opts1
|
||||||
let fdir = dropFileName file
|
let fdir = dropFileName file
|
||||||
let ps0 = flag optLibraryPath opts
|
let ps0 = flag optLibraryPath opts
|
||||||
ps1 <- ioeIO $ extendPathEnv $ fdir : ps0
|
ps1 <- ioeIO $ extendPathEnv opts $ fdir : ps0
|
||||||
let ps2 = ps1 ++ map (fdir </>) ps0
|
let ps2 = ps1 ++ map (fdir </>) ps0
|
||||||
ps <- ioeIO $ fmap nub $ mapM canonicalizePath ps2
|
ps <- ioeIO $ fmap nub $ mapM canonicalizePath ps2
|
||||||
ioeIO $ putIfVerb opts $ "module search path:" +++ show ps ----
|
ioeIO $ putIfVerb opts $ "module search path:" +++ show ps ----
|
||||||
|
|||||||
@@ -153,6 +153,7 @@ data Flags = Flags {
|
|||||||
optLexicalCats :: Set String,
|
optLexicalCats :: Set String,
|
||||||
optOutputFile :: Maybe FilePath,
|
optOutputFile :: Maybe FilePath,
|
||||||
optOutputDir :: Maybe FilePath,
|
optOutputDir :: Maybe FilePath,
|
||||||
|
optGFLibPath :: Maybe FilePath,
|
||||||
optRecomp :: Recomp,
|
optRecomp :: Recomp,
|
||||||
optPrinter :: [Printer],
|
optPrinter :: [Printer],
|
||||||
optProb :: Bool,
|
optProb :: Bool,
|
||||||
@@ -245,6 +246,7 @@ defaultFlags = Flags {
|
|||||||
optLexicalCats = Set.empty,
|
optLexicalCats = Set.empty,
|
||||||
optOutputFile = Nothing,
|
optOutputFile = Nothing,
|
||||||
optOutputDir = Nothing,
|
optOutputDir = Nothing,
|
||||||
|
optGFLibPath = Nothing,
|
||||||
optRecomp = RecompIfNewer,
|
optRecomp = RecompIfNewer,
|
||||||
optPrinter = [],
|
optPrinter = [],
|
||||||
optProb = False,
|
optProb = False,
|
||||||
@@ -307,7 +309,9 @@ optDescr =
|
|||||||
Option ['o'] ["output-file"] (ReqArg outFile "FILE")
|
Option ['o'] ["output-file"] (ReqArg outFile "FILE")
|
||||||
"Save output in FILE (default is out.X, where X depends on output format.",
|
"Save output in FILE (default is out.X, where X depends on output format.",
|
||||||
Option ['D'] ["output-dir"] (ReqArg outDir "DIR")
|
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))
|
Option [] ["src","force-recomp"] (NoArg (recomp AlwaysRecomp))
|
||||||
"Always recompile from source.",
|
"Always recompile from source.",
|
||||||
Option [] ["gfo","recomp-if-newer"] (NoArg (recomp RecompIfNewer))
|
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) }
|
lexicalCat x = set $ \o -> o { optLexicalCats = foldr Set.insert (optLexicalCats o) (splitBy (==',') x) }
|
||||||
outFile x = set $ \o -> o { optOutputFile = Just x }
|
outFile x = set $ \o -> o { optOutputFile = Just x }
|
||||||
outDir x = set $ \o -> o { optOutputDir = 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 }
|
recomp x = set $ \o -> o { optRecomp = x }
|
||||||
printer x = set $ \o -> o { optPrinter = x : optPrinter o }
|
printer x = set $ \o -> o { optPrinter = x : optPrinter o }
|
||||||
prob x = set $ \o -> o { optProb = x }
|
prob x = set $ \o -> o { optProb = x }
|
||||||
|
|||||||
@@ -56,18 +56,20 @@ type FullPath = String
|
|||||||
gfLibraryPath = "GF_LIB_PATH"
|
gfLibraryPath = "GF_LIB_PATH"
|
||||||
gfGrammarPathVar = "GF_GRAMMAR_PATH"
|
gfGrammarPathVar = "GF_GRAMMAR_PATH"
|
||||||
|
|
||||||
getLibraryPath :: IO FilePath
|
getLibraryPath :: Options -> IO FilePath
|
||||||
getLibraryPath =
|
getLibraryPath opts =
|
||||||
catch
|
case flag optGFLibPath opts of
|
||||||
(getEnv gfLibraryPath)
|
Just path -> return path
|
||||||
(\ex -> getDataDir >>= \path -> return (path </> "lib"))
|
Nothing -> catch
|
||||||
|
(getEnv gfLibraryPath)
|
||||||
|
(\ex -> getDataDir >>= \path -> return (path </> "lib"))
|
||||||
|
|
||||||
-- | extends the search path with the
|
-- | extends the search path with the
|
||||||
-- 'gfLibraryPath' and 'gfGrammarPathVar'
|
-- 'gfLibraryPath' and 'gfGrammarPathVar'
|
||||||
-- environment variables. Returns only existing paths.
|
-- environment variables. Returns only existing paths.
|
||||||
extendPathEnv :: [FilePath] -> IO [FilePath]
|
extendPathEnv :: Options -> [FilePath] -> IO [FilePath]
|
||||||
extendPathEnv ps = do
|
extendPathEnv opts ps = do
|
||||||
b <- getLibraryPath -- e.g. GF_LIB_PATH
|
b <- getLibraryPath opts -- e.g. GF_LIB_PATH
|
||||||
s <- catch (getEnv gfGrammarPathVar) (const (return "")) -- e.g. GF_GRAMMAR_PATH
|
s <- catch (getEnv gfGrammarPathVar) (const (return "")) -- e.g. GF_GRAMMAR_PATH
|
||||||
let ss = ps ++ splitSearchPath s
|
let ss = ps ++ splitSearchPath s
|
||||||
liftM concat $ mapM allSubdirs $ ss ++ [b </> s | s <- ss ++ ["prelude"]]
|
liftM concat $ mapM allSubdirs $ ss ++ [b </> s | s <- ss ++ ["prelude"]]
|
||||||
|
|||||||
Reference in New Issue
Block a user