@@ -98,31 +98,38 @@ data SessionLoadingOptions = SessionLoadingOptions
98
98
-- return the path for storing generated GHC artifacts,
99
99
-- or 'Nothing' to respect the cradle setting
100
100
, getCacheDirs :: String -> [String ] -> IO CacheDirs
101
+ -- | Return the GHC lib dir to use for the 'unsafeGlobalDynFlags'
102
+ , getInitialGhcLibDir :: IO (Maybe LibDir )
101
103
}
102
104
103
105
defaultLoadingOptions :: SessionLoadingOptions
104
106
defaultLoadingOptions = SessionLoadingOptions
105
107
{findCradle = HieBios. findCradle
106
108
,loadCradle = HieBios. loadCradle
107
109
,getCacheDirs = getCacheDirsDefault
110
+ ,getInitialGhcLibDir = getInitialGhcLibDirDefault
108
111
}
109
112
110
- -- | Sets `unsafeGlobalDynFlags` on using the hie-bios cradle and returns the GHC libdir
111
- setInitialDynFlags :: IO (Maybe LibDir )
112
- setInitialDynFlags = do
113
+ getInitialGhcLibDirDefault :: IO (Maybe LibDir )
114
+ getInitialGhcLibDirDefault = do
113
115
dir <- IO. getCurrentDirectory
114
116
hieYaml <- runMaybeT $ yamlConfig dir
115
117
cradle <- maybe (loadImplicitHieCradle $ addTrailingPathSeparator dir) HieBios. loadCradle hieYaml
116
118
hPutStrLn stderr $ " setInitialDynFlags cradle: " ++ show cradle
117
119
libDirRes <- getRuntimeGhcLibDir cradle
118
- libdir <- case libDirRes of
120
+ case libDirRes of
119
121
CradleSuccess libdir -> pure $ Just $ LibDir libdir
120
122
CradleFail err -> do
121
123
hPutStrLn stderr $ " Couldn't load cradle for libdir: " ++ show (err,dir,hieYaml,cradle)
122
124
pure Nothing
123
125
CradleNone -> do
124
126
hPutStrLn stderr $ " Couldn't load cradle (CradleNone)"
125
127
pure Nothing
128
+
129
+ -- | Sets `unsafeGlobalDynFlags` on using the hie-bios cradle and returns the GHC libdir
130
+ setInitialDynFlags :: SessionLoadingOptions -> IO (Maybe LibDir )
131
+ setInitialDynFlags SessionLoadingOptions {.. } = do
132
+ libdir <- getInitialGhcLibDir
126
133
dynFlags <- mapM dynFlagsForPrinting libdir
127
134
mapM_ setUnsafeGlobalDynFlags dynFlags
128
135
pure libdir
0 commit comments