[commit: ghc] master: Introduce flag -keep-hscpp-files (ebcbfba)

git at git.haskell.org git at git.haskell.org
Tue Aug 21 22:56:37 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/ebcbfba7bbf07fa9fbb78b46951892997795bcb8/ghc

>---------------------------------------------------------------

commit ebcbfba7bbf07fa9fbb78b46951892997795bcb8
Author: roland <rsx at bluewin.ch>
Date:   Tue Aug 21 12:18:26 2018 -0400

    Introduce flag -keep-hscpp-files
    
    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


>---------------------------------------------------------------

ebcbfba7bbf07fa9fbb78b46951892997795bcb8
 compiler/main/DriverPipeline.hs           |  2 ++
 compiler/main/DynFlags.hs                 |  5 +++++
 docs/users_guide/8.8.1-notes.rst          |  1 +
 docs/users_guide/separate_compilation.rst | 13 +++++++++++++
 testsuite/tests/driver/Makefile           |  8 ++++++++
 testsuite/tests/driver/T10869.hs          |  9 +++++++++
 testsuite/tests/driver/T10869A.hs         |  7 +++++++
 testsuite/tests/driver/all.T              |  2 ++
 8 files changed, 47 insertions(+)

diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs
index 68f69fc..eff542a 100644
--- a/compiler/main/DriverPipeline.hs
+++ b/compiler/main/DriverPipeline.hs
@@ -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
diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs
index ff4766f..be14879 100644
--- a/compiler/main/DynFlags.hs
+++ b/compiler/main/DynFlags.hs
@@ -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"
diff --git a/docs/users_guide/8.8.1-notes.rst b/docs/users_guide/8.8.1-notes.rst
index 2661b33..7ea2c87 100644
--- a/docs/users_guide/8.8.1-notes.rst
+++ b/docs/users_guide/8.8.1-notes.rst
@@ -30,6 +30,7 @@ Language
 Compiler
 ~~~~~~~~
 
+- New :ghc-flag:`-keep-hscpp-files` to keep the output of the CPP pre-processor.
 
 Runtime system
 ~~~~~~~~~~~~~~
diff --git a/docs/users_guide/separate_compilation.rst b/docs/users_guide/separate_compilation.rst
index 613e4de..d17ed21 100644
--- a/docs/users_guide/separate_compilation.rst
+++ b/docs/users_guide/separate_compilation.rst
@@ -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.
diff --git a/testsuite/tests/driver/Makefile b/testsuite/tests/driver/Makefile
index 727cc44..540f158 100644
--- a/testsuite/tests/driver/Makefile
+++ b/testsuite/tests/driver/Makefile
@@ -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
index 0000000..e151854
--- /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
index 0000000..14e5777
--- /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
index 07dc3bf..be91a26 100644
--- a/testsuite/tests/driver/all.T
+++ b/testsuite/tests/driver/all.T
@@ -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, [''])



More information about the ghc-commits mailing list