@@ -1,9 +1,12 @@
11{-# LANGUAGE CPP #-}
22module Util.System(tempfile,withTempdir,rmFile,catchIO, isWindows,
3− writeSource, readSource, setupBundledCC) where
3+ writeSource, writeSourceText, readSource,
4+ setupBundledCC) where
45
56-- System helper functions.
67import Control.Monad (when)
8+import qualified Data.Text as T
9+import qualified Data.Text.IO as TIO
710import System.Directory (getTemporaryDirectory
811 , removeFile
912 , removeDirectoryRecursive
@@ -44,6 +47,10 @@ readSource f = do h <- openFile f ReadMode
4447writeSource :: FilePath -> String -> IO ()
4548writeSource f s = withFile f WriteMode (\h -> hSetEncoding h utf8 >> hPutStr h s)
4649
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)
53+
4754withTempdir :: String -> (FilePath -> IO a) -> IO a
4855withTempdir subdir callback
4956 = do dir <- getTemporaryDirectory