diff options
author | Ben Gamari <ben@smart-cactus.org> | 2018-10-23 14:20:13 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2018-10-23 14:20:13 -0400 |
commit | 94756201349685a34c4495addd3484fdfcc8b498 (patch) | |
tree | fd4a9cee20d3c2b79f56ded7e02fb0c01b26b6c9 /hadrian/src/Hadrian/Haskell/Cabal.hs | |
parent | 575b35f4cdc18045bccd42d341d6f25d95c0696c (diff) | |
parent | 45f3bff7016a2a0cd9a5455a882ced984655e90b (diff) | |
download | haskell-94756201349685a34c4495addd3484fdfcc8b498.tar.gz |
Add 'hadrian/' from commit '45f3bff7016a2a0cd9a5455a882ced984655e90b'
git-subtree-dir: hadrian
git-subtree-mainline: 575b35f4cdc18045bccd42d341d6f25d95c0696c
git-subtree-split: 45f3bff7016a2a0cd9a5455a882ced984655e90b
Diffstat (limited to 'hadrian/src/Hadrian/Haskell/Cabal.hs')
-rw-r--r-- | hadrian/src/Hadrian/Haskell/Cabal.hs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/hadrian/src/Hadrian/Haskell/Cabal.hs b/hadrian/src/Hadrian/Haskell/Cabal.hs new file mode 100644 index 0000000000..327e6a0618 --- /dev/null +++ b/hadrian/src/Hadrian/Haskell/Cabal.hs @@ -0,0 +1,56 @@ +----------------------------------------------------------------------------- +-- | +-- Module : Hadrian.Haskell.Cabal +-- Copyright : (c) Andrey Mokhov 2014-2018 +-- 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, pkgSynopsis, pkgDescription, pkgDependencies, + pkgGenericDescription + ) where + +import Development.Shake +import Distribution.PackageDescription (GenericPackageDescription) + +import Hadrian.Haskell.Cabal.Type +import Hadrian.Oracles.Cabal +import Hadrian.Package + +-- | Read a Cabal file and return the package version. The Cabal file is tracked. +pkgVersion :: Package -> Action String +pkgVersion = fmap version . readPackageData + +-- | Read a Cabal file and return the package identifier, e.g. @base-4.10.0.0@. +-- The Cabal file is tracked. +pkgIdentifier :: Package -> Action String +pkgIdentifier package = do + cabal <- readPackageData package + return $ if null (version cabal) + then name cabal + else name cabal ++ "-" ++ version cabal + +-- | Read a Cabal file and return the package synopsis. The Cabal file is tracked. +pkgSynopsis :: Package -> Action String +pkgSynopsis = fmap synopsis . readPackageData + +-- | Read a Cabal file and return the package description. The Cabal file is +-- tracked. +pkgDescription :: Package -> Action String +pkgDescription = fmap description . readPackageData + +-- | 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 :: Package -> Action [PackageName] +pkgDependencies = fmap (map pkgName . packageDependencies) . readPackageData + +-- | Read a Cabal file and return the 'GenericPackageDescription'. The Cabal +-- file is tracked. +pkgGenericDescription :: Package -> Action GenericPackageDescription +pkgGenericDescription = fmap genericPackageDescription . readPackageData |