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)
75extraLib = " -L/usr/local/lib"
86getLibFlags = do dir <- getDataDir
87 return $ "-L" ++ (dir </> "rts") ++
88 " -lidris_rts" ++ extraLib ++ gmpLib ++ " -lpthread"
90getIdrisLibDir = do dir <- getDataDir
91 return $ addTrailingPathSeparator dir
94extraInclude = " -I/usr/local/include"
98getIncFlags = do dir <- getDataDir
99 return $ "-I" ++ dir </> "rts" ++ extraInclude
101getExecutablePom = do dir <- getDataDir
102 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