Cabal.hs 1.36 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
import Data.List
15
16
import Development.Shake

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

Andrey Mokhov's avatar
Andrey Mokhov committed
21
22
23
24
-- | 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
25
26
    cabal <- readCabalFile (pkgCabalFile pkg)
    return (name cabal, version cabal)
27

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