@@ -1,16 +1,11 @@
11-- Copyright (c) 2019 The DAML Authors. All rights reserved.
22-- SPDX-License-Identifier: Apache-2.0
33
4−{-# OPTIONS_GHC -Wno-missing-fields #-} -- to enable prettyPrint
5−{-# LANGUAGE CPP #-}
6−#include "ghc-api-version.h"
7−
84-- | General utility functions, mostly focused around GHC operations.
95module Development.IDE.GHC.Util(
106 -- * HcsEnv and environment
117 HscEnvEq, hscEnv, newHscEnvEq,
128 modifyDynFlags,
13− fakeDynFlags,
149 runGhcEnv,
1510 -- * GHC wrappers
1611 prettyPrint,
@@ -25,7 +20,6 @@ module Development.IDE.GHC.Util(
2520 hDuplicateTo',
2621 ) where
2722
28−
2923import Control.Concurrent
3024import Data.List.Extra
3125import Data.Maybe
@@ -47,11 +41,6 @@ import GHC.IO.Encoding
4741import GHC.IO.Exception
4842import GHC.IO.Handle.Types
4943import GHC.IO.Handle.Internals
50−#if MIN_GHC_API_VERSION(8,10,0)
51−#else
52−import Config
53−import Platform
54−#endif
5544import Data.Unique
5645import Development.Shake.Classes
5746import qualified Data.Text as T
@@ -94,9 +83,9 @@ textToStringBuffer :: T.Text -> StringBuffer
9483textToStringBuffer = stringToStringBuffer . T.unpack
9584
9685
97−-- | Pretty print a GHC value using 'fakeDynFlags'.
86+-- | Pretty print a GHC value using 'unsafeGlobalDynFlags '.
9887prettyPrint :: Outputable a => a -> String
99−prettyPrint = showSDoc fakeDynFlags . ppr
88+prettyPrint = showSDoc unsafeGlobalDynFlags . ppr
10089
10190-- | Run a 'Ghc' monad value using an existing 'HscEnv'. Sets up and tears down all the required
10291-- pieces, but designed to be more efficient than a standard 'runGhc'.
@@ -110,36 +99,6 @@ runGhcEnv env act = do
11099 cleanTempFiles dflags
111100 cleanTempDirs dflags
112101
113−-- | A 'DynFlags' value where most things are undefined. It's sufficient to call pretty printing,
114−-- but not much else.
115−fakeDynFlags :: DynFlags
116−#if MIN_GHC_API_VERSION(8,10,0)
117−fakeDynFlags = unsafeGlobalDynFlags
118−#else
119−fakeDynFlags = defaultDynFlags
120− settings
121− mempty
122− where
123− settings = Settings
124− { sTargetPlatform = platform
125− , sPlatformConstants = platformConstants
126− , sProgramName = "ghc"
127− , sProjectVersion = cProjectVersion
128−#if MIN_GHC_API_VERSION(8,6,0)
129− , sOpt_P_fingerprint = fingerprint0
130−#endif
131− }
132− platform = Platform
133− { platformWordSize=8
134− , platformOS=OSUnknown
135− , platformUnregisterised=True
136− }
137− platformConstants = PlatformConstants
138− { pc_DYNAMIC_BY_DEFAULT=False
139− , pc_WORD_SIZE=8
140− }
141−#endif
142−
143102-- | Given a module location, and its parse tree, figure out what is the include directory implied by it.
144103-- For example, given the file @\/usr\/\Test\/Foo\/Bar.hs@ with the module name @Foo.Bar@ the directory
145104-- @\/usr\/Test@ should be on the include path to find sibling modules.