on master help sign in
Allow an extension on tempfiles
commit609835e62c7e6866408e2096a2bcbe1937ead042 authorNiklas Larsson <niklas@mm.st> dateMon 5 Oct 2015, 12:53 (11 years ago) parentbf1a1ef
4 files changed+10−12
src/IRTS/CodegenC.hs+2−2 src/Idris/REPL.hs+1−1 src/Pkg/Package.hs+3−6 src/Util/System.hs+4−3
src/IRTS/CodegenC.hs+2−2
@@ -66,7 +66,7 @@ codegenC' defs out exec incs objs libs flags exports iface dbg
6666 MavenProject -> putStrLn ("FAILURE: output type not supported")
6767 Raw -> writeSource out cout
6868 _ -> do
69− (tmpn, tmph) <- tempfile
69+ (tmpn, tmph) <- tempfile ".c"
7070 hPutStr tmph cout
7171 hFlush tmph
7272 hClose tmph
@@ -78,7 +78,7 @@ codegenC' defs out exec incs objs libs flags exports iface dbg
7878 gccFlags iface ++
7979 -- # Any flags defined here which alter the RTS API must also be added to config.mk
8080 ["-DHAS_PTHREAD", "-DIDRIS_ENABLE_STATS",
81− "-I."] ++ objs ++ ["-x", "c"] ++ envFlags ++
81+ "-I."] ++ objs ++ envFlags ++
8282 (if (exec == Executable) then [] else ["-c"]) ++
8383 [tmpn] ++
8484 (if not iface then concatMap words libFlags else []) ++
src/Idris/REPL.hs+1−1
@@ -1189,7 +1189,7 @@ process fn (Execute tm)
11891189 = idrisCatch
11901190 (do ist <- getIState
11911191 (m, _) <- elabVal recinfo ERHS (elabExec fc tm)
1192− (tmpn, tmph) <- runIO tempfile
1192+ (tmpn, tmph) <- runIO $ tempfile ""
11931193 runIO $ hClose tmph
11941194 t <- codegen
11951195 -- gcc adds .exe when it builds windows programs
src/Pkg/Package.hs+3−6
@@ -164,7 +164,7 @@ testPkg fp
164164 do m_ist <- inPkgDir pkgdesc $
165165 do make (makefile pkgdesc)
166166 -- Get a temporary file to save the tests' source in
167− (tmpn, tmph) <- tempIdr
167+ (tmpn, tmph) <- tempfile ".idr"
168168 hPutStrLn tmph $
169169 "module Test_______\n" ++
170170 concat ["import " ++ show m ++ "\n"
@@ -175,7 +175,7 @@ testPkg fp
175175 concat [show t ++ "\n "
176176 | t <- idris_tests pkgdesc]
177177 hClose tmph
178− (tmpn', tmph') <- tempfile
178+ (tmpn', tmph') <- tempfile ""
179179 hClose tmph'
180180 m_ist <- idris (Filename tmpn : NoREPL : Verbose : Output tmpn' : idris_opts pkgdesc)
181181 rawSystem tmpn' []
@@ -187,9 +187,6 @@ testPkg fp
187187 case errSpan ist of
188188 Just _ -> exitWith (ExitFailure 1)
189189 _ -> return ()
190− where tempIdr :: IO (FilePath, Handle)
191− tempIdr = do dir <- getTemporaryDirectory
192− openTempFile (normalise dir) "idristests.idr"
193190
194191-- | Install package
195192installPkg :: PkgDesc -> IO ()
@@ -214,7 +211,7 @@ testLib :: Bool -> String -> String -> IO Bool
214211testLib warn p f
215212 = do d <- getDataDir
216213 gcc <- getCC
217− (tmpf, tmph) <- tempfile
214+ (tmpf, tmph) <- tempfile ""
218215 hClose tmph
219216 let libtest = d </> "rts" </> "libtest.c"
220217 e <- rawSystem gcc [libtest, "-l" ++ f, "-o", tmpf]
src/Util/System.hs+4−3
@@ -37,9 +37,10 @@ throwIO = CE.throw
3737isWindows :: Bool
3838isWindows = os `elem` ["win32", "mingw32", "cygwin32"]
3939
40−tempfile :: IO (FilePath, Handle)
41−tempfile = do dir <- getTemporaryDirectory
42− openTempFile (normalise dir) "idris"
40+-- | Create a temp file with the extensiom ext (in the format ".xxx")
41+tempfile :: String -> IO (FilePath, Handle)
42+tempfile ext = do dir <- getTemporaryDirectory
43+ openTempFile (normalise dir) $ "idris" ++ ext
4344
4445-- | Read a source file, same as readFile but make sure the encoding is utf-8.
4546readSource :: FilePath -> IO String