{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
module Distribution.Types.ComponentRequestedSpec (
ComponentRequestedSpec(..),
ComponentDisabledReason(..),
defaultComponentRequestedSpec,
componentNameRequested,
componentEnabled,
componentDisabledReason,
) where
import Prelude ()
import Distribution.Compat.Prelude
import Distribution.Types.Component
import Distribution.Types.ComponentName
import Distribution.Pretty (prettyShow)
data ComponentRequestedSpec
= ComponentRequestedSpec { ComponentRequestedSpec -> Bool
testsRequested :: Bool
, ComponentRequestedSpec -> Bool
benchmarksRequested :: Bool }
| OneComponentRequestedSpec ComponentName
deriving ((forall x. ComponentRequestedSpec -> Rep ComponentRequestedSpec x)
-> (forall x.
Rep ComponentRequestedSpec x -> ComponentRequestedSpec)
-> Generic ComponentRequestedSpec
forall x. Rep ComponentRequestedSpec x -> ComponentRequestedSpec
forall x. ComponentRequestedSpec -> Rep ComponentRequestedSpec x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ComponentRequestedSpec -> Rep ComponentRequestedSpec x
from :: forall x. ComponentRequestedSpec -> Rep ComponentRequestedSpec x
$cto :: forall x. Rep ComponentRequestedSpec x -> ComponentRequestedSpec
to :: forall x. Rep ComponentRequestedSpec x -> ComponentRequestedSpec
Generic, ReadPrec [ComponentRequestedSpec]
ReadPrec ComponentRequestedSpec
Int -> ReadS ComponentRequestedSpec
ReadS [ComponentRequestedSpec]
(Int -> ReadS ComponentRequestedSpec)
-> ReadS [ComponentRequestedSpec]
-> ReadPrec ComponentRequestedSpec
-> ReadPrec [ComponentRequestedSpec]
-> Read ComponentRequestedSpec
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS ComponentRequestedSpec
readsPrec :: Int -> ReadS ComponentRequestedSpec
$creadList :: ReadS [ComponentRequestedSpec]
readList :: ReadS [ComponentRequestedSpec]
$creadPrec :: ReadPrec ComponentRequestedSpec
readPrec :: ReadPrec ComponentRequestedSpec
$creadListPrec :: ReadPrec [ComponentRequestedSpec]
readListPrec :: ReadPrec [ComponentRequestedSpec]
Read, Int -> ComponentRequestedSpec -> ShowS
[ComponentRequestedSpec] -> ShowS
ComponentRequestedSpec -> String
(Int -> ComponentRequestedSpec -> ShowS)
-> (ComponentRequestedSpec -> String)
-> ([ComponentRequestedSpec] -> ShowS)
-> Show ComponentRequestedSpec
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ComponentRequestedSpec -> ShowS
showsPrec :: Int -> ComponentRequestedSpec -> ShowS
$cshow :: ComponentRequestedSpec -> String
show :: ComponentRequestedSpec -> String
$cshowList :: [ComponentRequestedSpec] -> ShowS
showList :: [ComponentRequestedSpec] -> ShowS
Show, ComponentRequestedSpec -> ComponentRequestedSpec -> Bool
(ComponentRequestedSpec -> ComponentRequestedSpec -> Bool)
-> (ComponentRequestedSpec -> ComponentRequestedSpec -> Bool)
-> Eq ComponentRequestedSpec
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ComponentRequestedSpec -> ComponentRequestedSpec -> Bool
== :: ComponentRequestedSpec -> ComponentRequestedSpec -> Bool
$c/= :: ComponentRequestedSpec -> ComponentRequestedSpec -> Bool
/= :: ComponentRequestedSpec -> ComponentRequestedSpec -> Bool
Eq, Typeable)
instance Binary ComponentRequestedSpec
instance Structured ComponentRequestedSpec
defaultComponentRequestedSpec :: ComponentRequestedSpec
defaultComponentRequestedSpec :: ComponentRequestedSpec
defaultComponentRequestedSpec = Bool -> Bool -> ComponentRequestedSpec
ComponentRequestedSpec Bool
False Bool
False
componentEnabled :: ComponentRequestedSpec -> Component -> Bool
componentEnabled :: ComponentRequestedSpec -> Component -> Bool
componentEnabled ComponentRequestedSpec
enabled = Maybe ComponentDisabledReason -> Bool
forall a. Maybe a -> Bool
isNothing (Maybe ComponentDisabledReason -> Bool)
-> (Component -> Maybe ComponentDisabledReason)
-> Component
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ComponentRequestedSpec
-> Component -> Maybe ComponentDisabledReason
componentDisabledReason ComponentRequestedSpec
enabled
componentNameRequested :: ComponentRequestedSpec -> ComponentName -> Bool
componentNameRequested :: ComponentRequestedSpec -> ComponentName -> Bool
componentNameRequested ComponentRequestedSpec
enabled = Maybe ComponentDisabledReason -> Bool
forall a. Maybe a -> Bool
isNothing (Maybe ComponentDisabledReason -> Bool)
-> (ComponentName -> Maybe ComponentDisabledReason)
-> ComponentName
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ComponentRequestedSpec
-> ComponentName -> Maybe ComponentDisabledReason
componentNameNotRequestedReason ComponentRequestedSpec
enabled
componentDisabledReason :: ComponentRequestedSpec -> Component
-> Maybe ComponentDisabledReason
componentDisabledReason :: ComponentRequestedSpec
-> Component -> Maybe ComponentDisabledReason
componentDisabledReason ComponentRequestedSpec
enabled Component
comp
| Bool -> Bool
not (Component -> Bool
componentBuildable Component
comp) = ComponentDisabledReason -> Maybe ComponentDisabledReason
forall a. a -> Maybe a
Just ComponentDisabledReason
DisabledComponent
| Bool
otherwise = ComponentRequestedSpec
-> ComponentName -> Maybe ComponentDisabledReason
componentNameNotRequestedReason ComponentRequestedSpec
enabled (Component -> ComponentName
componentName Component
comp)
componentNameNotRequestedReason :: ComponentRequestedSpec -> ComponentName
-> Maybe ComponentDisabledReason
componentNameNotRequestedReason :: ComponentRequestedSpec
-> ComponentName -> Maybe ComponentDisabledReason
componentNameNotRequestedReason
ComponentRequestedSpec{ testsRequested :: ComponentRequestedSpec -> Bool
testsRequested = Bool
False } (CTestName UnqualComponentName
_)
= ComponentDisabledReason -> Maybe ComponentDisabledReason
forall a. a -> Maybe a
Just ComponentDisabledReason
DisabledAllTests
componentNameNotRequestedReason
ComponentRequestedSpec{ benchmarksRequested :: ComponentRequestedSpec -> Bool
benchmarksRequested = Bool
False } (CBenchName UnqualComponentName
_)
= ComponentDisabledReason -> Maybe ComponentDisabledReason
forall a. a -> Maybe a
Just ComponentDisabledReason
DisabledAllBenchmarks
componentNameNotRequestedReason ComponentRequestedSpec{} ComponentName
_ = Maybe ComponentDisabledReason
forall a. Maybe a
Nothing
componentNameNotRequestedReason (OneComponentRequestedSpec ComponentName
cname) ComponentName
c
| ComponentName
c ComponentName -> ComponentName -> Bool
forall a. Eq a => a -> a -> Bool
== ComponentName
cname = Maybe ComponentDisabledReason
forall a. Maybe a
Nothing
| Bool
otherwise = ComponentDisabledReason -> Maybe ComponentDisabledReason
forall a. a -> Maybe a
Just (String -> ComponentDisabledReason
DisabledAllButOne (ComponentName -> String
forall a. Pretty a => a -> String
prettyShow ComponentName
cname))
data ComponentDisabledReason = DisabledComponent
| DisabledAllTests
| DisabledAllBenchmarks
| DisabledAllButOne String