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
  :: 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
  (Cradle a -> LogAction IO (WithSeverity Log)
forall a. Cradle a -> LogAction IO (WithSeverity Log)
cradleLogger Cradle a
cradle) LogAction IO (WithSeverity Log) -> WithSeverity Log -> IO ()
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)" Log -> Severity -> WithSeverity Log
forall msg. msg -> Severity -> WithSeverity msg
`WithSeverity` Severity
Info
  CradleAction a
-> FilePath -> [FilePath] -> IO (CradleLoadResult ComponentOptions)
forall a.
CradleAction a
-> FilePath -> [FilePath] -> IO (CradleLoadResult ComponentOptions)
runCradle (Cradle a -> CradleAction a
forall a. Cradle a -> CradleAction a
cradleOptsProg Cradle a
cradle) FilePath
fp [FilePath]
fps