@@ -1,51 +0,0 @@
1−{-# OPTIONS_GHC -W #-}
2−module InterfaceSerialization ( loadInterface
3− , interfaceDecode
4− , validVersion
5− ) where
6−
7−import qualified Data.ByteString.Lazy as L
8−import qualified Data.Binary as Binary
9−
10−import qualified Elm.Internal.Version as Version
11−import System.Directory (doesFileExist)
12−
13−import SourceSyntax.Module
14−
15−loadInterface :: FilePath -> IO (Either String L.ByteString)
16−loadInterface filePath = do
17− exists <- doesFileExist filePath
18− if exists
19− then do
20− byteString <- L.readFile filePath
21− return $ Right byteString
22−
23− else
24− return $ Left $ "Unable to find file " ++ filePath ++
25− " for deserialization!"
26−
27−interfaceDecode :: Binary.Binary a =>
28− FilePath -> L.ByteString -> Either String a
29−interfaceDecode filePath bytes = do
30− case Binary.decodeOrFail bytes of
31− Right (_, _, binaryInfo) -> Right binaryInfo
32−
33− Left (_, offset, err) ->
34− Left $ concat [ "Error reading build artifact: ", filePath, "\n"
35− , " The exact error was '", err, "' at offset ", show offset, ".\n"
36− , " The file was generated by a previous build and may be outdated or corrupt.\n"
37− , " Please remove the file and try again."
38− ]
39−
40−validVersion :: FilePath -> (String, ModuleInterface) ->
41− Either String (String, ModuleInterface)
42−validVersion filePath (name, interface) =
43− if iVersion interface == Version.elmVersion then
44− Right (name, interface)
45− else
46− Left $ concat
47− [ "Error reading build artifact: ", filePath, "\n"
48− , " It was generated by a different version of the compiler: "
49− , show (iVersion interface), "\n"
50− , " Please remove the file and try again.\n"
51− ]