git.iko.soy/typeable/cabal2nix
on master help sign in
Merge pull request #81 from bennofs/fix-compile-errors
fb1f0b0Peter Simons
src/Cabal2Nix/Package.hs+6−3
@@ -18,10 +18,10 @@ import qualified Distribution.Hackage.DB as DB
18import qualified Distribution.Package as Cabal
18import qualified Distribution.Package as Cabal
19import qualified Distribution.PackageDescription as Cabal
19import qualified Distribution.PackageDescription as Cabal
20import qualified Distribution.PackageDescription.Parse as Cabal
20import qualified Distribution.PackageDescription.Parse as Cabal
21−
22−import qualified Distribution.Compat.Exception as Compat
23import qualified Distribution.ParseUtils as ParseUtils
21import qualified Distribution.ParseUtils as ParseUtils
24
22
23+import qualified Control.Exception as Exception
24+
25data Package = Package
25data Package = Package
26 { source :: DerivationSource
26 { source :: DerivationSource
27 , cabal :: Cabal.GenericPackageDescription
27 , cabal :: Cabal.GenericPackageDescription
@@ -123,13 +123,16 @@ cabalFromDirectory dir = do
123 [cabalFile] -> cabalFromFile True cabalFile
123 [cabalFile] -> cabalFromFile True cabalFile
124 _ -> liftIO $ hPutStrLn stderr "*** found zero or more than one cabal file. Exiting." >> exitFailure
124 _ -> liftIO $ hPutStrLn stderr "*** found zero or more than one cabal file. Exiting." >> exitFailure
125
125
126+handleIO :: (Exception.IOException -> IO a) -> IO a -> IO a
127+handleIO = Exception.handle
128+
126cabalFromFile :: Bool -> FilePath -> MaybeT IO Cabal.GenericPackageDescription
129cabalFromFile :: Bool -> FilePath -> MaybeT IO Cabal.GenericPackageDescription
127cabalFromFile failHard file =
130cabalFromFile failHard file =
128 -- readFile throws an error if it's used on binary files which contain sequences
131 -- readFile throws an error if it's used on binary files which contain sequences
129 -- that do not represent valid characters. To catch that exception, we need to
132 -- that do not represent valid characters. To catch that exception, we need to
130 -- wrap the whole block in `catchIO`, because of lazy IO. The `case` will force
133 -- wrap the whole block in `catchIO`, because of lazy IO. The `case` will force
131 -- the reading of the file, so we will always catch the expression here.
134 -- 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
133 content <- readFile file
136 content <- readFile file
134 case Cabal.parsePackageDescription content of
137 case Cabal.parsePackageDescription content of
135 Cabal.ParseFailed e | failHard -> do
138 Cabal.ParseFailed e | failHard -> do