module Imm.Dyre
( Mode(..)
, defaultMode
, wrap
, recompile
) where
import Imm.Prelude
import Config.Dyre
import Config.Dyre.Compile
import Config.Dyre.Paths
data Mode = Normal | Vanilla | ForceReconfiguration | IgnoreReconfiguration
deriving(Eq, Show)
defaultMode :: Mode
defaultMode = Normal
describePaths :: (IsString t, MonadIO m) => m t
describePaths = io $ do
(a, b, c, d, e) <- getPaths baseParameters
return $ fromString $ unlines
[ "Current binary: " <> a
, "Custom binary: " <> b
, "Config file: " <> c
, "Cache directory: " <> d
, "Lib directory: " <> e
]
parameters :: Mode -> (a -> IO ()) -> Params (Either Text a)
parameters mode main = baseParameters
{ configCheck = mode /= Vanilla
, realMain = main'
}
where
main' (Left e) = hPutStrLn stderr e
main' (Right x) = main x
baseParameters :: Params (Either Text a)
baseParameters = defaultParams
{ projectName = "imm"
, showError = const (Left . fromString)
, ghcOpts = ["-threaded"]
, statusOut = hPutStrLn stderr
, includeCurrentDirectory = False
}
wrap :: Mode -> (a -> IO ()) -> a -> IO ()
wrap mode result args = wrapMain (parameters mode result) (Right args)
recompile :: (MonadIO m) => m (Maybe Text)
recompile = io $ do
customCompile baseParameters
fmap fromString <$> getErrorString baseParameters