-----------------------------------------------------------------------------
--- $Id: DriverPhases.hs,v 1.26 2003/06/05 10:11:22 simonmar Exp $
+-- $Id: DriverPhases.hs,v 1.27 2003/06/26 21:55:47 sof Exp $
--
-- GHC Driver
--
objish_file, objish_suffix,
cish_file, cish_suffix,
isExtCore_file, extcoreish_suffix,
+ haskellish_user_src_file,
isSourceFile -- :: FilePath -> Bool
) where
phaseInputExt Ilasm = "il"
#endif
-haskellish_suffix = (`elem` [ "hs", "lhs", "hspp", "hscpp", "hcr", "hc", "raw_s" ])
-haskellish_src_suffix = (`elem` [ "hs", "lhs", "hspp", "hscpp", "hcr"])
-cish_suffix = (`elem` [ "c", "cpp", "C", "cc", "cxx", "s", "S" ])
-extcoreish_suffix = (`elem` [ "hcr" ])
+haskellish_suffix = (`elem` [ "hs", "lhs", "hspp", "hscpp", "hcr", "hc", "raw_s" ])
+haskellish_src_suffix = (`elem` [ "hs", "lhs", "hspp", "hscpp", "hcr"])
+cish_suffix = (`elem` [ "c", "cpp", "C", "cc", "cxx", "s", "S" ])
+extcoreish_suffix = (`elem` [ "hcr" ])
+haskellish_user_src_suffix = (`elem` [ "hs", "lhs" ])
-- Use the appropriate suffix for the system on which
-- the GHC-compiled code will run
objish_suffix = (`elem` [ "o" ])
#endif
-haskellish_file = haskellish_suffix . getFileSuffix
-haskellish_src_file = haskellish_src_suffix . getFileSuffix
-cish_file = cish_suffix . getFileSuffix
-isExtCore_file = extcoreish_suffix . getFileSuffix
-objish_file = objish_suffix . getFileSuffix
+haskellish_file = haskellish_suffix . getFileSuffix
+haskellish_src_file = haskellish_src_suffix . getFileSuffix
+cish_file = cish_suffix . getFileSuffix
+isExtCore_file = extcoreish_suffix . getFileSuffix
+objish_file = objish_suffix . getFileSuffix
+haskellish_user_src_file = haskellish_user_src_suffix . getFileSuffix
isSourceFile :: FilePath -> Bool
isSourceFile f =
#include "HsVersions.h"
import DriverUtil
+import DriverPhases ( haskellish_user_src_file )
import Config
import Outputable
import Panic ( progName, GhcException(..) )
openFile, hPutChar, hPutStrLn, hPutStr, hClose, hFlush, IOMode(..),
stderr )
import Directory ( doesFileExist, removeFile )
-import List ( intersperse )
+import List ( intersperse, partition )
#include "../includes/config.h"
removeTmpFiles :: Int -> [FilePath] -> IO ()
removeTmpFiles verb fs
- = traceCmd "Deleting temp files"
- ("Deleting: " ++ unwords fs)
- (mapM_ rm fs)
+ = warnNon $
+ traceCmd "Deleting temp files"
+ ("Deleting: " ++ unwords deletees)
+ (mapM_ rm deletees)
where
+ -- Flat out refuse to delete files that are likely to be source input
+ -- files (is there a worse bug than having a compiler delete your source
+ -- files?)
+ --
+ -- Deleting source files is a sign of a bug elsewhere, so prominently flag
+ -- the condition.
+ warnNon act
+ | null non_deletees = act
+ | otherwise = do
+ hPutStrLn stderr ("WARNING - NOT deleting source files: " ++ unwords non_deletees)
+ act
+
+ (non_deletees, deletees) = partition haskellish_user_src_file fs
+
rm f = removeFile f `IO.catch`
(\_ignored ->
when (verb >= 2) $