Cabal.hs 1.32 KB
Newer Older
Andrey Mokhov's avatar
Andrey Mokhov committed
1
2
3
4
5
6
7
8
9
10
11
-----------------------------------------------------------------------------
-- |
-- 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.
-----------------------------------------------------------------------------
12
module Hadrian.Haskell.Cabal (pkgNameVersion, pkgDependencies) where
13
14
15

import Development.Shake

16
import Hadrian.Haskell.Cabal.Parse
Andrey Mokhov's avatar
Andrey Mokhov committed
17
import Hadrian.Haskell.Package
18
import Hadrian.Oracles.TextFile
19

Andrey Mokhov's avatar
Andrey Mokhov committed
20
21
22
23
-- | Read the @.cabal@ file of a given package and return the package name and
-- version. The @.cabal@ file is tracked.
pkgNameVersion :: Package -> Action (PackageName, String)
pkgNameVersion pkg = do
24
25
    cabal <- readCabalFile (pkgCabalFile pkg)
    return (name cabal, version cabal)
26

27
-- | Read the @.cabal@ file of a given package and return the sorted list of its
Andrey Mokhov's avatar
Andrey Mokhov committed
28
-- dependencies. The current version does not take care of Cabal conditionals
29
30
-- and therefore returns a crude overapproximation of actual dependencies. The
-- @.cabal@ file is tracked.
Andrey Mokhov's avatar
Andrey Mokhov committed
31
32
pkgDependencies :: Package -> Action [PackageName]
pkgDependencies pkg = do
33
    cabal <- readCabalFile (pkgCabalFile pkg)
Andrey Mokhov's avatar
Andrey Mokhov committed
34
    return (dependencies cabal)