on master help sign in
Fix :exec on Windows
5300c53Niklas Larsson
main/Main.hs+2−2
@@ -3,7 +3,6 @@ module Main where
3import System.Console.Haskeline
3import System.Console.Haskeline
4import System.IO
4import System.IO
5import System.Environment
5import System.Environment
6−import System.Info
7import System.Exit
6import System.Exit
8import System.FilePath ((</>), addTrailingPathSeparator)
7import System.FilePath ((</>), addTrailingPathSeparator)
9import System.Directory
8import System.Directory
@@ -30,6 +29,7 @@ import Idris.CmdOptions
30import IRTS.System ( getLibFlags, getIdrisLibDir, getIncFlags )
29import IRTS.System ( getLibFlags, getIdrisLibDir, getIncFlags )
31
30
32import Util.DynamicLinker
31import Util.DynamicLinker
32+import Util.System
33
33
34import Pkg.Package
34import Pkg.Package
35
35
@@ -40,7 +40,7 @@ import Paths_idris
40
40
41main :: IO ()
41main :: IO ()
42main = do
42main = do
43− when (os == "mingw32") $ do hSetEncoding stdout utf8
43+ when isWindows $ do hSetEncoding stdout utf8
44 opts <- runArgParser
44 opts <- runArgParser
45 runMain (runIdris opts)
45 runMain (runIdris opts)
46
46
src/Idris/REPL.hs+3−1
@@ -1104,10 +1104,12 @@ process fn Execute
1104 (tmpn, tmph) <- runIO tempfile
1104 (tmpn, tmph) <- runIO tempfile
1105 runIO $ hClose tmph
1105 runIO $ hClose tmph
1106 t <- codegen
1106 t <- codegen
1107+ -- gcc adds .exe when it builds windows programs
1108+ progName <- return $ if isWindows then tmpn ++ ".exe" else tmpn
1107 ir <- compile t tmpn m
1109 ir <- compile t tmpn m
1108 runIO $ generate t (fst (head (idris_imported ist))) ir
1110 runIO $ generate t (fst (head (idris_imported ist))) ir
1109 case idris_outputmode ist of
1111 case idris_outputmode ist of
1110− RawOutput h -> do runIO $ rawSystem tmpn []
1112+ RawOutput h -> do runIO $ rawSystem progName []
1111 return ()
1113 return ()
1112 IdeMode n h -> runIO . hPutStrLn h $
1114 IdeMode n h -> runIO . hPutStrLn h $
1113 IdeMode.convSExp "run-program" tmpn n)
1115 IdeMode.convSExp "run-program" tmpn n)
src/Pkg/PParser.hs+2−2
@@ -16,7 +16,7 @@ import Idris.CmdOptions
16import Control.Monad.State.Strict
16import Control.Monad.State.Strict
17import Control.Applicative
17import Control.Applicative
18
18
19−import System.Info (os)
19+import Util.System
20
20
21
21
22type PParser = StateT PkgDesc IdrisInnerParser
22type PParser = StateT PkgDesc IdrisInnerParser
@@ -63,7 +63,7 @@ pClause :: PParser ()
63pClause = do reserved "executable"; lchar '=';
63pClause = do reserved "executable"; lchar '=';
64 exec <- iName []
64 exec <- iName []
65 st <- get
65 st <- get
66− put (st { execout = Just (if os `elem` ["win32", "mingw32", "cygwin32"]
66+ put (st { execout = Just (if isWindows
67 then ((show exec) ++ ".exe")
67 then ((show exec) ++ ".exe")
68 else ( show exec )
68 else ( show exec )
69 ) })
69 ) })
src/Util/System.hs+5−1
@@ -1,4 +1,4 @@
1−module Util.System(tempfile,withTempdir,rmFile,catchIO) where
1+module Util.System(tempfile,withTempdir,rmFile,catchIO, isWindows) where
2
2
3-- System helper functions.
3-- System helper functions.
4import Control.Monad (when)
4import Control.Monad (when)
@@ -9,6 +9,7 @@ import System.Directory (getTemporaryDirectory
9 )
9 )
10import System.FilePath ((</>), normalise)
10import System.FilePath ((</>), normalise)
11import System.IO
11import System.IO
12+import System.Info
12import System.IO.Error
13import System.IO.Error
13import Control.Exception as CE
14import Control.Exception as CE
14
15
@@ -18,6 +19,9 @@ catchIO = CE.catch
18throwIO :: IOError -> IO a
19throwIO :: IOError -> IO a
19throwIO = CE.throw
20throwIO = CE.throw
20
21
22+isWindows :: Bool
23+isWindows = os `elem` ["win32", "mingw32", "cygwin32"]
24+
21tempfile :: IO (FilePath, Handle)
25tempfile :: IO (FilePath, Handle)
22tempfile = do dir <- getTemporaryDirectory
26tempfile = do dir <- getTemporaryDirectory
23 openTempFile (normalise dir) "idris"
27 openTempFile (normalise dir) "idris"