File tree 1 file changed +32
-13
lines changed 1 file changed +32
-13
lines changed Original file line number Diff line number Diff line change @@ -314,29 +314,48 @@ fn find_unique_target(
314
314
} ) ;
315
315
}
316
316
317
+ let mut num_packages = 0 ;
318
+ let mut is_default = false ;
319
+
317
320
let mut targets: Vec < _ > = packages
318
321
. flat_map ( |p| {
319
- let Package { targets, name, .. } = p;
322
+ let Package {
323
+ targets,
324
+ name,
325
+ default_run,
326
+ ..
327
+ } = p;
328
+ num_packages += 1 ;
329
+ if default_run. is_some ( ) {
330
+ is_default = true ;
331
+ }
320
332
targets. into_iter ( ) . filter_map ( move |t| {
321
- t. kind
322
- . iter ( )
323
- . any ( |s| kind. contains ( & s. as_str ( ) ) )
324
- . then ( || BinaryTarget {
325
- package : name. clone ( ) ,
326
- target : t. name ,
327
- kind : t. kind ,
328
- } )
333
+ // Keep only targets that are of the right kind.
334
+ let ok_kind = t. kind . iter ( ) . any ( |s| kind. contains ( & s. as_str ( ) ) ) ;
335
+ // When `default_run` is set, keep only the target with that name.
336
+ let default_filter = match & default_run {
337
+ None => true ,
338
+ Some ( default_name) => & t. name == default_name,
339
+ } ;
340
+ ( ok_kind && default_filter) . then ( || BinaryTarget {
341
+ package : name. clone ( ) ,
342
+ target : t. name ,
343
+ kind : t. kind ,
344
+ } )
329
345
} )
330
346
} )
331
347
. collect ( ) ;
332
348
333
349
match targets. as_slice ( ) {
334
350
[ _] => {
335
351
let target = targets. remove ( 0 ) ;
336
- eprintln ! (
337
- "automatically selected {} as it is the only valid target" ,
338
- target
339
- ) ;
352
+ // If the selected target is the default_run of the only package, do not print a message.
353
+ if num_packages != 1 || !is_default {
354
+ eprintln ! (
355
+ "automatically selected {} as it is the only valid target" ,
356
+ target
357
+ ) ;
358
+ }
340
359
Ok ( target)
341
360
}
342
361
[ ] => Err ( anyhow ! (
You can’t perform that action at this time.
0 commit comments