summaryrefslogtreecommitdiff
path: root/compiler/main/DriverMkDepend.hs
diff options
context:
space:
mode:
authorDavid Eichmann <EichmannD@gmail.com>2019-04-09 13:17:34 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-05-21 16:57:37 -0400
commit8fc654c3a00ab0cd842c3e8316f832170ea561d6 (patch)
treecb8e052c93d2709411d2b05760790953735bf1c2 /compiler/main/DriverMkDepend.hs
parent54095bbd3a5481e906b05c80ea68841165c7a2b3 (diff)
downloadhaskell-8fc654c3a00ab0cd842c3e8316f832170ea561d6.tar.gz
Include CPP preprocessor dependencies in -M output
Issue #16521
Diffstat (limited to 'compiler/main/DriverMkDepend.hs')
-rw-r--r--compiler/main/DriverMkDepend.hs15
1 files changed, 14 insertions, 1 deletions
diff --git a/compiler/main/DriverMkDepend.hs b/compiler/main/DriverMkDepend.hs
index 741104596a..6368d8c785 100644
--- a/compiler/main/DriverMkDepend.hs
+++ b/compiler/main/DriverMkDepend.hs
@@ -41,6 +41,7 @@ import System.IO
import System.IO.Error ( isEOFError )
import Control.Monad ( when )
import Data.Maybe ( isJust )
+import Data.IORef
-----------------------------------------------------------------
--
@@ -85,7 +86,7 @@ doMkDependHS srcs = do
-- Print out the dependencies if wanted
liftIO $ debugTraceMsg dflags 2 (text "Module dependencies" $$ ppr sorted)
- -- Prcess them one by one, dumping results into makefile
+ -- Process them one by one, dumping results into makefile
-- and complaining about cycles
hsc_env <- getSession
root <- liftIO getCurrentDirectory
@@ -224,6 +225,18 @@ processDeps dflags hsc_env excl_mods root hdl (AcyclicSCC node)
-- Something like A.o : A.hs
; writeDependency root hdl obj_files src_file
+ -- Emit a dependency for each CPP import
+ ; when (depIncludeCppDeps dflags) $ do
+ -- CPP deps are descovered in the module parsing phase by parsing
+ -- comment lines left by the preprocessor.
+ -- Note that GHC.parseModule may throw an exception if the module
+ -- fails to parse, which may not be desirable (see #16616).
+ { session <- Session <$> newIORef hsc_env
+ ; parsedMod <- reflectGhc (GHC.parseModule node) session
+ ; mapM_ (writeDependency root hdl obj_files)
+ (GHC.pm_extra_src_files parsedMod)
+ }
+
-- Emit a dependency for each import
; let do_imps is_boot idecls = sequence_