@@ -2,25 +2,37 @@ module Stackage.CheckPlan
2 ( checkPlan
2 ( checkPlan
5−import Control.Monad (unless)
5+import Control.Monad (unless, when)
6−import Data.List (sort)
6+import Data.List (isPrefixOf, sort)
7+import qualified Data.Map as Map
8+import qualified Data.Set as Set
7import Stackage.InstallInfo
9import Stackage.InstallInfo
8import Stackage.Types
10import Stackage.Types
9−import System.Exit (ExitCode (ExitFailure), exitWith)
12+import System.Exit (ExitCode (ExitFailure, ExitSuccess),
10−import System.Process (readProcess)
14+import System.Process (readProcessWithExitCode)
12data Mismatch = OnlyDryRun String | OnlySimpleList String
16data Mismatch = OnlyDryRun String | OnlySimpleList String
13 deriving Show
17 deriving Show
15checkPlan :: InstallInfo -> IO ()
19checkPlan :: InstallInfo -> IO ()
16checkPlan ii = do
20checkPlan ii = do
17− dryRun' <- readProcess "cabal-dev" ("install":"--dry-run":"-fnetwork23":iiPackageList ii) ""
21+ (ec, dryRun', stderr) <- readProcessWithExitCode "cabal-dev" ("install":"--dry-run":"-fnetwork23":iiPackageList ii) ""
22+ when (ec /= ExitSuccess || "Warning:" `isPrefixOf` stderr) $ do
25+ putStrLn "cabal-dev returned a bad result, exiting"
18− let dryRun = sort $ drop 2 $ lines dryRun'
27+ let dryRun = sort $ filter notOptionalCore $ map (takeWhile (/= ' ')) $ drop 2 $ lines dryRun'
19− let mismatches = getMismatches dryRun (iiPackageList ii)
28+ let mismatches = getMismatches dryRun (filter notOptionalCore $ iiPackageList ii)
20 unless (null mismatches) $ do
29 unless (null mismatches) $ do
21 putStrLn "Found the following mismtaches"
30 putStrLn "Found the following mismtaches"
22 mapM_ print mismatches
31 mapM_ print mismatches
23 exitWith $ ExitFailure 1
32 exitWith $ ExitFailure 1
34+ optionalCore = Set.fromList $ map packageVersionString $ Map.toList $ iiOptionalCore ii
35+ notOptionalCore s = not $ s `Set.member` optionalCore
25getMismatches :: [String] -> [String] -> [Mismatch]
37getMismatches :: [String] -> [String] -> [Mismatch]
26getMismatches =
38getMismatches =