Commit 4bf5ccdb authored by Saizan's avatar Saizan
Browse files

move inDir to Distribution.Simple.Utils

parent a8a1e2ea
......@@ -31,7 +31,6 @@ import Distribution.Simple.Program ( ProgramConfiguration,
import Distribution.Simple.GHC (ghcVerbosityOptions)
import Distribution.GetOpt
import System.Directory
import Control.Exception ( finally )
import Distribution.Verbosity
import System.FilePath ((</>), (<.>))
import Control.Monad ( when, unless )
......@@ -113,13 +112,6 @@ buildTypes = [
"import Distribution.Simple; main=defaultMainWithHooks autoconfUserHooks")),
(Make, (Make.defaultMainArgs, "import Distribution.Make; main=defaultMain"))]
inDir :: Maybe FilePath -> IO () -> IO ()
inDir Nothing m = m
inDir (Just d) m = do
old <- getCurrentDirectory
setCurrentDirectory d
m `finally` setCurrentDirectory old
data Flags
= Flags {
withCompiler :: Maybe FilePath,
......
......@@ -61,6 +61,7 @@ module Distribution.Simple.Utils (
rawSystemStdout',
maybeExit,
xargs,
inDir,
-- * copying files
smartCopySources,
......@@ -113,7 +114,7 @@ import Data.Bits
( Bits((.|.), (.&.), shiftL, shiftR) )
import System.Directory
( getDirectoryContents, getCurrentDirectory, doesDirectoryExist
( getDirectoryContents, getCurrentDirectory, setCurrentDirectory, doesDirectoryExist
, doesFileExist, removeFile )
import System.Environment
( getProgName )
......@@ -131,7 +132,7 @@ import System.IO
import System.IO.Error as IO.Error
( try )
import qualified Control.Exception as Exception
( bracket, bracketOnError, catch )
( bracket, bracketOnError, catch, finally )
import Distribution.Package
(PackageIdentifier, showPackageId)
......@@ -364,6 +365,14 @@ xargs maxSize rawSystemFun fixedArgs bigArgs =
| otherwise = (reverse acc, s:ss)
where len' = length s
-- | Executes the action in the specified directory.
inDir :: Maybe FilePath -> IO () -> IO ()
inDir Nothing m = m
inDir (Just d) m = do
old <- getCurrentDirectory
setCurrentDirectory d
m `Exception.finally` setCurrentDirectory old
-- ------------------------------------------------------------
-- * File Utilities
-- ------------------------------------------------------------
......
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