Skip to content

Commit

Permalink
Adds support for ghc7.8
Browse files Browse the repository at this point in the history
  • Loading branch information
schell committed Mar 24, 2014
1 parent f2f931d commit fde2ae8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
4 changes: 4 additions & 0 deletions hdevtools.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,7 @@ executable hdevtools
if impl(ghc == 7.6.*)
build-depends: Cabal == 1.16.*
cpp-options: -DENABLE_CABAL

if impl(ghc >= 7.7)
build-depends: Cabal >= 1.18
cpp-options: -DENABLE_CABAL
39 changes: 37 additions & 2 deletions src/Cabal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ import Data.Char (isSpace)
import Data.List (foldl', nub, sort, find, isPrefixOf, isSuffixOf)
import Data.Monoid (Monoid(..))
import Distribution.Package (PackageIdentifier(..), PackageName)
import Distribution.PackageDescription (PackageDescription(..), Executable(..), TestSuite(..), Benchmark(..), emptyHookedBuildInfo)
import Distribution.PackageDescription (PackageDescription(..), Executable(..), TestSuite(..), Benchmark(..), emptyHookedBuildInfo, buildable, libBuildInfo)
import Distribution.PackageDescription.Parse (readPackageDescription)
import Distribution.Simple.Configure (configure)
import Distribution.Simple.LocalBuildInfo (LocalBuildInfo(..), ComponentLocalBuildInfo(..), Component(..), ComponentName(..), allComponentsBy, componentBuildInfo, foldComponent)
import Distribution.Simple.LocalBuildInfo (LocalBuildInfo(..), ComponentLocalBuildInfo(..),
Component(..), ComponentName(..),
#if __GLASGOW_HASKELL__ < 707
allComponentsBy,
#endif
componentBuildInfo, foldComponent)
import Distribution.Simple.Compiler (PackageDB(..))
import Distribution.Simple.GHC (componentGhcOptions)
import Distribution.Simple.Program (defaultProgramConfiguration)
Expand All @@ -37,6 +42,12 @@ componentName =
(CBenchName . benchmarkName)

getComponentLocalBuildInfo :: LocalBuildInfo -> ComponentName -> ComponentLocalBuildInfo
#if __GLASGOW_HASKELL__ >= 707
getComponentLocalBuildInfo lbi cname = getLocalBuildInfo cname $ componentsConfigs lbi
where getLocalBuildInfo cname' ((cname'', clbi, _):cfgs) =
if cname' == cname'' then clbi else getLocalBuildInfo cname' cfgs
getLocalBuildInfo _ [] = error $ "internal error: missing config"
#else
getComponentLocalBuildInfo lbi CLibName =
case libraryConfig lbi of
Nothing -> error $ "internal error: missing library config"
Expand All @@ -53,6 +64,30 @@ getComponentLocalBuildInfo lbi (CBenchName name) =
case lookup name (testSuiteConfigs lbi) of
Nothing -> error $ "internal error: missing config for benchmark " ++ name
Just clbi -> clbi
#endif

#if __GLASGOW_HASKELL__ >= 707
-- TODO: Fix callsites so we don't need `allComponentsBy`. It was taken from
-- http://hackage.haskell.org/package/Cabal-1.16.0.3/docs/src/Distribution-Simple-LocalBuildInfo.html#allComponentsBy
-- since it doesn't exist in Cabal 1.18.*
--
-- | Obtains all components (libs, exes, or test suites), transformed by the
-- given function. Useful for gathering dependencies with component context.
allComponentsBy :: PackageDescription
-> (Component -> a)
-> [a]
allComponentsBy pkg_descr f =
[ f (CLib lib) | Just lib <- [library pkg_descr]
, buildable (libBuildInfo lib) ]
++ [ f (CExe exe) | exe <- executables pkg_descr
, buildable (buildInfo exe) ]
++ [ f (CTest tst) | tst <- testSuites pkg_descr
, buildable (testBuildInfo tst)
, testEnabled tst ]
++ [ f (CBench bm) | bm <- benchmarks pkg_descr
, buildable (benchmarkBuildInfo bm)
, benchmarkEnabled bm ]
#endif


getPackageGhcOpts :: FilePath -> IO (Either String [String])
Expand Down

0 comments on commit fde2ae8

Please sign in to comment.