1+ {-# LANGUAGE CPP #-}
2+ {-# LANGUAGE ScopedTypeVariables #-}
3+
14module Main where
25
6+ import Control.Exception (bracket )
37import Control.Monad
48import Data.Time (NominalDiffTime , diffUTCTime , getCurrentTime )
59import System.Directory (
@@ -9,8 +13,12 @@ import System.Directory (
913 getModificationTime ,
1014 getXdgDirectory ,
1115 )
16+ import System.Exit (ExitCode (.. ))
1217import System.FilePath ((</>) )
1318import System.Process
19+ #ifndef mingw32_HOST_OS
20+ import System.Posix.Signals (Handler (.. ), installHandler , sigINT )
21+ #endif
1422
1523main :: IO ()
1624main = do
@@ -37,15 +45,41 @@ main = do
3745 let command = " cabal"
3846 args =
3947 [ " repl"
48+ , " --ignore-project"
4049 , " -O2"
4150 , " --build-depends"
4251 , " dataframe"
4352 , " --repl-option=-ghci-script=" ++ filepath
4453 ]
45- (_, _, _, processHandle) <- createProcess (proc command args)
54+ let baseCp =
55+ (proc command args)
56+ { cwd = Just cacheDir
57+ , std_in = Inherit
58+ , std_out = Inherit
59+ , std_err = Inherit
60+ }
61+ #ifdef mingw32_HOST_OS
62+ cp = baseCp {delegate_ctlc = True }
63+ #else
64+ cp = baseCp
65+ #endif
66+ #ifndef mingw32_HOST_OS
67+ -- Unix: ignore Ctrl-C in the wrapper so the child handles it.
68+ bracket (installHandler sigINT Ignore Nothing )
69+ (\ old -> installHandler sigINT old Nothing )
70+ (\ _ -> runChild cp)
71+ #else
72+ -- Windows: delegate Ctrl-C handling to the child.
73+ runChild cp
74+ #endif
4675
47- exitCode <- waitForProcess processHandle
48- pure ()
76+ runChild :: CreateProcess -> IO ()
77+ runChild cp = do
78+ (_, _, _, ph) <- createProcess cp
79+ ec <- waitForProcess ph
80+ case ec of
81+ ExitSuccess -> pure ()
82+ ExitFailure n -> fail (" cabal repl failed with exit code " <> show n)
4983
5084oneWeek :: NominalDiffTime
5185oneWeek = 7 * 24 * 60 * 60
0 commit comments