Add some Binary & Structured instances
[cabal.git] / Cabal / src / Distribution / Simple / Setup / Benchmark.hs
blob5eac60aee007a8a5ebe560df720a749910fdfe70
1 {-# LANGUAGE CPP #-}
2 {-# LANGUAGE DeriveDataTypeable #-}
3 {-# LANGUAGE DeriveGeneric #-}
4 {-# LANGUAGE FlexibleContexts #-}
5 {-# LANGUAGE RankNTypes #-}
7 -----------------------------------------------------------------------------
9 -- |
10 -- Module : Distribution.Simple.Benchmark
11 -- Copyright : Isaac Jones 2003-2004
12 -- Duncan Coutts 2007
13 -- License : BSD3
15 -- Maintainer : cabal-devel@haskell.org
16 -- Portability : portable
18 -- Definition of the benchmarking command-line options.
19 -- See: @Distribution.Simple.Setup@
20 module Distribution.Simple.Setup.Benchmark
21 ( BenchmarkFlags (..)
22 , emptyBenchmarkFlags
23 , defaultBenchmarkFlags
24 , benchmarkCommand
25 , benchmarkOptions'
26 ) where
28 import Distribution.Compat.Prelude hiding (get)
29 import Prelude ()
31 import Distribution.Simple.Command hiding (boolOpt, boolOpt')
32 import Distribution.Simple.Flag
33 import Distribution.Simple.InstallDirs
34 import Distribution.Simple.Utils
35 import Distribution.Verbosity
37 import Distribution.Simple.Setup.Common
39 -- ------------------------------------------------------------
41 -- * Benchmark flags
43 -- ------------------------------------------------------------
45 data BenchmarkFlags = BenchmarkFlags
46 { benchmarkDistPref :: Flag FilePath
47 , benchmarkVerbosity :: Flag Verbosity
48 , benchmarkOptions :: [PathTemplate]
50 deriving (Show, Generic, Typeable)
52 instance Binary BenchmarkFlags
53 instance Structured BenchmarkFlags
55 defaultBenchmarkFlags :: BenchmarkFlags
56 defaultBenchmarkFlags =
57 BenchmarkFlags
58 { benchmarkDistPref = NoFlag
59 , benchmarkVerbosity = Flag normal
60 , benchmarkOptions = []
63 benchmarkCommand :: CommandUI BenchmarkFlags
64 benchmarkCommand =
65 CommandUI
66 { commandName = "bench"
67 , commandSynopsis =
68 "Run all/specific benchmarks."
69 , commandDescription = Just $ \_pname ->
70 wrapText $
71 testOrBenchmarkHelpText "benchmark"
72 , commandNotes = Nothing
73 , commandUsage =
74 usageAlternatives
75 "bench"
76 [ "[FLAGS]"
77 , "BENCHCOMPONENTS [FLAGS]"
79 , commandDefaultFlags = defaultBenchmarkFlags
80 , commandOptions = benchmarkOptions'
83 benchmarkOptions' :: ShowOrParseArgs -> [OptionField BenchmarkFlags]
84 benchmarkOptions' showOrParseArgs =
85 [ optionVerbosity
86 benchmarkVerbosity
87 (\v flags -> flags{benchmarkVerbosity = v})
88 , optionDistPref
89 benchmarkDistPref
90 (\d flags -> flags{benchmarkDistPref = d})
91 showOrParseArgs
92 , option
94 ["benchmark-options"]
95 ( "give extra options to benchmark executables "
96 ++ "(name templates can use $pkgid, $compiler, "
97 ++ "$os, $arch, $benchmark)"
99 benchmarkOptions
100 (\v flags -> flags{benchmarkOptions = v})
101 ( reqArg'
102 "TEMPLATES"
103 (map toPathTemplate . splitArgs)
104 (const [])
106 , option
108 ["benchmark-option"]
109 ( "give extra option to benchmark executables "
110 ++ "(no need to quote options containing spaces, "
111 ++ "name template can use $pkgid, $compiler, "
112 ++ "$os, $arch, $benchmark)"
114 benchmarkOptions
115 (\v flags -> flags{benchmarkOptions = v})
116 ( reqArg'
117 "TEMPLATE"
118 (\x -> [toPathTemplate x])
119 (map fromPathTemplate)
123 emptyBenchmarkFlags :: BenchmarkFlags
124 emptyBenchmarkFlags = mempty
126 instance Monoid BenchmarkFlags where
127 mempty = gmempty
128 mappend = (<>)
130 instance Semigroup BenchmarkFlags where
131 (<>) = gmappend