2module Util.System(tempfile,withTempdir,environment,getCC,
3 getLibFlags,getIdrisLibDir,getIncFlags,rmFile,
4 getMvn,getExecutablePom,catchIO) where
6-- System helper functions.
7import Control.Monad (when)
8import Distribution.Text (display)
9import System.Directory (getTemporaryDirectory
11 , removeDirectoryRecursive
12 , createDirectoryIfMissing
14import System.FilePath ((</>), addTrailingPathSeparator, normalise)
15import System.Environment
18#if MIN_VERSION_base(4,0,0)
19import Control.Exception as CE
24#if MIN_VERSION_base(4,0,0)
25catchIO :: IO a -> (IOError -> IO a) -> IO a
28throwIO :: IOError -> IO a
38getCC = do env <- environment "IDRIS_CC"
40 Nothing -> return "gcc"
44getMvn = do env <- environment "IDRIS_MVN"
46 Nothing -> return "mvn"
47 Just mvn -> return mvn
49tempfile :: IO (FilePath, Handle)
50tempfile = do dir <- getTemporaryDirectory
51 openTempFile (normalise dir) "idris"
53withTempdir :: String -> (FilePath -> IO a) -> IO a
54withTempdir subdir callback
55 = do dir <- getTemporaryDirectory
56 let tmpDir = (normalise dir) </> subdir
57 removeLater <- catchIO (createDirectoryIfMissing True tmpDir >> return True)
58 (\ ioError -> if isAlreadyExistsError ioError then return False
61 result <- callback tmpDir
62 when removeLater $ removeDirectoryRecursive tmpDir
65environment :: String -> IO (Maybe String)
66environment x = catchIO (do e <- getEnv x
68 (\_ -> return Nothing)
70rmFile :: FilePath -> IO ()
71rmFile f = do putStrLn $ "Removing " ++ f
72 catchIO (removeFile f)
73 (\ioerr -> putStrLn $ "WARNING: Cannot remove file "
74 ++ f ++ ", Error msg:" ++ show ioerr)
77getLibFlags = do dir <- getDataDir
78 return $ "-L" ++ (dir </> "rts") ++ " -lidris_rts -lgmp -lpthread"
80getIdrisLibDir = do dir <- getDataDir
81 return $ addTrailingPathSeparator dir
83getIncFlags = do dir <- getDataDir
84 return $ "-I" ++ dir </> "rts"
86getExecutablePom = do dir <- getDataDir
87 return $ dir </> "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