1
1
-- Copyright (c) 2019 The DAML Authors. All rights reserved.
2
2
-- SPDX-License-Identifier: Apache-2.0
3
3
4
- {-# OPTIONS_GHC -Wno-missing-fields #-} -- to enable prettyPrint
5
- {-# LANGUAGE CPP #-}
6
- #include "ghc-api-version.h"
7
-
8
4
-- | General utility functions, mostly focused around GHC operations.
9
5
module Development.IDE.GHC.Util (
10
6
-- * HcsEnv and environment
11
7
HscEnvEq , hscEnv , newHscEnvEq ,
12
8
modifyDynFlags ,
13
- fakeDynFlags ,
14
9
runGhcEnv ,
15
10
-- * GHC wrappers
16
11
prettyPrint ,
@@ -25,7 +20,6 @@ module Development.IDE.GHC.Util(
25
20
hDuplicateTo' ,
26
21
) where
27
22
28
-
29
23
import Control.Concurrent
30
24
import Data.List.Extra
31
25
import Data.Maybe
@@ -47,11 +41,6 @@ import GHC.IO.Encoding
47
41
import GHC.IO.Exception
48
42
import GHC.IO.Handle.Types
49
43
import GHC.IO.Handle.Internals
50
- #if MIN_GHC_API_VERSION(8,10,0)
51
- #else
52
- import Config
53
- import Platform
54
- #endif
55
44
import Data.Unique
56
45
import Development.Shake.Classes
57
46
import qualified Data.Text as T
@@ -94,9 +83,9 @@ textToStringBuffer :: T.Text -> StringBuffer
94
83
textToStringBuffer = stringToStringBuffer . T. unpack
95
84
96
85
97
- -- | Pretty print a GHC value using 'fakeDynFlags '.
86
+ -- | Pretty print a GHC value using 'unsafeGlobalDynFlags '.
98
87
prettyPrint :: Outputable a => a -> String
99
- prettyPrint = showSDoc fakeDynFlags . ppr
88
+ prettyPrint = showSDoc unsafeGlobalDynFlags . ppr
100
89
101
90
-- | Run a 'Ghc' monad value using an existing 'HscEnv'. Sets up and tears down all the required
102
91
-- pieces, but designed to be more efficient than a standard 'runGhc'.
@@ -110,36 +99,6 @@ runGhcEnv env act = do
110
99
cleanTempFiles dflags
111
100
cleanTempDirs dflags
112
101
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
-
143
102
-- | Given a module location, and its parse tree, figure out what is the include directory implied by it.
144
103
-- For example, given the file @\/usr\/\Test\/Foo\/Bar.hs@ with the module name @Foo.Bar@ the directory
145
104
-- @\/usr\/Test@ should be on the include path to find sibling modules.
0 commit comments