on master help sign in
Fix :exec on Windows

GCC on Windows will add .exe to the executable name. rawSystem needs the exact name. Add isWindows and put in the places that need special handling. Conflicts: main/Main.hs

commit5300c539c4525d22fe83cea83adfcf9485dd546a authorNiklas Larsson <niklas@mm.st> dateSun 22 Feb 2015, 23:15 (12 years ago) parent1b4b01c
4 files changed+12−6
main/Main.hs+2−2 src/Idris/REPL.hs+3−1 src/Pkg/PParser.hs+2−2 src/Util/System.hs+5−1
main/Main.hs+2−2
@@ -3,7 +3,6 @@ module Main where
33import System.Console.Haskeline
44import System.IO
55import System.Environment
6−import System.Info
76import System.Exit
87import System.FilePath ((</>), addTrailingPathSeparator)
98import System.Directory
@@ -30,6 +29,7 @@ import Idris.CmdOptions
3029import IRTS.System ( getLibFlags, getIdrisLibDir, getIncFlags )
3130
3231import Util.DynamicLinker
32+import Util.System
3333
3434import Pkg.Package
3535
@@ -40,7 +40,7 @@ import Paths_idris
4040
4141main :: IO ()
4242main = do
43− when (os == "mingw32") $ do hSetEncoding stdout utf8
43+ when isWindows $ do hSetEncoding stdout utf8
4444 opts <- runArgParser
4545 runMain (runIdris opts)
4646
src/Idris/REPL.hs+3−1
@@ -1104,10 +1104,12 @@ process fn Execute
11041104 (tmpn, tmph) <- runIO tempfile
11051105 runIO $ hClose tmph
11061106 t <- codegen
1107+ -- gcc adds .exe when it builds windows programs
1108+ progName <- return $ if isWindows then tmpn ++ ".exe" else tmpn
11071109 ir <- compile t tmpn m
11081110 runIO $ generate t (fst (head (idris_imported ist))) ir
11091111 case idris_outputmode ist of
1110− RawOutput h -> do runIO $ rawSystem tmpn []
1112+ RawOutput h -> do runIO $ rawSystem progName []
11111113 return ()
11121114 IdeMode n h -> runIO . hPutStrLn h $
11131115 IdeMode.convSExp "run-program" tmpn n)
src/Pkg/PParser.hs+2−2
@@ -16,7 +16,7 @@ import Idris.CmdOptions
1616import Control.Monad.State.Strict
1717import Control.Applicative
1818
19−import System.Info (os)
19+import Util.System
2020
2121
2222type PParser = StateT PkgDesc IdrisInnerParser
@@ -63,7 +63,7 @@ pClause :: PParser ()
6363pClause = do reserved "executable"; lchar '=';
6464 exec <- iName []
6565 st <- get
66− put (st { execout = Just (if os `elem` ["win32", "mingw32", "cygwin32"]
66+ put (st { execout = Just (if isWindows
6767 then ((show exec) ++ ".exe")
6868 else ( show exec )
6969 ) })
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
22
33-- System helper functions.
44import Control.Monad (when)
@@ -9,6 +9,7 @@ import System.Directory (getTemporaryDirectory
99 )
1010import System.FilePath ((</>), normalise)
1111import System.IO
12+import System.Info
1213import System.IO.Error
1314import Control.Exception as CE
1415
@@ -18,6 +19,9 @@ catchIO = CE.catch
1819throwIO :: IOError -> IO a
1920throwIO = CE.throw
2021
22+isWindows :: Bool
23+isWindows = os `elem` ["win32", "mingw32", "cygwin32"]
24+
2125tempfile :: IO (FilePath, Handle)
2226tempfile = do dir <- getTemporaryDirectory
2327 openTempFile (normalise dir) "idris"