make LTS branch pre-releases
[cabal.git] / Cabal-syntax / src / Distribution / Types / Benchmark.hs
blob13e5fe104e5317df2e2f351313d855c0f46024c6
1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE DeriveGeneric #-}
4 module Distribution.Types.Benchmark
5 ( Benchmark (..)
6 , emptyBenchmark
7 , benchmarkType
8 , benchmarkModules
9 , benchmarkModulesAutogen
10 ) where
12 import Distribution.Compat.Prelude
13 import Prelude ()
15 import Distribution.Types.BenchmarkInterface
16 import Distribution.Types.BenchmarkType
17 import Distribution.Types.BuildInfo
18 import Distribution.Types.UnqualComponentName
20 import Distribution.ModuleName
22 import qualified Distribution.Types.BuildInfo.Lens as L
24 -- | A \"benchmark\" stanza in a cabal file.
25 data Benchmark = Benchmark
26 { benchmarkName :: UnqualComponentName
27 , benchmarkInterface :: BenchmarkInterface
28 , benchmarkBuildInfo :: BuildInfo
30 deriving (Generic, Show, Read, Eq, Ord, Typeable, Data)
32 instance Binary Benchmark
33 instance Structured Benchmark
34 instance NFData Benchmark where rnf = genericRnf
36 instance L.HasBuildInfo Benchmark where
37 buildInfo f (Benchmark x1 x2 x3) = fmap (\y1 -> Benchmark x1 x2 y1) (f x3)
39 instance Monoid Benchmark where
40 mempty =
41 Benchmark
42 { benchmarkName = mempty
43 , benchmarkInterface = mempty
44 , benchmarkBuildInfo = mempty
46 mappend = (<>)
48 instance Semigroup Benchmark where
49 a <> b =
50 Benchmark
51 { benchmarkName = combineNames a b benchmarkName "benchmark"
52 , benchmarkInterface = combine benchmarkInterface
53 , benchmarkBuildInfo = combine benchmarkBuildInfo
55 where
56 combine field = field a `mappend` field b
58 emptyBenchmark :: Benchmark
59 emptyBenchmark = mempty
61 benchmarkType :: Benchmark -> BenchmarkType
62 benchmarkType benchmark = case benchmarkInterface benchmark of
63 BenchmarkExeV10 ver _ -> BenchmarkTypeExe ver
64 BenchmarkUnsupported benchmarktype -> benchmarktype
66 -- | Get all the module names from a benchmark.
67 benchmarkModules :: Benchmark -> [ModuleName]
68 benchmarkModules benchmark = otherModules (benchmarkBuildInfo benchmark)
70 -- | Get all the auto generated module names from a benchmark.
71 -- This are a subset of 'benchmarkModules'.
72 benchmarkModulesAutogen :: Benchmark -> [ModuleName]
73 benchmarkModulesAutogen benchmark = autogenModules (benchmarkBuildInfo benchmark)