1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE DeriveGeneric #-}
3 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
5 module Distribution
.Types
.UnqualComponentName
7 , unUnqualComponentName
8 , unUnqualComponentNameST
9 , mkUnqualComponentName
10 , packageNameToUnqualComponentName
11 , unqualComponentNameToPackageName
15 import Distribution
.Compat
.Prelude
16 import Distribution
.Utils
.ShortText
18 import Distribution
.Parsec
19 import Distribution
.Pretty
20 import Distribution
.Types
.PackageName
22 -- | An unqualified component name, for any kind of component.
24 -- This is distinguished from a 'ComponentName' and 'ComponentId'. The former
25 -- also states which of a library, executable, etc the name refers too. The
26 -- later uniquely identifiers a component and its closure.
29 newtype UnqualComponentName
= UnqualComponentName ShortText
39 , Monoid
-- TODO: bad enabler of bad monoids
42 -- | Convert 'UnqualComponentName' to 'String'
45 unUnqualComponentName
:: UnqualComponentName
-> String
46 unUnqualComponentName
(UnqualComponentName s
) = fromShortText s
49 unUnqualComponentNameST
:: UnqualComponentName
-> ShortText
50 unUnqualComponentNameST
(UnqualComponentName s
) = s
52 -- | Construct a 'UnqualComponentName' from a 'String'
54 -- 'mkUnqualComponentName' is the inverse to 'unUnqualComponentName'
56 -- Note: No validations are performed to ensure that the resulting
57 -- 'UnqualComponentName' is valid
60 mkUnqualComponentName
:: String -> UnqualComponentName
61 mkUnqualComponentName
= UnqualComponentName
. toShortText
63 -- | 'mkUnqualComponentName'
66 instance IsString UnqualComponentName
where
67 fromString
= mkUnqualComponentName
69 instance Binary UnqualComponentName
70 instance Structured UnqualComponentName
72 instance Pretty UnqualComponentName
where
73 pretty
= showToken
. unUnqualComponentName
75 instance Parsec UnqualComponentName
where
76 parsec
= mkUnqualComponentName
<$> parsecUnqualComponentName
78 instance NFData UnqualComponentName
where
79 rnf
(UnqualComponentName pkg
) = rnf pkg
81 -- TODO avoid String round trip with these PackageName <->
82 -- UnqualComponentName converters.
84 -- | Converts a package name to an unqualified component name
86 -- Useful in legacy situations where a package name may refer to an internal
87 -- component, if one is defined with that name.
89 -- 2018-12-21: These "legacy" situations are not legacy.
90 -- We can @build-depends@ on the internal library. However
91 -- Now dependency contains @Set LibraryName@, and we should use that.
94 packageNameToUnqualComponentName
:: PackageName
-> UnqualComponentName
95 packageNameToUnqualComponentName
= UnqualComponentName
. unPackageNameST
97 -- | Converts an unqualified component name to a package name
99 -- `packageNameToUnqualComponentName` is the inverse of
100 -- `unqualComponentNameToPackageName`.
102 -- Useful in legacy situations where a package name may refer to an internal
103 -- component, if one is defined with that name.
106 unqualComponentNameToPackageName
:: UnqualComponentName
-> PackageName
107 unqualComponentNameToPackageName
= mkPackageNameST
. unUnqualComponentNameST
109 -- | Combine names in targets if one name is empty or both names are equal
110 -- (partial function).
111 -- Useful in 'Semigroup' and similar instances.
113 :: (Monoid b
, Eq b
, Show b
)
119 combineNames a b tacc tt
120 -- One empty or the same.
126 -- Both non-empty, different.
129 "Ambiguous values for "
137 (na
, nb
) = (tacc a
, tacc b
)
138 {-# INLINEABLE combineNames #-}