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