diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs --- a/compiler/main/DriverPipeline.hs +++ b/compiler/main/DriverPipeline.hs @@ -762,6 +762,7 @@ odir = objectDir dflags osuf = objectSuf dflags keep_hc = gopt Opt_KeepHcFiles dflags + keep_hscpp = gopt Opt_KeepHscppFiles dflags keep_s = gopt Opt_KeepSFiles dflags keep_bc = gopt Opt_KeepLlvmFiles dflags @@ -778,6 +779,7 @@ As _ | keep_s -> True LlvmOpt | keep_bc -> True HCc | keep_hc -> True + HsPp _ | keep_hscpp -> True -- See Trac #10869 _other -> False suffix = myPhaseInputExt next_phase diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs --- a/compiler/main/DynFlags.hs +++ b/compiler/main/DynFlags.hs @@ -618,6 +618,7 @@ | Opt_ImplicitImportQualified -- keeping stuff + | Opt_KeepHscppFiles | Opt_KeepHiDiffs | Opt_KeepHcFiles | Opt_KeepSFiles @@ -2959,6 +2960,10 @@ (NoArg (setGeneralFlag Opt_KeepHcFiles)) , make_ord_flag defGhcFlag "keep-hc-files" (NoArg (setGeneralFlag Opt_KeepHcFiles)) + , make_ord_flag defGhcFlag "keep-hscpp-file" + (NoArg (setGeneralFlag Opt_KeepHscppFiles)) + , make_ord_flag defGhcFlag "keep-hscpp-files" + (NoArg (setGeneralFlag Opt_KeepHscppFiles)) , make_ord_flag defGhcFlag "keep-s-file" (NoArg (setGeneralFlag Opt_KeepSFiles)) , make_ord_flag defGhcFlag "keep-s-files" diff --git a/docs/users_guide/separate_compilation.rst b/docs/users_guide/separate_compilation.rst --- a/docs/users_guide/separate_compilation.rst +++ b/docs/users_guide/separate_compilation.rst @@ -397,6 +397,19 @@ Keep intermediate ``.hi`` files. This is the default. You may use ``-no-keep-hi-files`` if you are not interested in the ``.hi`` files. +.. ghc-flag:: -keep-hscpp-file + -keep-hscpp-files + :shortdesc: Retain intermediate ``.hscpp`` files. + :type: dynamic + :category: keep-intermediates + + .. index:: + single: temporary files; keeping + + Keep the output of the ``CPP`` pre-processor phase as ``.hscpp`` files. + A ``.hscpp`` file is only created, if a module gets compiled and uses the + C pre-processor. + .. ghc-flag:: -keep-llvm-file -keep-llvm-files :shortdesc: Retain intermediate LLVM ``.ll`` files. diff --git a/testsuite/tests/driver/Makefile b/testsuite/tests/driver/Makefile --- a/testsuite/tests/driver/Makefile +++ b/testsuite/tests/driver/Makefile @@ -619,6 +619,14 @@ "$(TEST_HC)" $(TEST_HC_OPTS) -v0 -fforce-recomp -ddump-to-file -ddump-rule-rewrites T10320.hs [ -f T10320.dump-rule-rewrites ] && [ ! -s T10320.dump-rule-rewrites ] +.PHONY: T10869 +T10869: + $(RM) -rf T10869.hi T10869.o T10869.hspp T10869 + $(RM) -rf T10869A.hi T10869A.o T10869A.hspp + "$(TEST_HC)" $(TEST_HC_OPTS) -c -keep-hscpp-files T10869A.hs T10869.hs + test -f T10869.hscpp + test -f T10869A.hscpp + .PHONY: T12135 T12135: $(RM) -rf T12135.o T12135.hi T12135 T12135a T12135b diff --git a/testsuite/tests/driver/T10869.hs b/testsuite/tests/driver/T10869.hs new file mode 100644 --- /dev/null +++ b/testsuite/tests/driver/T10869.hs @@ -0,0 +1,9 @@ +{-# LANGUAGE CPP #-} + +module T10869 where +import T10869A + +main :: IO() +#if defined(__GLASGOW_HASKELL__) +main = writeMsg +#endif diff --git a/testsuite/tests/driver/T10869A.hs b/testsuite/tests/driver/T10869A.hs new file mode 100644 --- /dev/null +++ b/testsuite/tests/driver/T10869A.hs @@ -0,0 +1,7 @@ +{-# LANGUAGE CPP #-} +module T10869A (writeMsg) where + +writeMsg :: IO () +#if defined(__GLASGOW_HASKELL__) +writeMsg = putStrLn "Hello HSPP File" +#endif diff --git a/testsuite/tests/driver/all.T b/testsuite/tests/driver/all.T --- a/testsuite/tests/driver/all.T +++ b/testsuite/tests/driver/all.T @@ -234,6 +234,8 @@ test('T10182', [], run_command, ['$MAKE -s --no-print-directory T10182']) +test('T10869', [], run_command, ['$MAKE -s --no-print-directory T10869']) + test('T365', [pre_cmd('touch test_preprocessor.txt'), unless(opsys('mingw32'), skip)], compile_fail, [''])