-gfo-files is consulted not only when .gfo files are created but also when we search for them

This commit is contained in:
krasimir
2009-05-11 06:50:50 +00:00
parent 2e068c90a4
commit 85d0324a9b
2 changed files with 18 additions and 12 deletions

View File

@@ -160,9 +160,7 @@ compileOne opts env@(_,srcgr,_) file = do
-- for gf source, do full compilation and generate code -- for gf source, do full compilation and generate code
_ -> do _ -> do
let gfo = maybe (gfoFile (dropExtension file)) let gfo = gf2gfo opts file
(\dir -> dir </> gfoFile (dropExtension (takeFileName file)))
(flag optGFODir opts)
b1 <- ioeIO $ doesFileExist file b1 <- ioeIO $ doesFileExist file
if not b1 if not b1
then compileOne opts env $ gfo then compileOne opts env $ gfo

View File

@@ -20,7 +20,7 @@
module GF.Compile.ReadFiles module GF.Compile.ReadFiles
( getAllFiles,ModName,ModEnv,importsOfModule, ( getAllFiles,ModName,ModEnv,importsOfModule,
gfoFile,gfFile,isGFO, gfoFile,gfFile,isGFO,gf2gfo,
getOptionsFromFile) where getOptionsFromFile) where
import GF.Infra.UseIO import GF.Infra.UseIO
@@ -37,6 +37,7 @@ import GF.Grammar.Binary
import Control.Monad import Control.Monad
import Data.Char import Data.Char
import Data.List import Data.List
import Data.Maybe(isJust)
import qualified Data.ByteString.Char8 as BS import qualified Data.ByteString.Char8 as BS
import qualified Data.Map as Map import qualified Data.Map as Map
import System.Time import System.Time
@@ -58,11 +59,14 @@ getAllFiles opts ps env file = do
return $ paths ds return $ paths ds
where where
-- construct list of paths to read -- construct list of paths to read
paths cs = [mk (p </> f) | (f,st,_,_,p) <- cs, mk <- mkFile st] paths ds = concatMap mkFile ds
where where
mkFile CSComp = [gfFile ] mkFile (f,st,gfTime,gfoTime,p) =
mkFile CSRead = [gfoFile] case st of
mkFile _ = [] CSComp -> [p </> gfFile f]
CSRead | isJust gfTime -> [gf2gfo opts (p </> gfFile f)]
| otherwise -> [p </> gfoFile f]
CSEnv -> []
-- | traverses the dependency graph and returns a topologicaly sorted -- | traverses the dependency graph and returns a topologicaly sorted
-- list of ModuleInfo. An error is raised if there is circular dependency -- list of ModuleInfo. An error is raised if there is circular dependency
@@ -90,10 +94,10 @@ getAllFiles opts ps env file = do
mb_gfFile <- ioeIO $ getFilePath ps (gfFile name) mb_gfFile <- ioeIO $ getFilePath ps (gfFile name)
case mb_gfFile of case mb_gfFile of
Just gfFile -> do gfTime <- ioeIO $ getModificationTime gfFile Just gfFile -> do gfTime <- ioeIO $ getModificationTime gfFile
mb_gfoTime <- ioeIO $ catch (liftM Just $ getModificationTime (replaceExtension gfFile "gfo")) mb_gfoTime <- ioeIO $ catch (liftM Just $ getModificationTime (gf2gfo opts gfFile))
(\_->return Nothing) (\_->return Nothing)
return (gfFile, Just gfTime, mb_gfoTime) return (gfFile, Just gfTime, mb_gfoTime)
Nothing -> do mb_gfoFile <- ioeIO $ getFilePath ps (gfoFile name) Nothing -> do mb_gfoFile <- ioeIO $ getFilePath (maybe id (:) (flag optGFODir opts) ps) (gfoFile name)
case mb_gfoFile of case mb_gfoFile of
Just gfoFile -> do gfoTime <- ioeIO $ getModificationTime gfoFile Just gfoFile -> do gfoTime <- ioeIO $ getModificationTime gfoFile
return (gfoFile, Nothing, Just gfoTime) return (gfoFile, Nothing, Just gfoTime)
@@ -106,7 +110,7 @@ getAllFiles opts ps env file = do
(mname,imps) <- case st of (mname,imps) <- case st of
CSEnv -> return (name, maybe [] snd mb_envmod) CSEnv -> return (name, maybe [] snd mb_envmod)
CSRead -> ioeIO $ fmap importsOfModule (decodeModHeader (replaceExtension file "gfo")) CSRead -> ioeIO $ fmap importsOfModule (decodeModHeader ((if isGFO file then id else gf2gfo opts) file))
CSComp -> do s <- ioeIO $ BS.readFile file CSComp -> do s <- ioeIO $ BS.readFile file
case runP pModHeader s of case runP pModHeader s of
Left (Pn l c,msg) -> ioeBad (file ++ ":" ++ show l ++ ":" ++ show c ++ ": " ++ msg) Left (Pn l c,msg) -> ioeBad (file ++ ":" ++ show l ++ ":" ++ show c ++ ": " ++ msg)
@@ -124,6 +128,10 @@ gfoFile f = addExtension f "gfo"
gfFile :: FilePath -> FilePath gfFile :: FilePath -> FilePath
gfFile f = addExtension f "gf" gfFile f = addExtension f "gf"
gf2gfo :: Options -> FilePath -> FilePath
gf2gfo opts file = maybe (gfoFile (dropExtension file))
(\dir -> dir </> gfoFile (dropExtension (takeFileName file)))
(flag optGFODir opts)
-- From the given Options and the time stamps computes -- From the given Options and the time stamps computes
-- whether the module have to be computed, read from .gfo or -- whether the module have to be computed, read from .gfo or