summaryrefslogtreecommitdiff
path: root/src/compiler/GF/Compile/ReadFiles.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler/GF/Compile/ReadFiles.hs')
-rw-r--r--src/compiler/GF/Compile/ReadFiles.hs17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/compiler/GF/Compile/ReadFiles.hs b/src/compiler/GF/Compile/ReadFiles.hs
index 5c3ac660d..a64bb2a06 100644
--- a/src/compiler/GF/Compile/ReadFiles.hs
+++ b/src/compiler/GF/Compile/ReadFiles.hs
@@ -108,13 +108,22 @@ getAllFiles opts ps env file = do
let mb_envmod = Map.lookup name env
(st,t) = selectFormat opts (fmap fst mb_envmod) gfTime gfoTime
- (mname,imps) <- case st of
- CSEnv -> return (name, maybe [] snd mb_envmod)
- CSRead -> ioeIO $ fmap importsOfModule (decodeModHeader ((if isGFO file then id else gf2gfo opts) file))
+ (st,(mname,imps)) <-
+ case st of
+ CSEnv -> return (st, (name, maybe [] snd mb_envmod))
+ CSRead -> do mb_mo <- ioeIO $ decodeModuleHeader ((if isGFO file then id else gf2gfo opts) file)
+ case mb_mo of
+ Just mo -> return (st,importsOfModule mo)
+ Nothing
+ | isGFO file -> ioeErr $ Bad (file ++ " is compiled with different GF version and I cannot find the source file")
+ | otherwise -> do s <- ioeIO $ BS.readFile file
+ case runP pModHeader s of
+ Left (Pn l c,msg) -> ioeBad (file ++ ":" ++ show l ++ ":" ++ show c ++ ": " ++ msg)
+ Right mo -> return (CSComp,importsOfModule mo)
CSComp -> do s <- ioeIO $ BS.readFile file
case runP pModHeader s of
Left (Pn l c,msg) -> ioeBad (file ++ ":" ++ show l ++ ":" ++ show c ++ ": " ++ msg)
- Right mo -> return (importsOfModule mo)
+ Right mo -> return (st,importsOfModule mo)
ioeErr $ testErr (mname == name)
("module name" +++ mname +++ "differs from file name" +++ name)
return (name,st,t,isJust gfTime,imps,dropFileName file)