Support GHC 9.12
[cabal.git] / Cabal / src / Distribution / Simple / Build / Inputs.hs
blob48b3b60a12b7e1abfdc47e092634de0509c0fd58
1 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
2 {-# LANGUAGE NamedFieldPuns #-}
3 {-# LANGUAGE PatternSynonyms #-}
5 module Distribution.Simple.Build.Inputs
6 ( -- * Inputs of actions for building components
7 PreBuildComponentInputs (..)
9 -- * Queries over the component being built
10 , buildVerbosity
11 , buildComponent
12 , buildIsLib
13 , buildCLBI
14 , buildBI
15 , buildCompiler
17 -- * Re-exports
18 , BuildingWhat (..)
19 , LocalBuildInfo (..)
20 , TargetInfo (..)
21 , buildingWhatVerbosity
22 , buildingWhatDistPref
24 where
26 import Distribution.Simple.Compiler
27 import Distribution.Simple.Setup (BuildingWhat (..), buildingWhatDistPref, buildingWhatVerbosity)
28 import Distribution.Types.BuildInfo
29 import Distribution.Types.Component
30 import Distribution.Types.ComponentLocalBuildInfo
31 import Distribution.Types.LocalBuildInfo
32 import Distribution.Types.TargetInfo
33 import Distribution.Verbosity
35 -- | The information required for a build computation which is available right
36 -- before building each component, i.e. the pre-build component inputs.
37 data PreBuildComponentInputs = PreBuildComponentInputs
38 { buildingWhat :: BuildingWhat
39 -- ^ What kind of build are we doing?
40 , localBuildInfo :: LocalBuildInfo
41 -- ^ Information about the package
42 , targetInfo :: TargetInfo
43 -- ^ Information about an individual component
46 -- | Get the @'Verbosity'@ from the context the component being built is in.
47 buildVerbosity :: PreBuildComponentInputs -> Verbosity
48 buildVerbosity = buildingWhatVerbosity . buildingWhat
50 -- | Get the @'Component'@ being built.
51 buildComponent :: PreBuildComponentInputs -> Component
52 buildComponent = targetComponent . targetInfo
54 -- | Is the @'Component'@ being built a @'Library'@?
55 buildIsLib :: PreBuildComponentInputs -> Bool
56 buildIsLib = do
57 component <- buildComponent
58 let isLib
59 | CLib{} <- component = True
60 | otherwise = False
61 return isLib
62 {-# INLINE buildIsLib #-}
64 -- | Get the @'ComponentLocalBuildInfo'@ for the component being built.
65 buildCLBI :: PreBuildComponentInputs -> ComponentLocalBuildInfo
66 buildCLBI = targetCLBI . targetInfo
68 -- | Get the @'BuildInfo'@ of the component being built.
69 buildBI :: PreBuildComponentInputs -> BuildInfo
70 buildBI = componentBuildInfo . buildComponent
72 -- | Get the @'Compiler'@ being used to build the component.
73 buildCompiler :: PreBuildComponentInputs -> Compiler
74 buildCompiler = compiler . localBuildInfo