on master help sign in
ghc 8.10 compatibility (CPP optP) (#452)
commit6f3bd734de52f933000ea92ff4a8a3dea3b95add authorsheaf <sam.derbyshire@gmail.com> dateMon 24 Feb 2020, 10:24 (7 years ago) parent29d7741
2 files changed+23−9
src/Development/IDE/Core/Preprocessor.hs+1−8 src/Development/IDE/GHC/CPP.hs+22−1
src/Development/IDE/Core/Preprocessor.hs+1−8
@@ -166,18 +166,11 @@ runLhs dflags filename contents = withTempDir $ \dir -> do
166166 escape (c:cs) = c : escape cs
167167 escape [] = []
168168
169−
170−modifyOptP :: ([String] -> [String]) -> DynFlags -> DynFlags
171−modifyOptP op = onSettings (onOptP op)
172− where
173− onSettings f x = x{settings = f $ settings x}
174− onOptP f x = x{sOpt_P = f $ sOpt_P x}
175−
176169-- | Run CPP on a file
177170runCpp :: DynFlags -> FilePath -> Maybe SB.StringBuffer -> IO SB.StringBuffer
178171runCpp dflags filename contents = withTempDir $ \dir -> do
179172 let out = dir </> takeFileName filename <.> "out"
180− dflags <- pure $ modifyOptP ("-D__GHCIDE__":) dflags
173+ dflags <- pure $ addOptP "-D__GHCIDE__" dflags
181174
182175 case contents of
183176 Nothing -> do
src/Development/IDE/GHC/CPP.hs+22−1
@@ -19,7 +19,8 @@
1919--
2020-----------------------------------------------------------------------------
2121
22−module Development.IDE.GHC.CPP(doCpp) where
22+module Development.IDE.GHC.CPP(doCpp, addOptP)
23+where
2324
2425import Development.IDE.GHC.Compat
2526import Packages
@@ -33,6 +34,10 @@ import LlvmCodeGen (llvmVersionList)
3334#elif MIN_GHC_API_VERSION(8,8,0)
3435import LlvmCodeGen (LlvmVersion (..))
3536#endif
37+#if MIN_GHC_API_VERSION (8,10,0)
38+import Fingerprint
39+import ToolSettings
40+#endif
3641
3742import System.Directory
3843import System.FilePath
@@ -162,6 +167,22 @@ getBackendDefs dflags | hscTarget dflags == HscLlvm = do
162167getBackendDefs _ =
163168 return []
164169
170+addOptP :: String -> DynFlags -> DynFlags
171+#if MIN_GHC_API_VERSION (8,10,0)
172+addOptP f = alterToolSettings $ \s -> s
173+ { toolSettings_opt_P = f : toolSettings_opt_P s
174+ , toolSettings_opt_P_fingerprint = fingerprintStrings (f : toolSettings_opt_P s)
175+ }
176+ where
177+ fingerprintStrings ss = fingerprintFingerprints $ map fingerprintString ss
178+ alterToolSettings f dynFlags = dynFlags { toolSettings = f (toolSettings dynFlags) }
179+#else
180+addOptP opt = onSettings (onOptP (opt:))
181+ where
182+ onSettings f x = x{settings = f $ settings x}
183+ onOptP f x = x{sOpt_P = f $ sOpt_P x}
184+#endif
185+
165186-- ---------------------------------------------------------------------------
166187-- Macros (cribbed from Cabal)
167188