on master help sign in
Merge pull request #2933 from LeifW/util_cleanup
00ab489Niklas Larsson
src/IRTS/CodegenCommon.hs−10
@@ -3,20 +3,10 @@ module IRTS.CodegenCommon where
3import Idris.Core.TT
3import Idris.Core.TT
4import IRTS.Simplified
4import IRTS.Simplified
5import IRTS.Defunctionalise
5import IRTS.Defunctionalise
6−import IRTS.Lang
7−
8−import Control.Exception
9−import Data.Word
10−import System.Environment
11
6
12data DbgLevel = NONE | DEBUG | TRACE deriving Eq
7data DbgLevel = NONE | DEBUG | TRACE deriving Eq
13data OutputType = Raw | Object | Executable | MavenProject deriving (Eq, Show)
8data OutputType = Raw | Object | Executable | MavenProject deriving (Eq, Show)
14
9
15−environment :: String -> IO (Maybe String)
16−environment x = Control.Exception.catch (do e <- getEnv x
17− return (Just e))
18− (\y-> do return (y::SomeException); return Nothing)
19−
20-- Everything which might be needed in a code generator - a CG can choose which
10-- Everything which might be needed in a code generator - a CG can choose which
21-- level of Decls to generate code from (simplified, defunctionalised or merely
11-- level of Decls to generate code from (simplified, defunctionalised or merely
22-- lambda lifted) and has access to the list of object files, libraries, etc.
12-- lambda lifted) and has access to the list of object files, libraries, etc.
src/IRTS/System.hs+9−25
@@ -1,8 +1,7 @@
1{-# LANGUAGE CPP #-}
1{-# LANGUAGE CPP #-}
2module IRTS.System(getDataFileName, getDataDir, getTargetDir,getCC,getLibFlags,getIdrisLibDir,
2module IRTS.System(getDataFileName, getDataDir, getTargetDir,getCC,getLibFlags,getIdrisLibDir,
3− getIncFlags, getEnvFlags, getMvn,getExecutablePom, version) where
3+ getIncFlags, getEnvFlags, version) where
4
4
5−import Util.System
6import Data.List.Split
5import Data.List.Split
7
6
8import Control.Applicative ((<$>))
7import Control.Applicative ((<$>))
@@ -17,28 +16,18 @@ import Paths_idris (version)
17import Paths_idris
16import Paths_idris
18#endif
17#endif
19
18
19+overrideDataDirWith :: String -> IO FilePath
20+overrideDataDirWith envVar = do envValue <- lookupEnv envVar
21+ maybe getDataDir return envValue
22+
20getCC :: IO String
23getCC :: IO String
21−getCC = fromMaybe "gcc" <$> environment "IDRIS_CC"
24+getCC = fromMaybe "gcc" <$> lookupEnv "IDRIS_CC"
22
25
23getEnvFlags :: IO [String]
26getEnvFlags :: IO [String]
24−getEnvFlags = maybe [] (splitOn " ") <$> environment "IDRIS_CFLAGS"
27+getEnvFlags = maybe [] (splitOn " ") <$> lookupEnv "IDRIS_CFLAGS"
25−
26−mvnCommand :: String
27−#ifdef mingw32_HOST_OS
28−mvnCommand = "mvn.bat"
29−#else
30−mvnCommand = "mvn"
31−#endif
32−
33−getMvn :: IO String
34−getMvn = fromMaybe mvnCommand <$> environment "IDRIS_MVN"
35−
36−environment :: String -> IO (Maybe String)
37−environment x = catchIO (Just <$> getEnv x)
38− (\_ -> return Nothing)
39
28
40getTargetDir :: IO String
29getTargetDir :: IO String
41−getTargetDir = environment "TARGET" >>= maybe getDataDir return
30+getTargetDir = overrideDataDirWith "TARGET"
42
31
43#if defined(FREEBSD) || defined(DRAGONFLY)
32#if defined(FREEBSD) || defined(DRAGONFLY)
44extraLib = ["-L/usr/local/lib"]
33extraLib = ["-L/usr/local/lib"]
@@ -56,9 +45,7 @@ getLibFlags = do dir <- getDataDir
56 return $ ["-L" ++ (dir </> "rts"),
45 return $ ["-L" ++ (dir </> "rts"),
57 "-lidris_rts"] ++ extraLib ++ gmpLib ++ ["-lpthread"]
46 "-lidris_rts"] ++ extraLib ++ gmpLib ++ ["-lpthread"]
58
47
59−getIdrisLibDir = do libPath <- environment "IDRIS_LIBRARY_PATH"
60− dir <- maybe getDataDir return libPath
61− return $ addTrailingPathSeparator dir
48+getIdrisLibDir = addTrailingPathSeparator <$> overrideDataDirWith "IDRIS_LIBRARY_PATH"
62
49
63#if defined(FREEBSD) || defined(DRAGONFLY)
50#if defined(FREEBSD) || defined(DRAGONFLY)
64extraInclude = ["-I/usr/local/include"]
51extraInclude = ["-I/usr/local/include"]
@@ -67,6 +54,3 @@ extraInclude = []
67#endif
54#endif
68getIncFlags = do dir <- getDataDir
55getIncFlags = do dir <- getDataDir
69 return $ ("-I" ++ dir </> "rts") : extraInclude
56 return $ ("-I" ++ dir </> "rts") : extraInclude
70−
71−getExecutablePom = do dir <- getDataDir
72− return $ dir </> "java" </> "executable_pom.xml"
src/Util/System.hs−4
@@ -2,7 +2,6 @@
2module Util.System(tempfile,withTempdir,rmFile,catchIO, isWindows,
2module Util.System(tempfile,withTempdir,rmFile,catchIO, isWindows,
3 writeSource, writeSourceText, readSource,
3 writeSource, writeSourceText, readSource,
4 setupBundledCC, isATTY) where
4 setupBundledCC, isATTY) where
5−
6-- System helper functions.
5-- System helper functions.
7
6
8import Control.Exception as CE
7import Control.Exception as CE
@@ -32,9 +31,6 @@ import System.Environment (getEnv, setEnv, getExecutablePath)
32catchIO :: IO a -> (IOError -> IO a) -> IO a
31catchIO :: IO a -> (IOError -> IO a) -> IO a
33catchIO = CE.catch
32catchIO = CE.catch
34
33
35−throwIO :: IOError -> IO a
36−throwIO = CE.throw
37−
38isWindows :: Bool
34isWindows :: Bool
39isWindows = os `elem` ["win32", "mingw32", "cygwin32"]
35isWindows = os `elem` ["win32", "mingw32", "cygwin32"]
40
36