@@ -16,13 +16,12 @@ module Development.IDE.Core.Compile
18import Development.IDE.Core.RuleTypes
18import Development.IDE.Core.RuleTypes
19−import Development.IDE.GHC.CPP
19+import Development.IDE.Core.Preprocessor
20import Development.IDE.GHC.Error
20import Development.IDE.GHC.Error
21import Development.IDE.GHC.Warnings
21import Development.IDE.GHC.Warnings
22import Development.IDE.Types.Diagnostics
22import Development.IDE.Types.Diagnostics
23import Development.IDE.GHC.Orphans()
23import Development.IDE.GHC.Orphans()
24import Development.IDE.GHC.Util
24import Development.IDE.GHC.Util
25−import Development.IDE.GHC.Compat
26import qualified GHC.LanguageExtensions.Type as GHC
25import qualified GHC.LanguageExtensions.Type as GHC
27import Development.IDE.Types.Options
26import Development.IDE.Types.Options
28import Development.IDE.Types.Location
27import Development.IDE.Types.Location
@@ -54,10 +53,6 @@ import Data.Maybe
54import Data.Tuple.Extra
53import Data.Tuple.Extra
55import qualified Data.Map.Strict as Map
54import qualified Data.Map.Strict as Map
56import System.FilePath
55import System.FilePath
57−import System.IO.Extra
60−import SysTools (Option (..), runUnlit)
63-- | Given a string buffer, return a pre-processed @ParsedModule@.
58-- | Given a string buffer, return a pre-processed @ParsedModule@.
@@ -270,70 +265,6 @@ getModSummaryFromBuffer fp contents dflags parsed = do
270 then (HsBootFile, \newExt -> stem <.> newExt ++ "-boot")
265 then (HsBootFile, \newExt -> stem <.> newExt ++ "-boot")
271 else (HsSrcFile , \newExt -> stem <.> newExt)
266 else (HsSrcFile , \newExt -> stem <.> newExt)
273−-- | Run (unlit) literate haskell preprocessor on a file, or buffer if set
274−runLhs :: DynFlags -> FilePath -> Maybe SB.StringBuffer -> IO SB.StringBuffer
275−runLhs dflags filename contents = withTempDir $ \dir -> do
276− let fout = dir </> takeFileName filename <.> "unlit"
277− filesrc <- case contents of
278− Nothing -> return filename
280− let fsrc = dir </> takeFileName filename <.> "literate"
281− withBinaryFile fsrc WriteMode $ \h ->
282− hPutStringBuffer h cnts
285− SB.hGetStringBuffer fout
287− unlit filein fileout = SysTools.runUnlit dflags (args filein fileout)
288− args filein fileout = [
289− SysTools.Option "-h"
290− , SysTools.Option (escape filename) -- name this file
291− , SysTools.FileOption "" filein -- input file
292− , SysTools.FileOption "" fileout ] -- output file
293− -- taken from ghc's DriverPipeline.hs
294− escape ('\\':cs) = '\\':'\\': escape cs
295− escape ('\"':cs) = '\\':'\"': escape cs
296− escape ('\'':cs) = '\\':'\'': escape cs
297− escape (c:cs) = c : escape cs
300−-- | Run CPP on a file
301−runCpp :: DynFlags -> FilePath -> Maybe SB.StringBuffer -> IO SB.StringBuffer
302−runCpp dflags filename contents = withTempDir $ \dir -> do
303− let out = dir </> takeFileName filename <.> "out"
306− -- Happy case, file is not modified, so run CPP on it in-place
307− -- which also makes things like relative #include files work
308− -- and means location information is correct
309− doCpp dflags True filename out
310− liftIO $ SB.hGetStringBuffer out
313− -- Sad path, we have to create a version of the path in a temp dir
314− -- __FILE__ macro is wrong, ignoring that for now (likely not a real issue)
316− -- Relative includes aren't going to work, so we fix that by adding to the include path.
317− dflags <- return $ addIncludePathsQuote (takeDirectory filename) dflags
319− -- Location information is wrong, so we fix that by patching it afterwards.
320− let inp = dir </> "___GHCIDE_MAGIC___"
321− withBinaryFile inp WriteMode $ \h ->
322− hPutStringBuffer h contents
323− doCpp dflags True inp out
325− -- Fix up the filename in lines like:
326− -- # 1 "C:/Temp/extra-dir-914611385186/___GHCIDE_MAGIC___"
328− | Just x <- stripPrefix "# " x
329− , "___GHCIDE_MAGIC___" `isInfixOf` x
330− , let num = takeWhile (not . isSpace) x
331− -- important to use /, and never \ for paths, even on Windows, since then C escapes them
332− -- and GHC gets all confused
333− = "# " <> num <> " \"" <> map (\x -> if isPathSeparator x then '/' else x) filename <> "\""
335− stringToStringBuffer . unlines . map tweak . lines <$> readFileUTF8' out
337-- | Given a buffer, flags, file path and module summary, produce a
268-- | Given a buffer, flags, file path and module summary, produce a
338-- parsed module (or errors) and any parse warnings.
269-- parsed module (or errors) and any parse warnings.
339parseFileContents
270parseFileContents