module HIE.Bios.Flags (getCompilerOptions) where

import HIE.Bios.Types

import Colog.Core (WithSeverity (..), Severity (..), (<&))

-- | Initialize the 'DynFlags' relating to the compilation of a single
-- file or GHC session according to the provided 'Cradle'.
getCompilerOptions
  :: FilePath -- ^ The file we are loading it because of
  -> [FilePath] -- ^ previous files we might want to include in the build
  -> Cradle a
  -> IO (CradleLoadResult ComponentOptions)
getCompilerOptions :: forall a.
FilePath
-> [FilePath] -> Cradle a -> IO (CradleLoadResult ComponentOptions)
getCompilerOptions FilePath
fp [FilePath]
fps Cradle a
cradle = do
  (forall a. Cradle a -> LogAction IO (WithSeverity Log)
cradleLogger Cradle a
cradle) forall (m :: * -> *) msg. LogAction m msg -> msg -> m ()
<& FilePath -> Log
LogProcessOutput FilePath
"invoking build tool to determine build flags (this may take some time depending on the cache)" forall msg. msg -> Severity -> WithSeverity msg
`WithSeverity` Severity
Info
  forall a.
CradleAction a
-> FilePath -> [FilePath] -> IO (CradleLoadResult ComponentOptions)
runCradle (forall a. Cradle a -> CradleAction a
cradleOptsProg Cradle a
cradle) FilePath
fp [FilePath]
fps