-
Notifications
You must be signed in to change notification settings - Fork 0
/
Setup.hs
41 lines (34 loc) · 1.55 KB
/
Setup.hs
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
import Control.Monad
import Distribution.Simple
import System.Environment
--import System.IO
-- Surprisingly, if the user types "cabal install --enable-tests",
-- `args` will *not* be ["install", "--enable-tests"]. Instead, cabal will
-- run Setup.hs repeatedly with different arguments:
--
-- ["configure","--verbose=1","--builddir=dist/dist-sandbox-28d8356a","--ghc","--prefix=...",...]
-- ["build","--verbose=1","--builddir=dist/dist-sandbox-28d8356a"]
-- ["test","--builddir=dist/dist-sandbox-28d8356a"]
-- ["install","--verbose=1","--builddir=dist/dist-sandbox-28d8356a"]
--
-- We need to manipulate `args` via `substitute` in order to preserve those
-- extra arguments.
substitute :: Eq a => [(a, [a])] -> [a] -> [a]
substitute substitutions = (>>= go)
where
go x = case lookup x substitutions of
Just xs -> xs
Nothing -> return x
main = do
args <- getArgs
--withFile "Setup.log" AppendMode $ \h -> do
-- hPutStrLn h (show args)
when ("test" `elem` args) $ do
-- unlike most packages, this one needs to be installed before it can be tested.
defaultMainArgs (substitute [ ("test", ["install","--verbose=1"])
-- remove test-specific arguments
, ("--log=$pkgid-$test-suite.log", [])
, ("--machine-log=$pkgid.log", [])
, ("--show-details=failures", [])
] args)
defaultMainArgs args