blob: 92865e7accf23001477badc3e96867e12f93b424 (
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
|
module Coolbal.Configure (configure) where
import Distribution.PackageDescription.Configuration (finalizePD)
import Distribution.PackageDescription.Parsec (readGenericPackageDescription)
import Distribution.Simple.Compiler (compilerInfo)
import qualified Distribution.Simple.Configure as Cabal (configure)
import qualified Distribution.Simple.GHC as GHC (configure)
import Distribution.Simple.Program.Db (restoreProgramDb, emptyProgramDb)
import Distribution.Simple.Program.Builtin (builtinPrograms)
import Distribution.Simple.Setup (defaultConfigFlags)
import Distribution.Types.ComponentRequestedSpec (ComponentRequestedSpec(..))
import Distribution.Types.Flag (mkFlagAssignment)
import Distribution.Types.HookedBuildInfo (emptyHookedBuildInfo)
import Distribution.Types.LocalBuildInfo (hostPlatform)
import Distribution.Types.PackageDescription (PackageDescription)
import qualified Distribution.Verbosity as V
import System.Exit (exitFailure)
import System.IO (hPutStrLn, stderr)
configure :: FilePath -> IO PackageDescription
configure fname = do
gpd <- readGenericPackageDescription V.normal fname
-- print gpd
(compiler, mplatform, programdb) <- GHC.configure V.normal Nothing Nothing (restoreProgramDb builtinPrograms emptyProgramDb)
platform <- maybe (hostPlatform <$> Cabal.configure (gpd, emptyHookedBuildInfo) (defaultConfigFlags programdb)) return mplatform
let mpd = finalizePD (mkFlagAssignment [])
(ComponentRequestedSpec { testsRequested = False, benchmarksRequested = False })
(const True) -- is a dependency available in the package set?
platform
(compilerInfo compiler)
[]
gpd
case mpd of
Left deps -> do
hPutStrLn stderr "Configuration failed due to the following packages:"
mapM_ (\d -> hPutStrLn stderr ("- " ++ show d)) deps
exitFailure
Right (pd, _flags) -> do
-- putStrLn ("Configured with flags: " ++ show flags)
return pd
|