@@ -129,16 +129,11 @@ parseRawTargetDirs root locals t =
129
129
then Just name
130
130
else Nothing
131
131
132
- data TargetType
133
- = TTUnknown
134
- | TTNonLocal
135
- | TTLocalComp ! NamedComponent
136
- | TTLocalAllComps ! (Set NamedComponent )
137
-
138
132
data SimpleTarget
139
133
= STUnknown
140
134
| STNonLocal
141
- | STLocal ! (Set NamedComponent )
135
+ | STLocalComps ! (Set NamedComponent )
136
+ | STLocalAll
142
137
deriving (Show , Eq , Ord )
143
138
144
139
resolveIdents :: Map PackageName Version -- ^ snapshot
@@ -180,7 +175,7 @@ resolveRawTarget :: Map PackageName Version -- ^ snapshot
180
175
-> Map PackageName Version -- ^ extra deps
181
176
-> Map PackageName LocalPackageView
182
177
-> (RawInput , RawTarget NoIdents )
183
- -> Either Text (PackageName , (RawInput , TargetType ))
178
+ -> Either Text (PackageName , (RawInput , SimpleTarget ))
184
179
resolveRawTarget snap extras locals (ri, rt) =
185
180
go rt
186
181
where
@@ -191,7 +186,7 @@ resolveRawTarget snap extras locals (ri, rt) =
191
186
case ucomp of
192
187
ResolvedComponent comp
193
188
| comp `Set.member` lpvComponents lpv ->
194
- Right (name, (ri, TTLocalComp comp))
189
+ Right (name, (ri, STLocalComps $ Set. singleton comp))
195
190
| otherwise -> Left $ T. pack $ concat
196
191
[ " Component "
197
192
, show comp
@@ -206,7 +201,7 @@ resolveRawTarget snap extras locals (ri, rt) =
206
201
, " does not exist in package "
207
202
, T. pack $ packageNameString name
208
203
]
209
- [x] -> Right (name, (ri, TTLocalComp x))
204
+ [x] -> Right (name, (ri, STLocalComps $ Set. singleton x))
210
205
matches -> Left $ T. concat
211
206
[ " Ambiguous component name "
212
207
, comp
@@ -222,7 +217,7 @@ resolveRawTarget snap extras locals (ri, rt) =
222
217
in case filter (isCompNamed cname . snd ) allPairs of
223
218
[] -> Left $ " Could not find a component named " `T.append` cname
224
219
[(name, comp)] ->
225
- Right (name, (ri, TTLocalComp comp))
220
+ Right (name, (ri, STLocalComps $ Set. singleton comp))
226
221
matches -> Left $ T. concat
227
222
[ " Ambiugous component name "
228
223
, cname
@@ -232,41 +227,33 @@ resolveRawTarget snap extras locals (ri, rt) =
232
227
233
228
go (RTPackage name) =
234
229
case Map. lookup name locals of
235
- Just lpv -> Right (name, (ri, TTLocalAllComps $ lpvComponents lpv ))
230
+ Just _lpv -> Right (name, (ri, STLocalAll ))
236
231
Nothing ->
237
232
case Map. lookup name extras of
238
- Just _ -> Right (name, (ri, TTNonLocal ))
233
+ Just _ -> Right (name, (ri, STNonLocal ))
239
234
Nothing ->
240
235
case Map. lookup name snap of
241
- Just _ -> Right (name, (ri, TTNonLocal ))
242
- Nothing -> Right (name, (ri, TTUnknown ))
236
+ Just _ -> Right (name, (ri, STNonLocal ))
237
+ Nothing -> Right (name, (ri, STUnknown ))
243
238
244
239
isCompNamed :: Text -> NamedComponent -> Bool
245
240
isCompNamed _ CLib = False
246
241
isCompNamed t1 (CExe t2) = t1 == t2
247
242
isCompNamed t1 (CTest t2) = t1 == t2
248
243
isCompNamed t1 (CBench t2) = t1 == t2
249
244
250
- simplifyTargets :: Bool -- ^ include tests
251
- -> Bool -- ^ include benchmarks
252
- -> [(PackageName , (RawInput , TargetType ))]
245
+ simplifyTargets :: [(PackageName , (RawInput , SimpleTarget ))]
253
246
-> ([Text ], Map PackageName SimpleTarget )
254
- simplifyTargets includeTests includeBenches =
247
+ simplifyTargets =
255
248
mconcat . map go . Map. toList . Map. fromListWith (++) . fmap (second return )
256
249
where
257
- go :: (PackageName , [(RawInput , TargetType )])
250
+ go :: (PackageName , [(RawInput , SimpleTarget )])
258
251
-> ([Text ], Map PackageName SimpleTarget )
259
252
go (_, [] ) = error " Stack.Build.Target.simplifyTargets: the impossible happened"
260
- go (name, [(_, tt)]) = ([] , Map. singleton name $
261
- case tt of
262
- TTUnknown -> STUnknown
263
- TTNonLocal -> STNonLocal
264
- TTLocalComp comp -> STLocal $ Set. singleton comp
265
- TTLocalAllComps comps -> STLocal $ Set. filter keepComp comps
266
- )
253
+ go (name, [(_, st)]) = ([] , Map. singleton name st)
267
254
go (name, pairs) =
268
255
case partitionEithers $ map (getLocalComp . snd ) pairs of
269
- ([] , comps) -> ([] , Map. singleton name $ STLocal $ Set. fromList comps)
256
+ ([] , comps) -> ([] , Map. singleton name $ STLocalComps $ Set. unions comps)
270
257
_ ->
271
258
let err = T. pack $ concat
272
259
[ " Overlapping targets provided for package "
@@ -276,25 +263,18 @@ simplifyTargets includeTests includeBenches =
276
263
]
277
264
in ([err], Map. empty)
278
265
279
- keepComp CLib = True
280
- keepComp (CExe _) = True
281
- keepComp (CTest _) = includeTests
282
- keepComp (CBench _) = includeBenches
283
-
284
- getLocalComp (TTLocalComp comp) = Right comp
266
+ getLocalComp (STLocalComps comps) = Right comps
285
267
getLocalComp _ = Left ()
286
268
287
269
parseTargets :: (MonadThrow m , MonadIO m )
288
270
=> Bool -- ^ using implicit global?
289
- -> Bool -- ^ include tests
290
- -> Bool -- ^ include benchmarks
291
271
-> Map PackageName Version -- ^ snapshot
292
272
-> Map PackageName Version -- ^ extra deps
293
273
-> Map PackageName LocalPackageView
294
274
-> Path Abs Dir -- ^ current directory
295
275
-> [Text ] -- ^ command line targets
296
276
-> m (Map PackageName Version , Map PackageName SimpleTarget )
297
- parseTargets implicitGlobal includeTests includeBenches snap extras locals currDir textTargets' = do
277
+ parseTargets implicitGlobal snap extras locals currDir textTargets' = do
298
278
let textTargets =
299
279
if null textTargets'
300
280
then map (T. pack . packageNameString) $ Map. keys $ Map. filter (not . lpvExtraDep) locals
@@ -306,7 +286,7 @@ parseTargets implicitGlobal includeTests includeBenches snap extras locals currD
306
286
map (resolveIdents snap extras locals) $ concat rawTargets
307
287
(errs3, targetTypes) = partitionEithers $
308
288
map (resolveRawTarget snap extras locals) rawTargets'
309
- (errs4, targets) = simplifyTargets includeTests includeBenches targetTypes
289
+ (errs4, targets) = simplifyTargets targetTypes
310
290
errs = concat [errs1, errs2, errs3, errs4]
311
291
312
292
if null errs
0 commit comments