parent
0960d01f8d
commit
b3b85c4583
@ -1,35 +0,0 @@ |
||||
{-# LANGUAGE NoImplicitPrelude #-} |
||||
{-# LANGUAGE CPP #-} |
||||
|
||||
module Distribution.CurrentPackageDescription |
||||
( currentPackageDescription |
||||
, getField |
||||
) where |
||||
|
||||
import Prelude.Compat |
||||
import Distribution.PackageDescription |
||||
import Distribution.PackageDescription.Parse |
||||
import Distribution.Verbosity |
||||
|
||||
import Data.List (isSuffixOf) |
||||
import Language.Haskell.TH (stringE, runIO, Q, Exp) |
||||
import System.Directory (getCurrentDirectory, getDirectoryContents) |
||||
|
||||
|
||||
getField :: (PackageDescription -> String) -> Q Exp |
||||
getField f = runIO currentPackageDescription >>= stringE . f |
||||
|
||||
currentPackageDescription :: IO PackageDescription |
||||
currentPackageDescription = fmap packageDescription $ do |
||||
dir <- getCurrentDirectory |
||||
cs <- cabalFiles dir |
||||
case cs of |
||||
#if MIN_VERSION_base(4,10,0) |
||||
(c:_) -> readGenericPackageDescription silent c |
||||
#else |
||||
(c:_) -> readPackageDescription silent c |
||||
#endif |
||||
[] -> error $ "Couldn't find a cabal file in the current working directory (" ++ dir ++ ")" |
||||
|
||||
cabalFiles :: FilePath -> IO [FilePath] |
||||
cabalFiles dir = filter (".cabal" `isSuffixOf`) <$> getDirectoryContents dir |
Loading…
Reference in new issue