Introduce flag -keep-hscpp-files
authorroland <rsx@bluewin.ch>
Tue, 21 Aug 2018 16:18:26 +0000 (12:18 -0400)
committerBen Gamari <ben@smart-cactus.org>
Tue, 21 Aug 2018 22:52:42 +0000 (18:52 -0400)
Test Plan: `make test=T10869`

Reviewers: mpickering, thomie, ezyang, bgamari

Reviewed By: thomie, bgamari

Subscribers: rwbarton, carter

GHC Trac Issues: #10869

Differential Revision: https://phabricator.haskell.org/D4861

compiler/main/DriverPipeline.hs
compiler/main/DynFlags.hs
docs/users_guide/8.8.1-notes.rst
docs/users_guide/separate_compilation.rst
testsuite/tests/driver/Makefile
testsuite/tests/driver/T10869.hs [new file with mode: 0644]
testsuite/tests/driver/T10869A.hs [new file with mode: 0644]
testsuite/tests/driver/all.T

index 68f69fc..eff542a 100644 (file)
@@ -762,6 +762,7 @@ getOutputFilename stop_phase output basename dflags next_phase maybe_location
           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 @@ getOutputFilename stop_phase output basename dflags next_phase maybe_location
                        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
index ff4766f..be14879 100644 (file)
@@ -618,6 +618,7 @@ data GeneralFlag
    | Opt_ImplicitImportQualified
 
    -- keeping stuff
+   | Opt_KeepHscppFiles
    | Opt_KeepHiDiffs
    | Opt_KeepHcFiles
    | Opt_KeepSFiles
@@ -2961,6 +2962,10 @@ dynamic_flags_deps = [
         (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"
index 2661b33..7ea2c87 100644 (file)
@@ -30,6 +30,7 @@ Language
 Compiler
 ~~~~~~~~
 
+- New :ghc-flag:`-keep-hscpp-files` to keep the output of the CPP pre-processor.
 
 Runtime system
 ~~~~~~~~~~~~~~
index 613e4de..d17ed21 100644 (file)
@@ -397,6 +397,19 @@ compilation:
     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.
index 727cc44..540f158 100644 (file)
@@ -619,6 +619,14 @@ T10320:
        "$(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 (file)
index 0000000..e151854
--- /dev/null
@@ -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 (file)
index 0000000..14e5777
--- /dev/null
@@ -0,0 +1,7 @@
+{-# LANGUAGE CPP #-}
+module T10869A (writeMsg) where
+
+writeMsg :: IO ()
+#if defined(__GLASGOW_HASKELL__)
+writeMsg = putStrLn "Hello HSPP File"
+#endif
index 07dc3bf..be91a26 100644 (file)
@@ -234,6 +234,8 @@ test('T10220', normal, run_command,
 
 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, [''])