diff --git a/Stackage/CheckPlan.hs b/Stackage/CheckPlan.hs index 3f067f0d..8a6c9c42 100644 --- a/Stackage/CheckPlan.hs +++ b/Stackage/CheckPlan.hs @@ -2,25 +2,37 @@ module Stackage.CheckPlan ( checkPlan ) where -import Control.Monad (unless) -import Data.List (sort) +import Control.Monad (unless, when) +import Data.List (isPrefixOf, sort) +import qualified Data.Map as Map +import qualified Data.Set as Set import Stackage.InstallInfo import Stackage.Types -import System.Exit (ExitCode (ExitFailure), exitWith) -import System.Process (readProcess) +import Stackage.Util +import System.Exit (ExitCode (ExitFailure, ExitSuccess), + exitWith) +import System.Process (readProcessWithExitCode) data Mismatch = OnlyDryRun String | OnlySimpleList String deriving Show checkPlan :: InstallInfo -> IO () checkPlan ii = do - dryRun' <- readProcess "cabal-dev" ("install":"--dry-run":"-fnetwork23":iiPackageList ii) "" - let dryRun = sort $ drop 2 $ lines dryRun' - let mismatches = getMismatches dryRun (iiPackageList ii) + (ec, dryRun', stderr) <- readProcessWithExitCode "cabal-dev" ("install":"--dry-run":"-fnetwork23":iiPackageList ii) "" + when (ec /= ExitSuccess || "Warning:" `isPrefixOf` stderr) $ do + putStr stderr + putStr dryRun' + putStrLn "cabal-dev returned a bad result, exiting" + exitWith ec + let dryRun = sort $ filter notOptionalCore $ map (takeWhile (/= ' ')) $ drop 2 $ lines dryRun' + let mismatches = getMismatches dryRun (filter notOptionalCore $ iiPackageList ii) unless (null mismatches) $ do putStrLn "Found the following mismtaches" mapM_ print mismatches exitWith $ ExitFailure 1 + where + optionalCore = Set.fromList $ map packageVersionString $ Map.toList $ iiOptionalCore ii + notOptionalCore s = not $ s `Set.member` optionalCore getMismatches :: [String] -> [String] -> [Mismatch] getMismatches = diff --git a/Stackage/Config.hs b/Stackage/Config.hs index d4fb84fd..80893b6c 100644 --- a/Stackage/Config.hs +++ b/Stackage/Config.hs @@ -1,11 +1,9 @@ {-# LANGUAGE CPP #-} module Stackage.Config where -import Control.Monad (unless, when) import Control.Monad.Trans.Writer (execWriter, tell) import qualified Data.Map as Map import Data.Set (fromList, singleton) -import Distribution.System (OS (..), buildOS) import Distribution.Text (simpleParse) import Stackage.Types diff --git a/Stackage/InstallInfo.hs b/Stackage/InstallInfo.hs index d5a4d29c..b3116a5b 100644 --- a/Stackage/InstallInfo.hs +++ b/Stackage/InstallInfo.hs @@ -28,6 +28,7 @@ getInstallInfo = do return InstallInfo { iiCore = totalCore , iiPackages = Map.map fst final + , iiOptionalCore = Map.fromList $ map (\(PackageIdentifier p v) -> (p, v)) $ Set.toList $ hplibs hp } showDep :: (PackageName, (Version, [PackageName])) -> String diff --git a/Stackage/LoadDatabase.hs b/Stackage/LoadDatabase.hs index 61257027..64064b2b 100644 --- a/Stackage/LoadDatabase.hs +++ b/Stackage/LoadDatabase.hs @@ -1,7 +1,6 @@ module Stackage.LoadDatabase where import qualified Codec.Archive.Tar as Tar -import Control.Exception (throwIO) import qualified Data.ByteString.Lazy as L import qualified Data.ByteString.Lazy.Char8 as L8 import qualified Data.Map as Map diff --git a/Stackage/Tarballs.hs b/Stackage/Tarballs.hs index 32d7f21a..7cd1b3be 100644 --- a/Stackage/Tarballs.hs +++ b/Stackage/Tarballs.hs @@ -3,7 +3,6 @@ module Stackage.Tarballs ) where import qualified Codec.Archive.Tar as Tar -import Control.Exception (throwIO) import qualified Data.ByteString.Lazy as L import qualified Data.Map as Map import qualified Data.Set as Set diff --git a/Stackage/Types.hs b/Stackage/Types.hs index 0fecab02..a9d18bc9 100644 --- a/Stackage/Types.hs +++ b/Stackage/Types.hs @@ -42,4 +42,8 @@ instance Monoid HaskellPlatform where data InstallInfo = InstallInfo { iiCore :: Set PackageName , iiPackages :: Map PackageName Version + , iiOptionalCore :: Map PackageName Version + -- ^ This is intended to hold onto packages which might be automatically + -- provided in the global package database. In practice, this would be + -- Haskell Platform packages provided by distributions. }