on 5697fdd help sign in
stackage/Stackage/CheckPlan.hs
35 lines 1.2 kB history raw
1module Stackage.CheckPlan
2 ( checkPlan
3 ) where
5import Control.Monad (unless)
6import Data.List (sort)
7import Stackage.InstallInfo
8import Stackage.Types
9import System.Exit (ExitCode (ExitFailure), exitWith)
10import System.Process (readProcess)
12data Mismatch = OnlyDryRun String | OnlySimpleList String
13 deriving Show
15checkPlan :: InstallInfo -> IO ()
16checkPlan 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)
20 unless (null mismatches) $ do
21 putStrLn "Found the following mismtaches"
22 mapM_ print mismatches
23 exitWith $ ExitFailure 1
25getMismatches :: [String] -> [String] -> [Mismatch]
26getMismatches =
27 go
28 where
29 go [] y = map OnlySimpleList y
30 go x [] = map OnlyDryRun x
31 go (x:xs) (y:ys) =
32 case compare x y of
33 EQ -> go xs ys
34 LT -> OnlyDryRun x : go xs (y:ys)
35 GT -> OnlySimpleList y : go (x:xs) ys