summaryrefslogtreecommitdiff
path: root/src/Hadrian/Haskell/Cabal.hs
blob: ab5f334f9bd4e69e8cdf457c79bbff9b8e585577 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
-----------------------------------------------------------------------------
-- |
-- Module     : Hadrian.Haskell.Cabal
-- Copyright  : (c) Andrey Mokhov 2014-2017
-- License    : MIT (see the file LICENSE)
-- Maintainer : andrey.mokhov@gmail.com
-- Stability  : experimental
--
-- Basic functionality for extracting Haskell package metadata stored in
-- Cabal files.
-----------------------------------------------------------------------------
module Hadrian.Haskell.Cabal (
    pkgVersion, pkgIdentifier, pkgDependencies, pkgSynopsis
    ) where

import Development.Shake

import Hadrian.Haskell.Cabal.Parse
import Hadrian.Package
import Hadrian.Oracles.TextFile

-- | Read a Cabal file and return the package version. The Cabal file is tracked.
pkgVersion :: FilePath -> Action String
pkgVersion cabalFile = version <$> readCabalFile cabalFile

-- | Read a Cabal file and return the package identifier, e.g. @base-4.10.0.0@.
-- The Cabal file is tracked.
pkgIdentifier :: FilePath -> Action String
pkgIdentifier cabalFile = do
    cabal <- readCabalFile cabalFile
    return $ if null (version cabal)
        then name cabal
        else name cabal ++ "-" ++ version cabal

-- | Read a Cabal file and return the sorted list of the package dependencies.
-- The current version does not take care of Cabal conditionals and therefore
-- returns a crude overapproximation of actual dependencies. The Cabal file is
-- tracked.
pkgDependencies :: FilePath -> Action [PackageName]
pkgDependencies cabalFile = dependencies <$> readCabalFile cabalFile

-- | Read a Cabal file and return the package synopsis. The Cabal file is tracked.
pkgSynopsis :: FilePath -> Action String
pkgSynopsis cabalFile = synopsis <$> readCabalFile cabalFile