2module Util.System(tempfile,withTempdir,getTargetDir,getCC,
3 getLibFlags,getIdrisLibDir,getIncFlags,rmFile,
4 getMvn,getExecutablePom,catchIO) where
6-- System helper functions.
7import Control.Monad (when)
8import Control.Applicative ((<$>))
9import Data.Maybe (fromMaybe)
10import Distribution.Text (display)
11import System.Directory (getTemporaryDirectory
13 , removeDirectoryRecursive
14 , createDirectoryIfMissing
16import System.FilePath ((</>), addTrailingPathSeparator, normalise)
17import System.Environment
20import Control.Exception as CE
24catchIO :: IO a -> (IOError -> IO a) -> IO a
27throwIO :: IOError -> IO a
32getCC = fromMaybe "gcc" <$> environment "IDRIS_CC"
42getMvn = fromMaybe mvnCommand <$> environment "IDRIS_MVN"
44tempfile :: IO (FilePath, Handle)
45tempfile = do dir <- getTemporaryDirectory
46 openTempFile (normalise dir) "idris"
48withTempdir :: String -> (FilePath -> IO a) -> IO a
49withTempdir subdir callback
50 = do dir <- getTemporaryDirectory
51 let tmpDir = (normalise dir) </> subdir
52 removeLater <- catchIO (createDirectoryIfMissing True tmpDir >> return True)
53 (\ ioError -> if isAlreadyExistsError ioError then return False
56 result <- callback tmpDir
57 when removeLater $ removeDirectoryRecursive tmpDir
60environment :: String -> IO (Maybe String)
61environment x = catchIO (do e <- getEnv x
63 (\_ -> return Nothing)
65getTargetDir :: IO String
66getTargetDir = environment "TARGET" >>= maybe getDataDir return
68rmFile :: FilePath -> IO ()
69rmFile f = do putStrLn $ "Removing " ++ f
70 catchIO (removeFile f)
71 (\ioerr -> putStrLn $ "WARNING: Cannot remove file "
72 ++ f ++ ", Error msg:" ++ show ioerr)
75getLibFlags = do dir <- getDataDir
76 return $ "-L" ++ (dir </> "rts") ++ " -lidris_rts -lgmp -lpthread"
78getIdrisLibDir = do dir <- getDataDir
79 return $ addTrailingPathSeparator dir
81getIncFlags = do dir <- getDataDir
82 return $ "-I" ++ dir </> "rts"
84getExecutablePom = do dir <- getDataDir
85 return $ dir </> "java" </> "executable_pom.xml"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list