git.iko.soy/typeable/cabal2nix
on master help sign in
Merge pull request #81 from bennofs/fix-compile-errors

fix compile errors on older versions of Cabal

commitfb1f0b02e025e1f216871da2a03289a8036fbe83 authorPeter Simons <simons@cryp.to> dateTue 19 Aug 2014, 15:19 (12 years ago) parent997bd024309feb
1 file changed+6−3
src/Cabal2Nix/Package.hs+6−3
src/Cabal2Nix/Package.hs+6−3
@@ -18,10 +18,10 @@ import qualified Distribution.Hackage.DB as DB
1818import qualified Distribution.Package as Cabal
1919import qualified Distribution.PackageDescription as Cabal
2020import qualified Distribution.PackageDescription.Parse as Cabal
21−
22−import qualified Distribution.Compat.Exception as Compat
2321import qualified Distribution.ParseUtils as ParseUtils
2422
23+import qualified Control.Exception as Exception
24+
2525data Package = Package
2626 { source :: DerivationSource
2727 , cabal :: Cabal.GenericPackageDescription
@@ -123,13 +123,16 @@ cabalFromDirectory dir = do
123123 [cabalFile] -> cabalFromFile True cabalFile
124124 _ -> liftIO $ hPutStrLn stderr "*** found zero or more than one cabal file. Exiting." >> exitFailure
125125
126+handleIO :: (Exception.IOException -> IO a) -> IO a -> IO a
127+handleIO = Exception.handle
128+
126129cabalFromFile :: Bool -> FilePath -> MaybeT IO Cabal.GenericPackageDescription
127130cabalFromFile failHard file =
128131 -- readFile throws an error if it's used on binary files which contain sequences
129132 -- that do not represent valid characters. To catch that exception, we need to
130133 -- wrap the whole block in `catchIO`, because of lazy IO. The `case` will force
131134 -- the reading of the file, so we will always catch the expression here.
132− MaybeT $ flip Compat.catchIO (const $ return Nothing) $ do
135+ MaybeT $ handleIO (const $ return Nothing) $ do
133136 content <- readFile file
134137 case Cabal.parsePackageDescription content of
135138 Cabal.ParseFailed e | failHard -> do