[commit: ghc] wip/nfs-locking: Move Base.removeFileIfExists to Rules.Actions.removeFile. (658d373)

git at git.haskell.org git at git.haskell.org
Fri Oct 27 00:58:34 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/nfs-locking
Link       : http://ghc.haskell.org/trac/ghc/changeset/658d373c5b823792758e7d3ccb0577b6ecb24c82/ghc

>---------------------------------------------------------------

commit 658d373c5b823792758e7d3ccb0577b6ecb24c82
Author: Andrey Mokhov <andrey.mokhov at gmail.com>
Date:   Thu May 5 03:59:50 2016 +0100

    Move Base.removeFileIfExists to Rules.Actions.removeFile.
    
    See #163.


>---------------------------------------------------------------

658d373c5b823792758e7d3ccb0577b6ecb24c82
 src/Base.hs               | 7 +------
 src/Rules/Actions.hs      | 8 +++++++-
 src/Rules/Clean.hs        | 4 +---
 src/Rules/Dependencies.hs | 2 +-
 src/Rules/Library.hs      | 2 +-
 5 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/src/Base.hs b/src/Base.hs
index ccadd22..a26fea1 100644
--- a/src/Base.hs
+++ b/src/Base.hs
@@ -23,7 +23,7 @@ module Base (
     -- * Miscellaneous utilities
     minusOrd, intersectOrd, lookupAll, replaceEq, quote, replaceSeparators,
     decodeModule, encodeModule, unifyPath, (-/-), versionToInt,
-    removeFileIfExists, matchVersionedFilePath
+    matchVersionedFilePath
     ) where
 
 import Control.Applicative
@@ -39,7 +39,6 @@ import Development.Shake hiding (parallel, unit, (*>), Normal)
 import Development.Shake.Classes
 import Development.Shake.FilePath
 import System.Console.ANSI
-import qualified System.Directory as IO
 import System.IO
 
 -- TODO: reexport Stage, etc.?
@@ -172,10 +171,6 @@ lookupAll (x:xs) (y:ys) = case compare x (fst y) of
     EQ -> Just (snd y) : lookupAll xs (y:ys)
     GT -> lookupAll (x:xs) ys
 
--- | Remove a file that doesn't necessarily exist
-removeFileIfExists :: FilePath -> Action ()
-removeFileIfExists f = liftIO . whenM (IO.doesFileExist f) $ IO.removeFile f
-
 -- | Given a @prefix@ and a @suffix@ check whether a @filePath@ matches the
 -- template @prefix ++ version ++ suffix@ where @version@ is an arbitrary string
 -- comprising digits (@0-9@), dashes (@-@), and dots (@.@). Examples:
diff --git a/src/Rules/Actions.hs b/src/Rules/Actions.hs
index 25bf72e..9910ce5 100644
--- a/src/Rules/Actions.hs
+++ b/src/Rules/Actions.hs
@@ -1,6 +1,6 @@
 module Rules.Actions (
     build, buildWithResources, buildWithCmdOptions, copyFile, moveFile,
-    createDirectory, removeDirectory, copyDirectory, moveDirectory,
+    removeFile, createDirectory, removeDirectory, copyDirectory, moveDirectory,
     applyPatch, fixFile, runMake, runMakeVerbose, renderLibrary, renderProgram,
     runBuilder, makeExecutable
     ) where
@@ -94,6 +94,12 @@ moveFile source target = do
     putProgressInfo $ renderAction "Move file" source target
     liftIO $ IO.renameFile source target
 
+-- | Remove a file that doesn't necessarily exist.
+removeFile :: FilePath -> Action ()
+removeFile file = do
+    putBuild $ "| Remove file " ++ file
+    liftIO . whenM (IO.doesFileExist file) $ IO.removeFile file
+
 createDirectory :: FilePath -> Action ()
 createDirectory dir = do
     putBuild $ "| Create directory " ++ dir
diff --git a/src/Rules/Clean.hs b/src/Rules/Clean.hs
index f615e54..613073a 100644
--- a/src/Rules/Clean.hs
+++ b/src/Rules/Clean.hs
@@ -17,9 +17,7 @@ cleanRules = do
         removeDirectory programInplacePath
         removeDirectory "inplace/lib"
         removeDirectory derivedConstantsPath
-        forM_ includesDependencies $ \file -> do
-            putBuild $ "| Remove " ++ file
-            removeFileIfExists file
+        forM_ includesDependencies removeFile
         putBuild $ "| Remove files generated by ghc-cabal..."
         forM_ knownPackages $ \pkg ->
             forM_ [Stage0 ..] $ \stage -> do
diff --git a/src/Rules/Dependencies.hs b/src/Rules/Dependencies.hs
index 9059b3d..f5d781a 100644
--- a/src/Rules/Dependencies.hs
+++ b/src/Rules/Dependencies.hs
@@ -29,7 +29,7 @@ buildPackageDependencies rs context at Context {..} =
             then writeFileChanged out ""
             else buildWithResources rs $
                 Target context (Ghc FindDependencies stage) srcs [out]
-            removeFileIfExists $ out <.> "bak"
+            removeFile $ out <.> "bak"
 
         -- TODO: don't accumulate *.deps into .dependencies
         path -/- ".dependencies" %> \out -> do
diff --git a/src/Rules/Library.hs b/src/Rules/Library.hs
index 8e09162..2b90d1f 100644
--- a/src/Rules/Library.hs
+++ b/src/Rules/Library.hs
@@ -22,7 +22,7 @@ buildPackageLibrary context at Context {..} = do
 
     -- TODO: handle dynamic libraries
     matchVersionedFilePath libPrefix (waySuffix way <.> "a") ?> \a -> do
-        removeFileIfExists a
+        removeFile a
         cSrcs <- cSources context
         hSrcs <- hSources context
 



More information about the ghc-commits mailing list