HIE.Bios.Environment

hie-bios-0.14.0: Set up a GHC API session

Safe Haskell | None
Language | Haskell2010

HIE.Bios.Environment

Synopsis

- initSession :: GhcMonad m => ComponentOptions -> m [Target]
- getRuntimeGhcLibDir :: Cradle a -> IO (CradleLoadResult FilePath)
- getRuntimeGhcVersion :: Cradle a -> IO (CradleLoadResult String)
- makeDynFlagsAbsolute :: FilePath -> DynFlags -> DynFlags
- makeTargetsAbsolute :: FilePath -> [Target] -> [Target]
- getCacheDir :: FilePath -> IO FilePath
- addCmdOpts :: GhcMonad m => [String] -> DynFlags -> m (DynFlags, [Target])

# Documentation

initSession :: GhcMonad m => ComponentOptions -> m [Target] #

Start a GHC session and set some sensible options for tooling to use. Creates a folder in the cache directory to cache interface files to make reloading faster.

getRuntimeGhcLibDir :: Cradle a -> IO (CradleLoadResult FilePath) #

`getRuntimeGhcLibDir cradle` will give you the ghc libDir: do not use `runGhcCmd` directly.

Obtains libdir by calling `runCradleGhc` on the provided cradle.

getRuntimeGhcVersion :: Cradle a -> IO (CradleLoadResult String) #

Gets the version of ghc used when compiling the cradle. It is based off of `getRuntimeGhcLibDir`. If it can't work out the verison reliably, it will return a `CradleError`

makeDynFlagsAbsolute :: FilePath -> DynFlags -> DynFlags #

Make filepaths in the given `DynFlags` absolute. This makes the `DynFlags` independent of the current working directory.

makeTargetsAbsolute :: FilePath -> [Target] -> [Target] #

getCacheDir :: FilePath -> IO FilePath #

Back in the day we used to clear the cache at the start of each session, however, it's not really necessary as 1. There is one cache dir for any change in options. 2. Interface files are resistent to bad option changes anyway.

    clearInterfaceCache :: FilePath -> IO ()
    clearInterfaceCache fp = do
      cd <- getCacheDir fp
      res <- doesPathExist cd
      when res (removeDirectoryRecursive cd)

Prepends the cache directory used by the library to the supplied file path. It tries to use the path under the environment variable `$HIE_BIOS_CACHE_DIR` and falls back to the standard `$XDG_CACHE_HOME/hie-bios` if the former is not set

addCmdOpts :: GhcMonad m => [String] -> DynFlags -> m (DynFlags, [Target]) #

Interpret and set the specific command line options. A lot of this code is just copied from ghc/Main.hs It would be good to move this code into a library module so we can just use it rather than copy it.