Occurrrence analysis improvements for NOINLINE functions
[ghc.git] / hadrian / 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 Development.Shake
17
18 import Hadrian.Haskell.Cabal.Parse
19 import Hadrian.Package
20 import Hadrian.Oracles.TextFile
21
22 -- | Read a Cabal file and return the package version. The Cabal file is tracked.
23 pkgVersion :: FilePath -> Action String
24 pkgVersion cabalFile = version <$> readCabalFile cabalFile
25
26 -- | Read a Cabal file and return the package identifier, e.g. @base-4.10.0.0@.
27 -- The Cabal file is tracked.
28 pkgIdentifier :: FilePath -> Action String
29 pkgIdentifier cabalFile = do
30 cabal <- readCabalFile cabalFile
31 return $ if null (version cabal)
32 then name cabal
33 else name cabal ++ "-" ++ version cabal
34
35 -- | Read a Cabal file and return the sorted list of the package dependencies.
36 -- The current version does not take care of Cabal conditionals and therefore
37 -- returns a crude overapproximation of actual dependencies. The Cabal file is
38 -- tracked.
39 pkgDependencies :: FilePath -> Action [PackageName]
40 pkgDependencies cabalFile = dependencies <$> readCabalFile cabalFile
41
42 -- | Read a Cabal file and return the package synopsis. The Cabal file is tracked.
43 pkgSynopsis :: FilePath -> Action String
44 pkgSynopsis cabalFile = synopsis <$> readCabalFile cabalFile