From 2a093d820234b160f945e6f26047575e47e9e667 Mon Sep 17 00:00:00 2001
From: alistair <alistair@abayley.org>
Date: Tue, 4 Dec 2007 21:13:56 +0000
Subject: [PATCH] haddock: run unlit before cpp, like ghc does.

---
 Distribution/Simple/Haddock.hs | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/Distribution/Simple/Haddock.hs b/Distribution/Simple/Haddock.hs
index 15c99a0187..30a5e4b626 100644
--- a/Distribution/Simple/Haddock.hs
+++ b/Distribution/Simple/Haddock.hs
@@ -274,15 +274,19 @@ haddock pkg_descr lbi suffixes flags = do
                  let targetDir  = pref </> filePref
                  let targetFile = targetDir </> fileName
                  let (targetFileNoext, targetFileExt) = splitExtension targetFile
+                 let cppOutput = targetFileNoext <.> "hspp"
+                 let hsFile = targetFileNoext <.> "hs"
                  createDirectoryIfMissingVerbose verbosity True targetDir
-                 if needsCpp bi
-                    then runSimplePreProcessor (ppCpp' inputArgs bi lbi)
-                           file targetFile verbosity
-                    else copyFile file targetFile
-                 when (targetFileExt == ".lhs") $ do
-                       runSimplePreProcessor ppUnlit
-                         targetFile (targetFileNoext <.> "hs") verbosity
-                       return ()
+                 -- Run unlit first, then CPP
+                 if (targetFileExt == ".lhs")
+                     then runSimplePreProcessor ppUnlit file hsFile verbosity
+                     else copyFile file hsFile
+                 when (needsCpp bi) $ do
+                     runSimplePreProcessor (ppCpp' inputArgs bi lbi)
+                       hsFile cppOutput verbosity
+                     removeFile hsFile
+                     copyFile cppOutput hsFile
+                     removeFile cppOutput
         needsCpp :: BuildInfo -> Bool
         needsCpp bi = CPP `elem` extensions bi
 
-- 
GitLab