Tool to transform OLTP database schemas to OLAP database schemas automatically
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CurrentPackageDescription.hs 1.1KB

1234567891011121314151617181920212223242526272829303132333435
  1. {-# LANGUAGE NoImplicitPrelude #-}
  2. {-# LANGUAGE CPP #-}
  3. module Distribution.CurrentPackageDescription
  4. ( currentPackageDescription
  5. , getField
  6. ) where
  7. import Prelude.Compat
  8. import Distribution.PackageDescription
  9. import Distribution.PackageDescription.Parse
  10. import Distribution.Verbosity
  11. import Data.List (isSuffixOf)
  12. import Language.Haskell.TH (stringE, runIO, Q, Exp)
  13. import System.Directory (getCurrentDirectory, getDirectoryContents)
  14. getField :: (PackageDescription -> String) -> Q Exp
  15. getField f = runIO currentPackageDescription >>= stringE . f
  16. currentPackageDescription :: IO PackageDescription
  17. currentPackageDescription = fmap packageDescription $ do
  18. dir <- getCurrentDirectory
  19. cs <- cabalFiles dir
  20. case cs of
  21. #if MIN_VERSION_base(4,10,0)
  22. (c:_) -> readGenericPackageDescription silent c
  23. #else
  24. (c:_) -> readPackageDescription silent c
  25. #endif
  26. [] -> error $ "Couldn't find a cabal file in the current working directory (" ++ dir ++ ")"
  27. cabalFiles :: FilePath -> IO [FilePath]
  28. cabalFiles dir = filter (".cabal" `isSuffixOf`) <$> getDirectoryContents dir