{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
module Stack.Types.NamedComponent
( NamedComponent (..)
, renderComponent
, renderPkgComponents
, renderPkgComponent
, exeComponents
, testComponents
, benchComponents
, internalLibComponents
, isCLib
, isCInternalLib
, isCExe
, isCTest
, isCBench
) where
import qualified Data.Set as Set
import qualified Data.Text as T
import Stack.Prelude
data NamedComponent
= CLib
| CInternalLib !Text
| CExe !Text
| CTest !Text
| CBench !Text
deriving (NamedComponent -> NamedComponent -> Bool
(NamedComponent -> NamedComponent -> Bool)
-> (NamedComponent -> NamedComponent -> Bool) -> Eq NamedComponent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: NamedComponent -> NamedComponent -> Bool
== :: NamedComponent -> NamedComponent -> Bool
$c/= :: NamedComponent -> NamedComponent -> Bool
/= :: NamedComponent -> NamedComponent -> Bool
Eq, Eq NamedComponent
Eq NamedComponent
-> (NamedComponent -> NamedComponent -> Ordering)
-> (NamedComponent -> NamedComponent -> Bool)
-> (NamedComponent -> NamedComponent -> Bool)
-> (NamedComponent -> NamedComponent -> Bool)
-> (NamedComponent -> NamedComponent -> Bool)
-> (NamedComponent -> NamedComponent -> NamedComponent)
-> (NamedComponent -> NamedComponent -> NamedComponent)
-> Ord NamedComponent
NamedComponent -> NamedComponent -> Bool
NamedComponent -> NamedComponent -> Ordering
NamedComponent -> NamedComponent -> NamedComponent
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: NamedComponent -> NamedComponent -> Ordering
compare :: NamedComponent -> NamedComponent -> Ordering
$c< :: NamedComponent -> NamedComponent -> Bool
< :: NamedComponent -> NamedComponent -> Bool
$c<= :: NamedComponent -> NamedComponent -> Bool
<= :: NamedComponent -> NamedComponent -> Bool
$c> :: NamedComponent -> NamedComponent -> Bool
> :: NamedComponent -> NamedComponent -> Bool
$c>= :: NamedComponent -> NamedComponent -> Bool
>= :: NamedComponent -> NamedComponent -> Bool
$cmax :: NamedComponent -> NamedComponent -> NamedComponent
max :: NamedComponent -> NamedComponent -> NamedComponent
$cmin :: NamedComponent -> NamedComponent -> NamedComponent
min :: NamedComponent -> NamedComponent -> NamedComponent
Ord, Int -> NamedComponent -> ShowS
[NamedComponent] -> ShowS
NamedComponent -> String
(Int -> NamedComponent -> ShowS)
-> (NamedComponent -> String)
-> ([NamedComponent] -> ShowS)
-> Show NamedComponent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NamedComponent -> ShowS
showsPrec :: Int -> NamedComponent -> ShowS
$cshow :: NamedComponent -> String
show :: NamedComponent -> String
$cshowList :: [NamedComponent] -> ShowS
showList :: [NamedComponent] -> ShowS
Show)
renderComponent :: NamedComponent -> Text
renderComponent :: NamedComponent -> Text
renderComponent NamedComponent
CLib = Text
"lib"
renderComponent (CInternalLib Text
x) = Text
"internal-lib:" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
x
renderComponent (CExe Text
x) = Text
"exe:" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
x
renderComponent (CTest Text
x) = Text
"test:" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
x
renderComponent (CBench Text
x) = Text
"bench:" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
x
renderPkgComponents :: [(PackageName, NamedComponent)] -> Text
renderPkgComponents :: [(PackageName, NamedComponent)] -> Text
renderPkgComponents = Text -> [Text] -> Text
T.intercalate Text
" " ([Text] -> Text)
-> ([(PackageName, NamedComponent)] -> [Text])
-> [(PackageName, NamedComponent)]
-> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((PackageName, NamedComponent) -> Text)
-> [(PackageName, NamedComponent)] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (PackageName, NamedComponent) -> Text
renderPkgComponent
renderPkgComponent :: (PackageName, NamedComponent) -> Text
renderPkgComponent :: (PackageName, NamedComponent) -> Text
renderPkgComponent (PackageName
pkg, NamedComponent
comp) =
String -> Text
forall a. IsString a => String -> a
fromString (PackageName -> String
packageNameString PackageName
pkg) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
":" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> NamedComponent -> Text
renderComponent NamedComponent
comp
exeComponents :: Set NamedComponent -> Set Text
exeComponents :: Set NamedComponent -> Set Text
exeComponents = [Text] -> Set Text
forall a. Ord a => [a] -> Set a
Set.fromList ([Text] -> Set Text)
-> (Set NamedComponent -> [Text]) -> Set NamedComponent -> Set Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NamedComponent -> Maybe Text) -> [NamedComponent] -> [Text]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe NamedComponent -> Maybe Text
mExeName ([NamedComponent] -> [Text])
-> (Set NamedComponent -> [NamedComponent])
-> Set NamedComponent
-> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set NamedComponent -> [NamedComponent]
forall a. Set a -> [a]
Set.toList
where
mExeName :: NamedComponent -> Maybe Text
mExeName (CExe Text
name) = Text -> Maybe Text
forall a. a -> Maybe a
Just Text
name
mExeName NamedComponent
_ = Maybe Text
forall a. Maybe a
Nothing
testComponents :: Set NamedComponent -> Set Text
testComponents :: Set NamedComponent -> Set Text
testComponents = [Text] -> Set Text
forall a. Ord a => [a] -> Set a
Set.fromList ([Text] -> Set Text)
-> (Set NamedComponent -> [Text]) -> Set NamedComponent -> Set Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NamedComponent -> Maybe Text) -> [NamedComponent] -> [Text]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe NamedComponent -> Maybe Text
mTestName ([NamedComponent] -> [Text])
-> (Set NamedComponent -> [NamedComponent])
-> Set NamedComponent
-> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set NamedComponent -> [NamedComponent]
forall a. Set a -> [a]
Set.toList
where
mTestName :: NamedComponent -> Maybe Text
mTestName (CTest Text
name) = Text -> Maybe Text
forall a. a -> Maybe a
Just Text
name
mTestName NamedComponent
_ = Maybe Text
forall a. Maybe a
Nothing
benchComponents :: Set NamedComponent -> Set Text
benchComponents :: Set NamedComponent -> Set Text
benchComponents = [Text] -> Set Text
forall a. Ord a => [a] -> Set a
Set.fromList ([Text] -> Set Text)
-> (Set NamedComponent -> [Text]) -> Set NamedComponent -> Set Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NamedComponent -> Maybe Text) -> [NamedComponent] -> [Text]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe NamedComponent -> Maybe Text
mBenchName ([NamedComponent] -> [Text])
-> (Set NamedComponent -> [NamedComponent])
-> Set NamedComponent
-> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set NamedComponent -> [NamedComponent]
forall a. Set a -> [a]
Set.toList
where
mBenchName :: NamedComponent -> Maybe Text
mBenchName (CBench Text
name) = Text -> Maybe Text
forall a. a -> Maybe a
Just Text
name
mBenchName NamedComponent
_ = Maybe Text
forall a. Maybe a
Nothing
internalLibComponents :: Set NamedComponent -> Set Text
internalLibComponents :: Set NamedComponent -> Set Text
internalLibComponents = [Text] -> Set Text
forall a. Ord a => [a] -> Set a
Set.fromList ([Text] -> Set Text)
-> (Set NamedComponent -> [Text]) -> Set NamedComponent -> Set Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NamedComponent -> Maybe Text) -> [NamedComponent] -> [Text]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe NamedComponent -> Maybe Text
mInternalName ([NamedComponent] -> [Text])
-> (Set NamedComponent -> [NamedComponent])
-> Set NamedComponent
-> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set NamedComponent -> [NamedComponent]
forall a. Set a -> [a]
Set.toList
where
mInternalName :: NamedComponent -> Maybe Text
mInternalName (CInternalLib Text
name) = Text -> Maybe Text
forall a. a -> Maybe a
Just Text
name
mInternalName NamedComponent
_ = Maybe Text
forall a. Maybe a
Nothing
isCLib :: NamedComponent -> Bool
isCLib :: NamedComponent -> Bool
isCLib CLib{} = Bool
True
isCLib NamedComponent
_ = Bool
False
isCInternalLib :: NamedComponent -> Bool
isCInternalLib :: NamedComponent -> Bool
isCInternalLib CInternalLib{} = Bool
True
isCInternalLib NamedComponent
_ = Bool
False
isCExe :: NamedComponent -> Bool
isCExe :: NamedComponent -> Bool
isCExe CExe{} = Bool
True
isCExe NamedComponent
_ = Bool
False
isCTest :: NamedComponent -> Bool
isCTest :: NamedComponent -> Bool
isCTest CTest{} = Bool
True
isCTest NamedComponent
_ = Bool
False
isCBench :: NamedComponent -> Bool
isCBench :: NamedComponent -> Bool
isCBench CBench{} = Bool
True
isCBench NamedComponent
_ = Bool
False