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 -- hPutStrLn stderr ("Configured with flags: " ++ show flags) return pd