+ case exitStatus of
+ ExitFailure _ -> die $ action ++ " failed\ncommand was: " ++ cmdLine ++ "\n"
+ _ -> return ()
+
+
+-- delay the cleanup of generated files until the end; attempts to
+-- get around intermittent failure to delete files which has
+-- just been exec'ed by a sub-process (Win32 only.)
+finallyRemove :: FilePath -> IO a -> IO a
+finallyRemove fp act =
+ bracket_ (return fp)
+ (const $ noisyRemove fp)
+ act
+ where
+ noisyRemove fpath =
+ catch (removeFile fpath)
+ (\ e -> hPutStrLn stderr ("Failed to remove file " ++ fpath ++ "; error= " ++ show e))