Permalink
Browse files

move filehandling code to utils module

  • Loading branch information...
1 parent 2384c71 commit 5a65714482e2551c589fa9eff9aa3c7bde70d5dc @mwotton committed Jan 11, 2013
@@ -0,0 +1,12 @@
+module Language.Ruby.Hubris.FileUtil where
+import System.IO(hPutStr, hClose, openTempFile)
+import System.Process( readProcessWithExitCode )
+import System.Exit(ExitCode)
+withTempFile :: String -> String -> IO String
+withTempFile pattern code = do (name, handle) <- openTempFile "/tmp" pattern
+ hPutStr handle code
+ hClose handle
+ return name
+
+noisySystem :: String -> [String] -> IO (ExitCode, String,String)
+noisySystem cmd args = (putStrLn . unwords) (cmd:args) >> readProcessWithExitCode cmd args ""
@@ -10,6 +10,7 @@ import System.Process
import Control.Monad(forM_,guard)
import System.IO(hPutStr, hClose, openTempFile)
import System.Exit
+import Language.Ruby.Hubris.FileUtil
import Language.Ruby.Hubris.Includes (extraIncludeDirs) -- this is generated by Cabal
@@ -21,12 +22,6 @@ type Filename = String
standardGHCFlags = (words $ "--make -shared -dynamic -fPIC -optc-DHAVE_SNPRINTF -lHSrts-ghc" ++Config.cProjectVersion)
++ map ("-I"++) extraIncludeDirs
-withTempFile :: String -> String -> IO String
-withTempFile pattern code = do (name, handle) <- openTempFile "/tmp" pattern
- hPutStr handle code
- hClose handle
- return name
-
ghcBuild :: Filename -> String -> String -> [Filename] -> [String]-> IO (Either String Filename)
ghcBuild libFile immediateSource modName extra_sources args =
do -- putStrLn ("modname is " ++ modName)
@@ -39,7 +34,5 @@ ghcBuild libFile immediateSource modName extra_sources args =
ExitSuccess -> Right libFile
otherCode -> Left $ unlines ["Errcode: " ++show code,"output: " ++ out, "error: " ++ err]
-noisySystem :: String -> [String] -> IO (ExitCode, String,String)
-noisySystem cmd args = (putStrLn . unwords) (cmd:args) >> readProcessWithExitCode cmd args ""
@@ -5,6 +5,7 @@ import Language.Ruby.Hubris
import Language.Haskell.Interpreter
-- import Language.Haskell.Meta.QQ.HsHere
import Language.Ruby.Hubris.GHCBuild
+import Language.Ruby.Hubris.FileUtil
import Data.List(intercalate,intersperse)
import qualified Debug.Trace
@@ -14,8 +15,8 @@ import Control.Monad.Error.Class
import Data.Maybe(catMaybes,fromJust, isJust)
import GHC(parseStaticFlags, noLoc)
-import System.IO(hPutStr, hClose, openTempFile)
-import System.Exit
+
+
import Language.Ruby.Hubris.ZCode (zenc,Zname(..))
type Filename = String

0 comments on commit 5a65714

Please sign in to comment.