[commit: ghc] master: Made ghc -e have a nonzero exit code upon failure (Trac #7962 ) (47024b6)

git at git.haskell.org git at git.haskell.org
Thu Dec 5 04:00:11 UTC 2013


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/47024b63835e2bc238f88e3e1a5b5927a850e74c/ghc

>---------------------------------------------------------------

commit 47024b63835e2bc238f88e3e1a5b5927a850e74c
Author: khyperia <khyperia at live.com>
Date:   Wed Nov 27 23:30:59 2013 -0500

    Made ghc -e have a nonzero exit code upon failure (Trac #7962 )
    
    Signed-off-by: Austin Seipp <austin at well-typed.com>


>---------------------------------------------------------------

47024b63835e2bc238f88e3e1a5b5927a850e74c
 ghc/InteractiveUI.hs |   14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/ghc/InteractiveUI.hs b/ghc/InteractiveUI.hs
index 5413a1a..024aa2d 100644
--- a/ghc/InteractiveUI.hs
+++ b/ghc/InteractiveUI.hs
@@ -524,7 +524,8 @@ runGHCi paths maybe_exprs = do
                                    $ topHandler e
                                    -- this used to be topHandlerFastExit, see #2228
             runInputTWithPrefs defaultPrefs defaultSettings $ do
-                runCommands' hdle (return Nothing)
+                -- make `ghc -e` exit nonzero on invalid input, see Trac #7962
+                runCommands' hdle (Just $ hdle (toException $ ExitFailure 1) >> return ()) (return Nothing)
 
   -- and finally, exit
   liftIO $ when (verbosity dflags > 0) $ putStrLn "Leaving GHCi."
@@ -675,11 +676,12 @@ installInteractivePrint (Just ipFun) exprmode = do
 
 -- | The main read-eval-print loop
 runCommands :: InputT GHCi (Maybe String) -> InputT GHCi ()
-runCommands = runCommands' handler
+runCommands = runCommands' handler Nothing
 
 runCommands' :: (SomeException -> GHCi Bool) -- ^ Exception handler
+             -> Maybe (GHCi ()) -- ^ Source error handler
              -> InputT GHCi (Maybe String) -> InputT GHCi ()
-runCommands' eh gCmd = do
+runCommands' eh sourceErrorHandler gCmd = do
     b <- ghandle (\e -> case fromException e of
                           Just UserInterrupt -> return $ Just False
                           _ -> case fromException e of
@@ -691,7 +693,11 @@ runCommands' eh gCmd = do
             (runOneCommand eh gCmd)
     case b of
       Nothing -> return ()
-      Just _  -> runCommands' eh gCmd
+      Just success -> do
+        let nextCommand = runCommands' eh sourceErrorHandler gCmd
+        case sourceErrorHandler of
+          Just handler | success == False -> lift handler >> nextCommand
+          _ -> nextCommand
 
 -- | Evaluate a single line of user input (either :<command> or Haskell code)
 runOneCommand :: (SomeException -> GHCi Bool) -> InputT GHCi (Maybe String)



More information about the ghc-commits mailing list