on master help sign in
Allow an extension on tempfiles
609835eNiklas Larsson
src/IRTS/CodegenC.hs+2−2
@@ -66,7 +66,7 @@ codegenC' defs out exec incs objs libs flags exports iface dbg
66 MavenProject -> putStrLn ("FAILURE: output type not supported")
66 MavenProject -> putStrLn ("FAILURE: output type not supported")
67 Raw -> writeSource out cout
67 Raw -> writeSource out cout
68 _ -> do
68 _ -> do
69− (tmpn, tmph) <- tempfile
69+ (tmpn, tmph) <- tempfile ".c"
70 hPutStr tmph cout
70 hPutStr tmph cout
71 hFlush tmph
71 hFlush tmph
72 hClose tmph
72 hClose tmph
@@ -78,7 +78,7 @@ codegenC' defs out exec incs objs libs flags exports iface dbg
78 gccFlags iface ++
78 gccFlags iface ++
79 -- # Any flags defined here which alter the RTS API must also be added to config.mk
79 -- # Any flags defined here which alter the RTS API must also be added to config.mk
80 ["-DHAS_PTHREAD", "-DIDRIS_ENABLE_STATS",
80 ["-DHAS_PTHREAD", "-DIDRIS_ENABLE_STATS",
81− "-I."] ++ objs ++ ["-x", "c"] ++ envFlags ++
81+ "-I."] ++ objs ++ envFlags ++
82 (if (exec == Executable) then [] else ["-c"]) ++
82 (if (exec == Executable) then [] else ["-c"]) ++
83 [tmpn] ++
83 [tmpn] ++
84 (if not iface then concatMap words libFlags else []) ++
84 (if not iface then concatMap words libFlags else []) ++
src/Idris/REPL.hs+1−1
@@ -1189,7 +1189,7 @@ process fn (Execute tm)
1189 = idrisCatch
1189 = idrisCatch
1190 (do ist <- getIState
1190 (do ist <- getIState
1191 (m, _) <- elabVal recinfo ERHS (elabExec fc tm)
1191 (m, _) <- elabVal recinfo ERHS (elabExec fc tm)
1192− (tmpn, tmph) <- runIO tempfile
1192+ (tmpn, tmph) <- runIO $ tempfile ""
1193 runIO $ hClose tmph
1193 runIO $ hClose tmph
1194 t <- codegen
1194 t <- codegen
1195 -- gcc adds .exe when it builds windows programs
1195 -- gcc adds .exe when it builds windows programs
src/Pkg/Package.hs+3−6
@@ -164,7 +164,7 @@ testPkg fp
164 do m_ist <- inPkgDir pkgdesc $
164 do m_ist <- inPkgDir pkgdesc $
165 do make (makefile pkgdesc)
165 do make (makefile pkgdesc)
166 -- Get a temporary file to save the tests' source in
166 -- Get a temporary file to save the tests' source in
167− (tmpn, tmph) <- tempIdr
167+ (tmpn, tmph) <- tempfile ".idr"
168 hPutStrLn tmph $
168 hPutStrLn tmph $
169 "module Test_______\n" ++
169 "module Test_______\n" ++
170 concat ["import " ++ show m ++ "\n"
170 concat ["import " ++ show m ++ "\n"
@@ -175,7 +175,7 @@ testPkg fp
175 concat [show t ++ "\n "
175 concat [show t ++ "\n "
176 | t <- idris_tests pkgdesc]
176 | t <- idris_tests pkgdesc]
177 hClose tmph
177 hClose tmph
178− (tmpn', tmph') <- tempfile
178+ (tmpn', tmph') <- tempfile ""
179 hClose tmph'
179 hClose tmph'
180 m_ist <- idris (Filename tmpn : NoREPL : Verbose : Output tmpn' : idris_opts pkgdesc)
180 m_ist <- idris (Filename tmpn : NoREPL : Verbose : Output tmpn' : idris_opts pkgdesc)
181 rawSystem tmpn' []
181 rawSystem tmpn' []
@@ -187,9 +187,6 @@ testPkg fp
187 case errSpan ist of
187 case errSpan ist of
188 Just _ -> exitWith (ExitFailure 1)
188 Just _ -> exitWith (ExitFailure 1)
189 _ -> return ()
189 _ -> return ()
190− where tempIdr :: IO (FilePath, Handle)
191− tempIdr = do dir <- getTemporaryDirectory
192− openTempFile (normalise dir) "idristests.idr"
193
190
194-- | Install package
191-- | Install package
195installPkg :: PkgDesc -> IO ()
192installPkg :: PkgDesc -> IO ()
@@ -214,7 +211,7 @@ testLib :: Bool -> String -> String -> IO Bool
214testLib warn p f
211testLib warn p f
215 = do d <- getDataDir
212 = do d <- getDataDir
216 gcc <- getCC
213 gcc <- getCC
217− (tmpf, tmph) <- tempfile
214+ (tmpf, tmph) <- tempfile ""
218 hClose tmph
215 hClose tmph
219 let libtest = d </> "rts" </> "libtest.c"
216 let libtest = d </> "rts" </> "libtest.c"
220 e <- rawSystem gcc [libtest, "-l" ++ f, "-o", tmpf]
217 e <- rawSystem gcc [libtest, "-l" ++ f, "-o", tmpf]
src/Util/System.hs+4−3
@@ -37,9 +37,10 @@ throwIO = CE.throw
37isWindows :: Bool
37isWindows :: Bool
38isWindows = os `elem` ["win32", "mingw32", "cygwin32"]
38isWindows = os `elem` ["win32", "mingw32", "cygwin32"]
39
39
40+-- | Create a temp file with the extensiom ext (in the format ".xxx")
40−tempfile :: IO (FilePath, Handle)
41+tempfile :: String -> IO (FilePath, Handle)
41−tempfile = do dir <- getTemporaryDirectory
42+tempfile ext = do dir <- getTemporaryDirectory
42− openTempFile (normalise dir) "idris"
43+ openTempFile (normalise dir) $ "idris" ++ ext
43
44
44-- | Read a source file, same as readFile but make sure the encoding is utf-8.
45-- | Read a source file, same as readFile but make sure the encoding is utf-8.
45readSource :: FilePath -> IO String
46readSource :: FilePath -> IO String