1 {-# LANGUAGE DeriveGeneric #-}
3 module Distribution
.Types
.Component
12 import Distribution
.Compat
.Prelude
15 import Distribution
.Types
.Benchmark
16 import Distribution
.Types
.Executable
17 import Distribution
.Types
.ForeignLib
18 import Distribution
.Types
.Library
19 import Distribution
.Types
.TestSuite
21 import Distribution
.Types
.BuildInfo
22 import Distribution
.Types
.ComponentName
24 import qualified Distribution
.Types
.BuildInfo
.Lens
as L
32 deriving (Generic
, Show, Eq
, Read)
34 instance Binary Component
35 instance Structured Component
37 instance Semigroup Component
where
38 CLib l
<> CLib l
' = CLib
(l
<> l
')
39 CFLib l
<> CFLib l
' = CFLib
(l
<> l
')
40 CExe e
<> CExe e
' = CExe
(e
<> e
')
41 CTest t
<> CTest t
' = CTest
(t
<> t
')
42 CBench b
<> CBench b
' = CBench
(b
<> b
')
43 _
<> _
= error "Cannot merge Component"
45 instance L
.HasBuildInfo Component
where
46 buildInfo f
(CLib l
) = CLib
<$> L
.buildInfo f l
47 buildInfo f
(CFLib l
) = CFLib
<$> L
.buildInfo f l
48 buildInfo f
(CExe e
) = CExe
<$> L
.buildInfo f e
49 buildInfo f
(CTest t
) = CTest
<$> L
.buildInfo f t
50 buildInfo f
(CBench b
) = CBench
<$> L
.buildInfo f b
60 foldComponent f _ _ _ _
(CLib lib
) = f lib
61 foldComponent _ f _ _ _
(CFLib flib
) = f flib
62 foldComponent _ _ f _ _
(CExe exe
) = f exe
63 foldComponent _ _ _ f _
(CTest tst
) = f tst
64 foldComponent _ _ _ _ f
(CBench bch
) = f bch
66 componentBuildInfo
:: Component
-> BuildInfo
68 foldComponent libBuildInfo foreignLibBuildInfo buildInfo testBuildInfo benchmarkBuildInfo
70 -- | Is a component buildable (i.e., not marked with @buildable: False@)?
71 -- See also this note in
72 -- "Distribution.Types.ComponentRequestedSpec#buildable_vs_enabled_components".
75 componentBuildable
:: Component
-> Bool
76 componentBuildable
= buildable
. componentBuildInfo
78 componentName
:: Component
-> ComponentName
82 (CFLibName
. foreignLibName
)
84 (CTestName
. testName
)
85 (CBenchName
. benchmarkName
)
89 -> ([Library
], [ForeignLib
], [Executable
], [TestSuite
], [Benchmark
])
90 partitionComponents
= foldr (foldComponent fa fb fc fd fe
) ([], [], [], [], [])
92 fa x ~
(a
, b
, c
, d
, e
) = (x
: a
, b
, c
, d
, e
)
93 fb x ~
(a
, b
, c
, d
, e
) = (a
, x
: b
, c
, d
, e
)
94 fc x ~
(a
, b
, c
, d
, e
) = (a
, b
, x
: c
, d
, e
)
95 fd x ~
(a
, b
, c
, d
, e
) = (a
, b
, c
, x
: d
, e
)
96 fe x ~
(a
, b
, c
, d
, e
) = (a
, b
, c
, d
, x
: e
)