-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathExample.hs
More file actions
58 lines (47 loc) · 1.69 KB
/
Example.hs
File metadata and controls
58 lines (47 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
{-# LANGUAGE FlexibleInstances #-}
module Example(main, platforms) where
import Development.Bake
import Development.Shake.Command
import System.Environment.Extra
import System.FilePath
import Data.List.Extra
import Data.Tuple.Extra
import System.Directory
import Control.Monad
import Data.Maybe
import System.Time.Extra
useStep = True
data Platform = Linux | Windows deriving (Show,Read)
data Action = Compile | Run Int deriving (Show,Read)
instance Stringy (Platform, Action) where
stringyTo (a,b) = show a ++ " " ++ show b
stringyFrom = (read *** read) . word1
platforms = [Linux,Windows]
main :: IO ()
main = do
let err = "You need to set an environment variable named $REPO for the Git repo"
repo <- fromMaybe (error err) `fmap` lookupEnv "REPO"
bake $
ovenPretty $
(if useStep
then ovenStepGit compile repo "master" Nothing ["dist"]
else ovenIncremental . ovenGit repo "master" Nothing) $
ovenNotifyStdout $
ovenTest (return allTests) execute
defaultOven{ovenServer=("127.0.0.1",5000)}
allTests = [(p,t) | p <- platforms, t <- Compile : map Run [1,10,0]]
compile :: IO [FilePath]
compile = do
createDirectoryIfMissing True "dist"
unit $ cmd "ghc --make Main.hs -o dist/Main"
-- ghc --make only has 1 second timestamp resolution
-- so sleep for a second to make sure we work with incremental compilation
sleep 1
return ["dist"]
execute :: (Platform,Action) -> TestInfo (Platform,Action)
execute (p,Compile) = require [show p] $ run $ unless useStep $ do
incrementalStart
compile
incrementalDone
execute (p,Run i) = depend [(p,Compile)] $ require [show p] $ run $
cmd ("dist" </> "Main") (show i)