Use Cabal directly in place of ghc-cabal + make build root configurable (#531)
[hadrian.git] / src / Hadrian / Haskell / Cabal.hs
1 -----------------------------------------------------------------------------
2 -- |
3 -- Module : Hadrian.Haskell.Cabal
4 -- Copyright : (c) Andrey Mokhov 2014-2017
5 -- License : MIT (see the file LICENSE)
6 -- Maintainer : andrey.mokhov@gmail.com
7 -- Stability : experimental
8 --
9 -- Basic functionality for extracting Haskell package metadata stored in
10 -- Cabal files.
11 -----------------------------------------------------------------------------
12 module Hadrian.Haskell.Cabal (
13 pkgVersion, pkgIdentifier, pkgDependencies, pkgSynopsis
14 ) where
15
16 import Data.Maybe
17 import Development.Shake
18
19 import Context.Type
20 import Hadrian.Haskell.Cabal.Type as C
21 import Hadrian.Haskell.Cabal.PackageData as PD
22 import Hadrian.Package
23 import Hadrian.Oracles.TextFile
24
25 -- | Read a Cabal file and return the package version. The Cabal file is tracked.
26 pkgVersion :: Context -> Action (Maybe String)
27 pkgVersion = fmap (fmap C.version) . readCabalFile
28
29 -- | Read a Cabal file and return the package identifier, e.g. @base-4.10.0.0@.
30 -- The Cabal file is tracked.
31 pkgIdentifier :: Context -> Action String
32 pkgIdentifier ctx = do
33 cabal <- fromMaybe (error "Cabal file could not be read") <$> readCabalFile ctx
34 return $ if null (C.version cabal)
35 then C.name cabal
36 else C.name cabal ++ "-" ++ C.version cabal
37
38 -- | Read a Cabal file and return the sorted list of the package dependencies.
39 -- The current version does not take care of Cabal conditionals and therefore
40 -- returns a crude overapproximation of actual dependencies. The Cabal file is
41 -- tracked.
42 pkgDependencies :: Context -> Action (Maybe [PackageName])
43 pkgDependencies = fmap (fmap PD.dependencies) . readPackageDataFile
44
45 -- | Read a Cabal file and return the package synopsis. The Cabal file is tracked.
46 pkgSynopsis :: Context -> Action (Maybe String)
47 pkgSynopsis = fmap (fmap C.synopsis) . readCabalFile