Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC

Commits:

7 changed files:

Changes:

  • changelog.d/tool-messages-27370
    1
    +section: compiler
    
    2
    +synopsis: Mark messages from external tools as errors or warnings depending on
    
    3
    +  the tool's exit code. Previously, output printed to stderr by tools was
    
    4
    +  unconditionally reported as errors.
    
    5
    +issues: #27370
    
    6
    +mrs: !16170

  • compiler/GHC/SysTools/Process.hs
    ... ... @@ -26,8 +26,9 @@ import GHC.Utils.Logger
    26 26
     import GHC.Utils.TmpFs
    
    27 27
     import GHC.Utils.CliOption
    
    28 28
     
    
    29
    -import GHC.Driver.Errors (reportError)
    
    29
    +import GHC.Driver.Errors (reportDiagnostic)
    
    30 30
     
    
    31
    +import GHC.Types.Error ( DiagnosticReason(..) )
    
    31 32
     import GHC.Types.SrcLoc ( SrcLoc, mkSrcLoc, mkSrcSpan )
    
    32 33
     import GHC.Data.FastString
    
    33 34
     
    
    ... ... @@ -271,9 +272,10 @@ builderMainLoop logger filter_fn pgm real_args mb_cwd mb_env = withPipe $ \ (rea
    271 272
               getLocaleEncoding >>= hSetEncoding readEnd
    
    272 273
               hSetNewlineMode readEnd nativeNewlineMode
    
    273 274
               hSetBuffering readEnd LineBuffering
    
    274
    -          messages <- parseBuildMessages . filter_fn . lines <$> hGetContents readEnd
    
    275
    -          mapM_ processBuildMessage messages
    
    276
    -          waitForProcess hProcess
    
    275
    +          messages <- parseBuildMessages . filter_fn . lines <$> hGetContents' readEnd
    
    276
    +          code <- waitForProcess hProcess
    
    277
    +          mapM_ (processBuildMessage code) messages
    
    278
    +          return code
    
    277 279
             hClose hStdIn
    
    278 280
             case r of
    
    279 281
               Left (SomeException e) -> do
    
    ... ... @@ -282,13 +284,16 @@ builderMainLoop logger filter_fn pgm real_args mb_cwd mb_env = withPipe $ \ (rea
    282 284
               Right s -> do
    
    283 285
                 return s
    
    284 286
       where
    
    285
    -    processBuildMessage :: BuildMessage -> IO ()
    
    286
    -    processBuildMessage msg = do
    
    287
    +    processBuildMessage :: ExitCode -> BuildMessage -> IO ()
    
    288
    +    processBuildMessage code msg = do
    
    287 289
           case msg of
    
    288 290
             BuildMsg msg -> do
    
    289 291
               logInfo logger $ withPprStyle defaultUserStyle msg
    
    290 292
             BuildError loc msg -> do
    
    291
    -          reportError logger neverQualify emptyDiagOpts (mkSrcSpan loc loc) msg
    
    293
    +          let reason = case code of
    
    294
    +                ExitSuccess   -> WarningWithoutFlag
    
    295
    +                ExitFailure{} -> ErrorWithoutFlag
    
    296
    +          reportDiagnostic logger neverQualify emptyDiagOpts (mkSrcSpan loc loc) reason msg
    
    292 297
     
    
    293 298
     parseBuildMessages :: [String] -> [BuildMessage]
    
    294 299
     parseBuildMessages str = loop str Nothing
    

  • testsuite/tests/driver/T27370/Makefile
    1
    +TOP=../../..
    
    2
    +include $(TOP)/mk/boilerplate.mk
    
    3
    +include $(TOP)/mk/test.mk
    
    4
    +
    
    5
    +T27370:
    
    6
    +	chmod +x ./T27370.pp
    
    7
    +	'$(TEST_HC)' $(TEST_HC_OPTS) -c T27370.hs

  • testsuite/tests/driver/T27370/T27370.hs
    1
    +{-# OPTIONS_GHC -F -pgmF ./T27370.pp #-}
    
    2
    +module T27370 where

  • testsuite/tests/driver/T27370/T27370.pp
    1
    +#!/bin/sh
    
    2
    +cp "$2" "$3"
    
    3
    +echo "$1:2:8: a located warning from an external tool"
    
    4
    +echo "  with a continuation line"
    
    5
    +echo "an unlocated line from an external tool"

  • testsuite/tests/driver/T27370/T27370.stderr
    1
    +T27370.hs:2:8: warning:
    
    2
    +     a located warning from an external tool
    
    3
    +      with a continuation line
    
    4
    +
    
    5
    +an unlocated line from an external tool

  • testsuite/tests/driver/T27370/all.T
    1
    +test('T27370',
    
    2
    +     [extra_files(['T27370.hs', 'T27370.pp']),
    
    3
    +      when(opsys('mingw32'), skip)],
    
    4
    +     makefile_test, ['T27370'])