make LTS branch pre-releases
[cabal.git] / Cabal-syntax / src / Distribution / Types / Executable.hs
bloba2140e074a744b9cbbbc44189760fc0b195af253
1 {-# LANGUAGE DataKinds #-}
2 {-# LANGUAGE DeriveDataTypeable #-}
3 {-# LANGUAGE DeriveGeneric #-}
5 module Distribution.Types.Executable
6 ( Executable (..)
7 , emptyExecutable
8 , exeModules
9 , exeModulesAutogen
10 ) where
12 import Distribution.Compat.Prelude
13 import Prelude ()
15 import Distribution.ModuleName
16 import Distribution.Types.BuildInfo
17 import Distribution.Types.ExecutableScope
18 import Distribution.Types.UnqualComponentName
19 import Distribution.Utils.Path
21 import qualified Distribution.Types.BuildInfo.Lens as L
23 data Executable = Executable
24 { exeName :: UnqualComponentName
25 , modulePath :: RelativePath Source File
26 , exeScope :: ExecutableScope
27 , buildInfo :: BuildInfo
29 deriving (Generic, Show, Read, Eq, Ord, Typeable, Data)
31 instance L.HasBuildInfo Executable where
32 buildInfo f l = (\x -> l{buildInfo = x}) <$> f (buildInfo l)
34 instance Binary Executable
35 instance Structured Executable
36 instance NFData Executable where rnf = genericRnf
38 instance Monoid Executable where
39 mempty =
40 Executable
41 { exeName = mempty
42 , modulePath = unsafeMakeSymbolicPath ""
43 , exeScope = mempty
44 , buildInfo = mempty
46 mappend = (<>)
48 instance Semigroup Executable where
49 a <> b =
50 Executable
51 { exeName = combineNames a b exeName "executable"
52 , modulePath = unsafeMakeSymbolicPath $ combineNames a b (getSymbolicPath . modulePath) "modulePath"
53 , exeScope = combine exeScope
54 , buildInfo = combine buildInfo
56 where
57 combine field = field a `mappend` field b
59 emptyExecutable :: Executable
60 emptyExecutable = mempty
62 -- | Get all the module names from an exe
63 exeModules :: Executable -> [ModuleName]
64 exeModules exe = otherModules (buildInfo exe)
66 -- | Get all the auto generated module names from an exe
67 -- This are a subset of 'exeModules'.
68 exeModulesAutogen :: Executable -> [ModuleName]
69 exeModulesAutogen exe = autogenModules (buildInfo exe)