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
18import Control.Exception as CE
22catchIO :: IO a -> (IOError -> IO a) -> IO a
25throwIO :: IOError -> IO a
31getCC = do env <- environment "IDRIS_CC"
33 Nothing -> return "gcc"
37getMvn = do env <- environment "IDRIS_MVN"
40 Nothing -> return "mvn.bat"
42 Nothing -> return "mvn"
44 Just mvn -> return mvn
46tempfile :: IO (FilePath, Handle)
47tempfile = do dir <- getTemporaryDirectory
48 openTempFile (normalise dir) "idris"
50withTempdir :: String -> (FilePath -> IO a) -> IO a
51withTempdir subdir callback
52 = do dir <- getTemporaryDirectory
53 let tmpDir = (normalise dir) </> subdir
54 removeLater <- catchIO (createDirectoryIfMissing True tmpDir >> return True)
55 (\ ioError -> if isAlreadyExistsError ioError then return False
58 result <- callback tmpDir
59 when removeLater $ removeDirectoryRecursive tmpDir
62environment :: String -> IO (Maybe String)
63environment x = catchIO (do e <- getEnv x
65 (\_ -> return Nothing)
67rmFile :: FilePath -> IO ()
68rmFile f = do putStrLn $ "Removing " ++ f
69 catchIO (removeFile f)
70 (\ioerr -> putStrLn $ "WARNING: Cannot remove file "
71 ++ f ++ ", Error msg:" ++ show ioerr)
74getLibFlags = do dir <- getDataDir
75 return $ "-L" ++ (dir </> "rts") ++ " -lidris_rts -lgmp -lpthread"
77getIdrisLibDir = do dir <- getDataDir
78 return $ addTrailingPathSeparator dir
80getIncFlags = do dir <- getDataDir
81 return $ "-I" ++ dir </> "rts"
83getExecutablePom = do dir <- getDataDir
84 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