Skip to content

Commit

Permalink
Update for ghc-7.6.1 not exporting catch from Prelude anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottt committed Oct 16, 2012
1 parent 7c7ba69 commit 6504244
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
3 changes: 3 additions & 0 deletions cabal-dev.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ Executable cabal-dev
Build-depends:
containers == 0.1.0.2

if impl(ghc >= 7.6.1)
CPP-Options: -DNO_PRELUDE_CATCH

Build-depends:
bytestring >= 0.9 && < 0.11,
directory >= 1.0 && < 1.3,
Expand Down
4 changes: 4 additions & 0 deletions src/Distribution/Dev/AddSource.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ where
#define MIN_VERSION_Cabal(a,b,c) 1
#endif

#ifdef NO_PRELUDE_CATCH
import Control.Exception ( catch )
#endif

import Control.Applicative ( (<$>), (<*>) )
import Control.Arrow ( right )
import Control.Exception ( bracket )
Expand Down
20 changes: 16 additions & 4 deletions src/Distribution/Dev/RewriteCabalConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ This module is written so that it will work out-of-the-box with GHC >=
6.8 && < 6.13 with no other packages installed.
-}
{-# LANGUAGE CPP #-}

module Distribution.Dev.RewriteCabalConfig
( rewriteCabalConfig
, Rewrite(..)
Expand All @@ -18,6 +20,10 @@ module Distribution.Dev.RewriteCabalConfig
)
where

#ifdef NO_PRELUDE_CATCH
import Control.Exception ( catch, IOException )
#endif

import Control.Applicative ( Applicative, pure, (<$>) )
import Data.Maybe ( fromMaybe )
import Data.Traversable ( traverse, Traversable )
Expand All @@ -38,8 +44,14 @@ readConfig s = case readFields s of

-- XXX: we should avoid this lazy IO that leaks a file handle.
readConfigF :: FilePath -> IO (Either String [Field])
readConfigF fn =
(readConfig <$> readUTF8File fn) `catch` \e -> return $ Left $ show e
readConfigF fn = (readConfig <$> readUTF8File fn) `catch` handler
where
#ifdef NO_PRELUDE_CATCH
handler :: IOException -> IO (Either String [Field])
handler = return . Left . show
#else
handler = return . Left . show
#endif

readConfigF_ :: FilePath -> IO [Field]
readConfigF_ fn = either error id <$> readConfigF fn
Expand Down Expand Up @@ -72,8 +84,8 @@ rewriteField expand field =
F l name val -> F l name <$> rewriteLeaf name val
Section l name key fs -> Section l name key <$>
rewriteSection name fs
_ -> error $ "Only top-level fields and sections \
\supported. Not: " ++ show field
_ -> error $ "Only top-level fields and sections "
++ "supported. Not: " ++ show field
where
rewriteLeaf name val
| name `elem` eLeaves expand = eExpand expand val
Expand Down
4 changes: 4 additions & 0 deletions src/Distribution/Dev/Sandbox.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import System.Directory ( createDirectoryIfMissing
, doesFileExist, copyFile )
import System.FilePath ( (</>) )

#ifdef NO_PRELUDE_CATCH
import Control.Exception ( catch )
#endif

#ifdef mingw32_HOST_OS
import System.IO ( hPutStrLn, stderr )
import System.Win32.Types ( getLastError )
Expand Down

0 comments on commit 6504244

Please sign in to comment.