on master help sign in
Ensure that binary serialization works on Windows. Previously had issues with line ending conversions messing with binary data.
a446d60Evan Czaplicki
Setup.hs+10−2
@@ -11,6 +11,7 @@ import System.Process
11
11
12import Control.Monad
12import Control.Monad
13import qualified Data.Binary as Binary
13import qualified Data.Binary as Binary
14+import qualified Data.ByteString.Lazy as BS
14
15
15-- Part 1
16-- Part 1
16-- ------
17-- ------
@@ -130,8 +131,15 @@ buildInterfaces :: LocalBuildInfo -> [FilePath] -> IO ()
130buildInterfaces lbi elmis = do
131buildInterfaces lbi elmis = do
131 createDirectoryIfMissing True (rtsDir lbi)
132 createDirectoryIfMissing True (rtsDir lbi)
132 let ifaces = interfaces lbi
133 let ifaces = interfaces lbi
134+ ifaceHandle <- openBinaryFile ifaces WriteMode
133− Binary.encodeFile ifaces (length elmis)
135+ BS.hPut ifaceHandle (Binary.encode (length elmis))
134− mapM_ (\elmi -> readFile elmi >>= appendFile ifaces) elmis
136+ let append file = do
137+ handle <- openBinaryFile file ReadMode
138+ bits <- hGetContents handle
139+ length bits `seq` hPutStr ifaceHandle bits
140+ hClose handle
141+ mapM_ append elmis
142+ hClose ifaceHandle
135
143
136buildRuntime :: LocalBuildInfo -> [FilePath] -> IO ()
144buildRuntime :: LocalBuildInfo -> [FilePath] -> IO ()
137buildRuntime lbi elmos = do
145buildRuntime lbi elmos = do
compiler/Compiler.hs+13−3
@@ -10,12 +10,14 @@ import System.Console.CmdArgs hiding (program)
10import System.Directory
10import System.Directory
11import System.Exit
11import System.Exit
12import System.FilePath
12import System.FilePath
13+import System.IO
13import GHC.Conc
14import GHC.Conc
14
15
15import qualified Text.Blaze.Html.Renderer.Pretty as Pretty
16import qualified Text.Blaze.Html.Renderer.Pretty as Pretty
16import qualified Text.Blaze.Html.Renderer.String as Normal
17import qualified Text.Blaze.Html.Renderer.String as Normal
17import qualified Text.Jasmine as JS
18import qualified Text.Jasmine as JS
18import qualified Data.ByteString.Lazy.Char8 as BS
19import qualified Data.ByteString.Lazy.Char8 as BS
20+import qualified Data.ByteString.Lazy as L
19
21
20import qualified Metadata.Prelude as Prelude
22import qualified Metadata.Prelude as Prelude
21import qualified Transform.Canonicalize as Canonical
23import qualified Transform.Canonicalize as Canonical
@@ -91,8 +93,14 @@ elmi flags filePath = file flags filePath "elmi"
91buildFile :: Flags -> Int -> Int -> Interfaces -> FilePath -> IO ModuleInterface
93buildFile :: Flags -> Int -> Int -> Interfaces -> FilePath -> IO ModuleInterface
92buildFile flags moduleNum numModules interfaces filePath =
94buildFile flags moduleNum numModules interfaces filePath =
93 do compiled <- alreadyCompiled
95 do compiled <- alreadyCompiled
94− if not compiled then compile
96+ case compiled of
95− else getInterface `fmap` Binary.decodeFile (elmi flags filePath)
97+ False -> compile
98+ True -> do
99+ handle <- openBinaryFile (elmi flags filePath) ReadMode
100+ bits <- L.hGetContents handle
101+ let iface = getInterface (Binary.decode bits)
102+ L.length bits `seq` hClose handle
103+ return iface
96 where
104 where
97 getInterface :: (String, ModuleInterface) -> ModuleInterface
105 getInterface :: (String, ModuleInterface) -> ModuleInterface
98 getInterface = snd
106 getInterface = snd
@@ -139,7 +147,9 @@ buildFile flags moduleNum numModules interfaces filePath =
139 iAliases = aliases metaModule
147 iAliases = aliases metaModule
140 }
148 }
141 createDirectoryIfMissing True . dropFileName $ elmi flags filePath
149 createDirectoryIfMissing True . dropFileName $ elmi flags filePath
142− Binary.encodeFile (elmi flags filePath) (name,interface)
150+ handle <- openBinaryFile (elmi flags filePath) WriteMode
151+ L.hPut handle (Binary.encode (name,interface))
152+ hClose handle
143 writeFile (elmo flags filePath) (jsModule metaModule)
153 writeFile (elmo flags filePath) (jsModule metaModule)
144 return interface
154 return interface
145
155
compiler/Metadata/Prelude.hs+10−2
@@ -6,9 +6,11 @@ import qualified Paths_Elm as Path
6import System.Directory
6import System.Directory
7import System.Exit
7import System.Exit
8import System.FilePath
8import System.FilePath
9+import System.IO
9import System.IO.Unsafe (unsafePerformIO)
10import System.IO.Unsafe (unsafePerformIO)
10import SourceSyntax.Module
11import SourceSyntax.Module
11import qualified Data.Binary as Binary
12import qualified Data.Binary as Binary
13+import qualified Data.ByteString.Lazy as BS
12
14
13
15
14add :: Module t v -> Module t v
16add :: Module t v -> Module t v
@@ -47,5 +49,11 @@ safeReadDocs name =
47readDocs :: FilePath -> IO Interfaces
49readDocs :: FilePath -> IO Interfaces
48readDocs name = do
50readDocs name = do
49 exists <- doesFileExist name
51 exists <- doesFileExist name
50− if exists then Map.fromList `fmap` Binary.decodeFile name
52+ case exists of
51− else ioError . userError $ "File Not Found"
53+ False -> ioError . userError $ "File Not Found"
54+ True -> do
55+ handle <- openBinaryFile name ReadMode
56+ bits <- BS.hGetContents handle
57+ let ifaces = Map.fromList (Binary.decode bits)
58+ BS.length bits `seq` hClose handle
59+ return ifaces