module HIE.Bios.Flags (getCompilerOptions) where

import HIE.Bios.Types

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

-- | Initialize the 'DynFlags' relating to the compilation of a single
-- file or GHC session according to the provided 'Cradle'.
getCompilerOptions
  :: LogAction IO (WithSeverity Log)
  -> FilePath -- The file we are loading it because of
  -> Cradle a
  -> IO (CradleLoadResult ComponentOptions)
getCompilerOptions :: forall a.
LogAction IO (WithSeverity Log)
-> FilePath -> Cradle a -> IO (CradleLoadResult ComponentOptions)
getCompilerOptions LogAction IO (WithSeverity Log)
l FilePath
fp Cradle a
cradle = do
  LogAction IO (WithSeverity Log)
l 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
-> LogAction IO (WithSeverity Log)
-> FilePath
-> IO (CradleLoadResult ComponentOptions)
runCradle (forall a. Cradle a -> CradleAction a
cradleOptsProg Cradle a
cradle) LogAction IO (WithSeverity Log)
l FilePath
fp