Ticket #7962: 0001-Made-ghc-e-have-a-nonzero-exit-code-upon-failure-Tra.patch

File 0001-Made-ghc-e-have-a-nonzero-exit-code-upon-failure-Tra.patch, 2.3 KB (added by khyperia, 5 months ago)

Patch file

  • ghc/InteractiveUI.hs

    From fe6e1e79dfdb4b65c143da7883d881b912e40c60 Mon Sep 17 00:00:00 2001
    From: khyperia <khyperia@live.com>
    Date: Wed, 27 Nov 2013 23:30:59 -0500
    Subject: [PATCH] Made ghc -e have a nonzero exit code upon failure (Trac #7962
     )
    
    ---
     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 b runGHCi paths maybe_exprs = do 
    524524                                   $ topHandler e 
    525525                                   -- this used to be topHandlerFastExit, see #2228 
    526526            runInputTWithPrefs defaultPrefs defaultSettings $ do 
    527                 runCommands' hdle (return Nothing) 
     527                -- make `ghc -e` exit nonzero on invalid input, see Trac #7962 
     528                runCommands' hdle (Just $ hdle (toException $ ExitFailure 1) >> return ()) (return Nothing) 
    528529 
    529530  -- and finally, exit 
    530531  liftIO $ when (verbosity dflags > 0) $ putStrLn "Leaving GHCi." 
    installInteractivePrint (Just ipFun) exprmode = do 
    675676 
    676677-- | The main read-eval-print loop 
    677678runCommands :: InputT GHCi (Maybe String) -> InputT GHCi () 
    678 runCommands = runCommands' handler 
     679runCommands = runCommands' handler Nothing 
    679680 
    680681runCommands' :: (SomeException -> GHCi Bool) -- ^ Exception handler 
     682             -> Maybe (GHCi ()) -- ^ Source error handler 
    681683             -> InputT GHCi (Maybe String) -> InputT GHCi () 
    682 runCommands' eh gCmd = do 
     684runCommands' eh sourceErrorHandler gCmd = do 
    683685    b <- ghandle (\e -> case fromException e of 
    684686                          Just UserInterrupt -> return $ Just False 
    685687                          _ -> case fromException e of 
    runCommands' eh gCmd = do 
    691693            (runOneCommand eh gCmd) 
    692694    case b of 
    693695      Nothing -> return () 
    694       Just _  -> runCommands' eh gCmd 
     696      Just success -> do 
     697        let nextCommand = runCommands' eh sourceErrorHandler gCmd 
     698        case sourceErrorHandler of 
     699          Just handler | success == False -> lift handler >> nextCommand 
     700          _ -> nextCommand 
    695701 
    696702-- | Evaluate a single line of user input (either :<command> or Haskell code) 
    697703runOneCommand :: (SomeException -> GHCi Bool) -> InputT GHCi (Maybe String)