[project @ 2003-06-26 21:55:46 by sof]
authorsof <unknown>
Thu, 26 Jun 2003 21:55:47 +0000 (21:55 +0000)
committersof <unknown>
Thu, 26 Jun 2003 21:55:47 +0000 (21:55 +0000)
SysTools.removeTmpFiles:
  - never delete source files with a DriverPhases.haskellish_user_src_file
    file extension & loudly complain should the compiler attempt to do so.

    This is a protective measure against bugs elsewhere in the driver pipeline
    (cf., 'ghc-6.0 --make' deleting input files if specified using backward
     instead of forward slashes under win32.)

ghc/compiler/main/DriverPhases.hs
ghc/compiler/main/SysTools.lhs

index 14cf635..8d67ae0 100644 (file)
@@ -1,5 +1,5 @@
 -----------------------------------------------------------------------------
--- $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
 --
@@ -20,6 +20,7 @@ module DriverPhases (
    objish_file, objish_suffix,
    cish_file, cish_suffix,
    isExtCore_file, extcoreish_suffix,
+   haskellish_user_src_file,
    isSourceFile         -- :: FilePath -> Bool
  ) where
 
@@ -106,10 +107,11 @@ phaseInputExt Ilx2Il      = "ilx"
 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
@@ -119,11 +121,12 @@ objish_suffix     = (`elem` [ "o", "O", "obj", "OBJ" ])
 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    =
index 6f73313..e5fafdd 100644 (file)
@@ -65,6 +65,7 @@ module SysTools (
 #include "HsVersions.h"
 
 import DriverUtil
+import DriverPhases     ( haskellish_user_src_file )
 import Config
 import Outputable
 import Panic           ( progName, GhcException(..) )
@@ -81,7 +82,7 @@ import IO             ( try, catch,
                          openFile, hPutChar, hPutStrLn, hPutStr, hClose, hFlush, IOMode(..),
                          stderr )
 import Directory       ( doesFileExist, removeFile )
-import List             ( intersperse )
+import List             ( intersperse, partition )
 
 #include "../includes/config.h"
 
@@ -681,10 +682,25 @@ addFilesToClean files = mapM_ (add v_FilesToClean) files
 
 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) $