3
3
module Distribution.Backpack.ConfiguredComponent (
4
4
ConfiguredComponent (.. ),
5
5
cc_name ,
6
+ cc_cid ,
7
+ cc_pkgid ,
6
8
toConfiguredComponent ,
7
9
toConfiguredComponents ,
8
10
dispConfiguredComponent ,
@@ -19,6 +21,7 @@ import Distribution.Compat.Prelude hiding ((<>))
19
21
20
22
import Distribution.Backpack.Id
21
23
24
+ import Distribution.Types.AnnotatedId
22
25
import Distribution.Types.Dependency
23
26
import Distribution.Types.ExeDependency
24
27
import Distribution.Types.IncludeRenaming
@@ -48,10 +51,8 @@ import Text.PrettyPrint
48
51
-- and the 'ComponentId's of the things it depends on.
49
52
data ConfiguredComponent
50
53
= ConfiguredComponent {
51
- -- | Uniquely identifies a configured component.
52
- cc_cid :: ComponentId ,
53
- -- | The package this component came from.
54
- cc_pkgid :: PackageId ,
54
+ -- | Unique identifier of component, plus extra useful info.
55
+ cc_ann_id :: AnnotatedId ComponentId ,
55
56
-- | The fragment of syntax from the Cabal file describing this
56
57
-- component.
57
58
cc_component :: Component ,
@@ -63,19 +64,28 @@ data ConfiguredComponent
63
64
cc_public :: Bool ,
64
65
-- | Dependencies on executables from @build-tools@ and
65
66
-- @build-tool-depends@.
66
- cc_exe_deps :: [( ComponentId , PackageId ) ],
67
+ cc_exe_deps :: [AnnotatedId ComponentId ],
67
68
-- | The mixins of this package, including both explicit (from
68
69
-- the @mixins@ field) and implicit (from @build-depends@). Not
69
70
-- mix-in linked yet; component configuration only looks at
70
71
-- 'ComponentId's.
71
72
cc_includes :: [ComponentInclude ComponentId IncludeRenaming ]
72
73
}
73
74
75
+
76
+ -- | Uniquely identifies a configured component.
77
+ cc_cid :: ConfiguredComponent -> ComponentId
78
+ cc_cid = ann_id . cc_ann_id
79
+
80
+ -- | The package this component came from.
81
+ cc_pkgid :: ConfiguredComponent -> PackageId
82
+ cc_pkgid = ann_pid . cc_ann_id
83
+
74
84
-- | The 'ComponentName' of a component; this uniquely identifies
75
85
-- a fragment of syntax within a specified Cabal file describing the
76
86
-- component.
77
87
cc_name :: ConfiguredComponent -> ComponentName
78
- cc_name = componentName . cc_component
88
+ cc_name = ann_cname . cc_ann_id
79
89
80
90
-- | Pretty-print a 'ConfiguredComponent'.
81
91
dispConfiguredComponent :: ConfiguredComponent -> Doc
@@ -91,27 +101,24 @@ dispConfiguredComponent cc =
91
101
mkConfiguredComponent
92
102
:: PackageDescription
93
103
-> ComponentId
94
- -> [(( PackageName , ComponentName ), ( ComponentId , PackageId ))]
95
- -> [( ComponentId , PackageId )]
104
+ -> [AnnotatedId ComponentId ] -- lib deps
105
+ -> [AnnotatedId ComponentId ] -- exe deps
96
106
-> Component
97
107
-> LogProgress ConfiguredComponent
98
- mkConfiguredComponent pkg_decr this_cid lib_deps exe_deps component = do
108
+ mkConfiguredComponent pkg_descr this_cid lib_deps exe_deps component = do
99
109
-- Resolve each @mixins@ into the actual dependency
100
110
-- from @lib_deps@.
101
111
explicit_includes <- forM (mixins bi) $ \ (Mixin name rns) -> do
102
- let keys@ (_, cname) = fixFakePkgName pkg_decr name
103
- (cid, pid) <-
104
- case Map. lookup keys deps_map of
112
+ let keys = fixFakePkgName pkg_descr name
113
+ aid <- case Map. lookup keys deps_map of
105
114
Nothing ->
106
115
dieProgress $
107
116
text " Mix-in refers to non-existent package" <+>
108
117
quotes (disp name) $$
109
118
text " (did you forget to add the package to build-depends?)"
110
119
Just r -> return r
111
120
return ComponentInclude {
112
- ci_id = cid,
113
- ci_pkgid = pid,
114
- ci_compname = cname,
121
+ ci_ann_id = aid,
115
122
ci_renaming = rns,
116
123
ci_implicit = False
117
124
}
@@ -120,30 +127,32 @@ mkConfiguredComponent pkg_decr this_cid lib_deps exe_deps component = do
120
127
-- @backpack-include@ is converted into an "implicit" include.
121
128
let used_explicitly = Set. fromList (map ci_id explicit_includes)
122
129
implicit_includes
123
- = map (\ ((_, cn), (cid, pid)) -> ComponentInclude {
124
- ci_id = cid,
125
- ci_pkgid = pid,
126
- ci_compname = cn,
127
- ci_renaming = defaultIncludeRenaming,
128
- ci_implicit = True
129
- })
130
- $ filter (flip Set. notMember used_explicitly . fst . snd ) lib_deps
130
+ = map (\ aid -> ComponentInclude {
131
+ ci_ann_id = aid,
132
+ ci_renaming = defaultIncludeRenaming,
133
+ ci_implicit = True
134
+ })
135
+ $ filter (flip Set. notMember used_explicitly . ann_id) lib_deps
131
136
132
137
return ConfiguredComponent {
133
- cc_cid = this_cid,
134
- cc_pkgid = package pkg_decr,
138
+ cc_ann_id = AnnotatedId {
139
+ ann_id = this_cid,
140
+ ann_pid = package pkg_descr,
141
+ ann_cname = componentName component
142
+ },
135
143
cc_component = component,
136
144
cc_public = is_public,
137
145
cc_exe_deps = exe_deps,
138
146
cc_includes = explicit_includes ++ implicit_includes
139
147
}
140
148
where
141
149
bi = componentBuildInfo component
142
- deps_map = Map. fromList lib_deps
150
+ deps_map = Map. fromList [ ((packageName dep, ann_cname dep), dep)
151
+ | dep <- lib_deps ]
143
152
is_public = componentName component == CLibName
144
153
145
154
type ConfiguredComponentMap =
146
- Map PackageName (Map ComponentName (ComponentId , PackageId ))
155
+ Map PackageName (Map ComponentName (AnnotatedId ComponentId ))
147
156
148
157
toConfiguredComponent
149
158
:: PackageDescription
@@ -155,15 +164,15 @@ toConfiguredComponent pkg_descr this_cid dep_map component = do
155
164
lib_deps <-
156
165
if newPackageDepsBehaviour pkg_descr
157
166
then forM (targetBuildDepends bi) $ \ (Dependency name _) -> do
158
- let keys @ (pn, cn) = fixFakePkgName pkg_descr name
167
+ let (pn, cn) = fixFakePkgName pkg_descr name
159
168
value <- case Map. lookup cn =<< Map. lookup pn dep_map of
160
169
Nothing ->
161
170
dieProgress $
162
171
text " Dependency on unbuildable" <+>
163
172
text (showComponentName cn) <+>
164
173
text " from" <+> disp pn
165
174
Just v -> return v
166
- return (keys, value)
175
+ return value
167
176
else return old_style_lib_deps
168
177
mkConfiguredComponent
169
178
pkg_descr this_cid
@@ -177,7 +186,7 @@ toConfiguredComponent pkg_descr this_cid dep_map component = do
177
186
-- this is not supported by old-style deps behavior
178
187
-- because it would imply a cyclic dependency for the
179
188
-- library itself.
180
- old_style_lib_deps = [ ((pn, cn), e)
189
+ old_style_lib_deps = [ e
181
190
| (pn, comp_map) <- Map. toList dep_map
182
191
, pn /= packageName pkg_descr
183
192
, (cn, e) <- Map. toList comp_map
@@ -215,10 +224,11 @@ toConfiguredComponent' use_external_internal_deps flags
215
224
then cc { cc_public = True }
216
225
else cc
217
226
where
227
+ -- TODO: pass component names to it too!
218
228
this_cid = computeComponentId deterministic ipid_flag cid_flag (package pkg_descr)
219
229
(componentName component) (Just (deps, flags))
220
- deps = [ cid | m <- Map. elems dep_map
221
- , (cid, _) <- Map. elems m ]
230
+ deps = [ ann_id aid | m <- Map. elems dep_map
231
+ , aid <- Map. elems m ]
222
232
223
233
extendConfiguredComponentMap
224
234
:: ConfiguredComponent
@@ -227,7 +237,7 @@ extendConfiguredComponentMap
227
237
extendConfiguredComponentMap cc =
228
238
Map. insertWith Map. union
229
239
(pkgName (cc_pkgid cc))
230
- (Map. singleton (cc_name cc) (cc_cid cc, cc_pkgid cc))
240
+ (Map. singleton (cc_name cc) (cc_ann_id cc))
231
241
232
242
-- Compute the 'ComponentId's for a graph of 'Component's. The
233
243
-- list of internal components must be topologically sorted
0 commit comments