module Shaker.Type
where
import DynFlags hiding (OneShot)
import qualified Data.Map as M
import Control.Monad.Reader
import System.Time(ClockTime)
import Control.Concurrent.MVar
import Control.Concurrent
type Shaker = ReaderT ShakerInput
type ShakerR = Reader ShakerInput
type ThreadIdList = MVar [ThreadId]
type Token = MVar Int
type CompileM = Reader CompileInput
data Duration =
OneShot
| Continuous
deriving (Show,Eq)
data Action =
Action ShakerAction
| ActionWithArg ShakerAction [String]
deriving (Show,Eq,Ord)
type Input = MVar (Maybe Command)
data InputState = InputState {
input :: Input,
token :: Token
}
data ShakerAction =
Compile
| FullCompile
| TestFramework
| ModuleTestFramework
| IntelligentTestFramework
| IntelligentModuleTestFramework
| InvalidAction
| Help
| Execute
| Empty
| Quit
| Clean
deriving (Show,Eq,Ord)
data Command = Command Duration [Action]
deriving (Show,Eq)
data ShakerInput = ShakerInput {
compileInputs :: [CompileInput]
,listenerInput :: ListenerInput
,pluginMap :: PluginMap
,commandMap :: CommandMap
,argument :: [String]
,modifiedInfoFiles :: [FileInfo]
,threadData :: ThreadData
,inputState :: InputState
}
data ThreadData = ThreadData {
listenToken :: Token
,quitToken :: Token
,threadIdListenList :: ThreadIdList
,threadIdQuitList :: ThreadIdList
}
getListenThreadList :: ShakerInput -> ThreadIdList
getListenThreadList = threadIdListenList . threadData
data CompileInput = CompileInput{
cfSourceDirs :: [String]
,cfDescription :: String
,cfCompileTarget :: String
,cfDynFlags :: (DynFlags->DynFlags)
,cfCommandLineFlags :: [String]
,cfTargetFiles :: [String]
}
instance Show CompileInput
where show (CompileInput src desc _ _ commandLine target) =
concat ["CompileInput |source : ",show src," |desc : ",desc," |cmdLine : ",show commandLine," |targetfiles : ", show target]
data ListenerInput = ListenerInput {
fileListenInfo :: [FileListenInfo]
,delay :: Int
}
data FileListenInfo = FileListenInfo{
dir :: FilePath
,ignore :: [String]
,include :: [String]
}
deriving (Show,Eq)
data FileInfo = FileInfo {
fileInfoFilePath :: FilePath
,fileInfoClockTime:: ClockTime
}
deriving (Show,Eq)
type PluginMap = M.Map ShakerAction Plugin
type CommandMap = M.Map String ShakerAction
type Plugin = Shaker IO()
defaultCompileInput :: CompileInput
defaultCompileInput = CompileInput {
cfSourceDirs= ["src/","testsuite/tests/"]
,cfDescription = "Default Compilation"
,cfCompileTarget = "dist/shakerTarget"
,cfDynFlags = defaultCompileFlags
,cfCommandLineFlags = ["-Wall"]
,cfTargetFiles = []
}
defaultCompileFlags :: (DynFlags -> DynFlags)
defaultCompileFlags = \a-> a {
verbosity = 1
,ghcLink = NoLink
}
defaultListenerInput :: ListenerInput
defaultListenerInput = ListenerInput {
fileListenInfo= [FileListenInfo "src/" [] defaultHaskellPatterns, FileListenInfo "testsuite/" [] defaultHaskellPatterns ]
,delay = 2000000
}
defaultHaskellPatterns :: [String]
defaultHaskellPatterns = [".*\\.hs$", ".*\\.lhs"]
defaultExclude :: [String]
defaultExclude = [".*Setup\\.hs$"]
exitCommand :: Command
exitCommand = Command OneShot [Action Quit]
emptyCommand :: Command
emptyCommand = Command OneShot [Action Empty]