@@ -1,9 +1,12 @@
1{-# LANGUAGE CPP #-}
1{-# LANGUAGE CPP #-}
2module Util.System(tempfile,withTempdir,rmFile,catchIO, isWindows,
2module Util.System(tempfile,withTempdir,rmFile,catchIO, isWindows,
3+ writeSource, writeSourceText, readSource,
3− writeSource, readSource, setupBundledCC) where
4+ setupBundledCC) where
5-- System helper functions.
6-- System helper functions.
6import Control.Monad (when)
7import Control.Monad (when)
8+import qualified Data.Text as T
9+import qualified Data.Text.IO as TIO
7import System.Directory (getTemporaryDirectory
10import System.Directory (getTemporaryDirectory
8 , removeFile
11 , removeFile
9 , removeDirectoryRecursive
12 , removeDirectoryRecursive
@@ -44,6 +47,10 @@ readSource f = do h <- openFile f ReadMode
44writeSource :: FilePath -> String -> IO ()
47writeSource :: FilePath -> String -> IO ()
45writeSource f s = withFile f WriteMode (\h -> hSetEncoding h utf8 >> hPutStr h s)
48writeSource f s = withFile f WriteMode (\h -> hSetEncoding h utf8 >> hPutStr h s)
50+-- | Write a utf-8 source file from Text
51+writeSourceText :: FilePath -> T.Text -> IO ()
52+writeSourceText f s = withFile f WriteMode (\h -> hSetEncoding h utf8 >> TIO.hPutStr h s)
47withTempdir :: String -> (FilePath -> IO a) -> IO a
54withTempdir :: String -> (FilePath -> IO a) -> IO a
48withTempdir subdir callback
55withTempdir subdir callback
49 = do dir <- getTemporaryDirectory
56 = do dir <- getTemporaryDirectory