diff options
author | Daniel Gröber <dxld@darkboxed.org> | 2019-05-25 13:57:45 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2019-05-30 16:44:08 -0400 |
commit | 99e7276982fe41dca0098e37a9cbf71091c3e275 (patch) | |
tree | 92f37e76956e161696926ea65c32505f2f56244d /compiler/main/DriverPipeline.hs | |
parent | 18d3f01d9abe2994b2b3d07b67ee9616c3553e16 (diff) | |
download | haskell-99e7276982fe41dca0098e37a9cbf71091c3e275.tar.gz |
Catch preprocessor errors in downsweep
This changes the way preprocessor failures are presented to the
user. Previously the user would simply get an unlocated message on stderr
such as:
`gcc' failed in phase `C pre-processor'. (Exit code: 1)
Now at the problematic source file is mentioned:
A.hs:1:1: error:
`gcc' failed in phase `C pre-processor'. (Exit code: 1)
This also makes live easier for GHC API clients as the preprocessor error
is now thrown as a SourceError exception.
Diffstat (limited to 'compiler/main/DriverPipeline.hs')
-rw-r--r-- | compiler/main/DriverPipeline.hs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs index 9ac973cbc4..78e4a810d7 100644 --- a/compiler/main/DriverPipeline.hs +++ b/compiler/main/DriverPipeline.hs @@ -64,6 +64,8 @@ import Hooks import qualified GHC.LanguageExtensions as LangExt import FileCleanup import Ar +import Bag ( unitBag ) +import FastString ( mkFastString ) import Exception import System.Directory @@ -91,8 +93,11 @@ preprocess :: HscEnv -> Maybe StringBuffer -- ^ optional buffer to use instead of reading input file -> Maybe Phase -- ^ starting phase - -> IO (DynFlags, FilePath) + -> IO (Either ErrorMessages (DynFlags, FilePath)) preprocess hsc_env input_fn mb_input_buf mb_phase = + handleSourceError (\err -> return (Left (srcErrorMessages err))) $ + ghandle handler $ + fmap Right $ ASSERT2(isJust mb_phase || isHaskellSrcFilename input_fn, text input_fn) runPipeline anyHsc hsc_env (input_fn, mb_input_buf, fmap RealPhase mb_phase) Nothing @@ -101,6 +106,11 @@ preprocess hsc_env input_fn mb_input_buf mb_phase = (Temporary TFL_GhcSession) Nothing{-no ModLocation-} []{-no foreign objects-} + where + srcspan = srcLocSpan $ mkSrcLoc (mkFastString input_fn) 1 1 + handler (ProgramError msg) = return $ Left $ unitBag $ + mkPlainErrMsg (hsc_dflags hsc_env) srcspan $ text msg + handler ex = throwGhcExceptionIO ex -- --------------------------------------------------------------------------- |