Commit 658d373c authored by Andrey Mokhov's avatar Andrey Mokhov
Browse files

Move Base.removeFileIfExists to Rules.Actions.removeFile.

See #163.
parent ad53022e
......@@ -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:
......
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
......
......@@ -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
......
......@@ -29,7 +29,7 @@ buildPackageDependencies rs context@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
......
......@@ -22,7 +22,7 @@ buildPackageLibrary context@Context {..} = do
-- TODO: handle dynamic libraries
matchVersionedFilePath libPrefix (waySuffix way <.> "a") ?> \a -> do
removeFileIfExists a
removeFile a
cSrcs <- cSources context
hSrcs <- hSources context
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment