@@ -46,6 +46,18 @@ pub struct Workspace<'cfg> {
46
46
// set above.
47
47
members : Vec < PathBuf > ,
48
48
49
+ // The subset of `members` that are used by the
50
+ // `build`, `check`, `test`, and `bench` subcommands
51
+ // when no package is selected with `--package` / `-p` and `--all`
52
+ // is not used.
53
+ //
54
+ // This is set by the `default-members` config
55
+ // in the `[workspace]` section.
56
+ // When unset, this is the same as `members` for virtual workspaces
57
+ // (`--all` is implied)
58
+ // or only the root package for non-virtual workspaces.
59
+ default_members : Vec < PathBuf > ,
60
+
49
61
// True, if this is a temporary workspace created for the purposes of
50
62
// cargo install or cargo package.
51
63
is_ephemeral : bool ,
@@ -90,6 +102,7 @@ pub enum WorkspaceConfig {
90
102
pub struct WorkspaceRootConfig {
91
103
root_dir : PathBuf ,
92
104
members : Option < Vec < String > > ,
105
+ default_members : Option < Vec < String > > ,
93
106
exclude : Vec < String > ,
94
107
}
95
108
@@ -121,6 +134,7 @@ impl<'cfg> Workspace<'cfg> {
121
134
root_manifest : None ,
122
135
target_dir : target_dir,
123
136
members : Vec :: new ( ) ,
137
+ default_members : Vec :: new ( ) ,
124
138
is_ephemeral : false ,
125
139
require_optional_deps : true ,
126
140
} ;
@@ -157,6 +171,7 @@ impl<'cfg> Workspace<'cfg> {
157
171
root_manifest : None ,
158
172
target_dir : None ,
159
173
members : Vec :: new ( ) ,
174
+ default_members : Vec :: new ( ) ,
160
175
is_ephemeral : true ,
161
176
require_optional_deps : require_optional_deps,
162
177
} ;
@@ -170,6 +185,7 @@ impl<'cfg> Workspace<'cfg> {
170
185
ws. config . target_dir ( ) ?
171
186
} ;
172
187
ws. members . push ( ws. current_manifest . clone ( ) ) ;
188
+ ws. default_members . push ( ws. current_manifest . clone ( ) ) ;
173
189
}
174
190
Ok ( ws)
175
191
}
@@ -267,6 +283,14 @@ impl<'cfg> Workspace<'cfg> {
267
283
}
268
284
}
269
285
286
+ /// Returns an iterator over default packages in this workspace
287
+ pub fn default_members < ' a > ( & ' a self ) -> Members < ' a , ' cfg > {
288
+ Members {
289
+ ws : self ,
290
+ iter : self . default_members . iter ( ) ,
291
+ }
292
+ }
293
+
270
294
pub fn is_ephemeral ( & self ) -> bool {
271
295
self . is_ephemeral
272
296
}
@@ -345,23 +369,51 @@ impl<'cfg> Workspace<'cfg> {
345
369
None => {
346
370
debug ! ( "find_members - only me as a member" ) ;
347
371
self . members . push ( self . current_manifest . clone ( ) ) ;
372
+ self . default_members . push ( self . current_manifest . clone ( ) ) ;
348
373
return Ok ( ( ) )
349
374
}
350
375
} ;
351
376
352
- let members_paths = {
377
+ let members_paths;
378
+ let default_members_paths;
379
+ {
353
380
let root_package = self . packages . load ( & root_manifest_path) ?;
354
381
match * root_package. workspace_config ( ) {
355
- WorkspaceConfig :: Root ( ref root_config) => root_config. members_paths ( ) ?,
382
+ WorkspaceConfig :: Root ( ref root_config) => {
383
+ members_paths = root_config. members_paths (
384
+ root_config. members . as_ref ( ) . unwrap_or ( & vec ! [ ] )
385
+ ) ?;
386
+ default_members_paths = if let Some ( ref default) = root_config. default_members {
387
+ Some ( root_config. members_paths ( default) ?)
388
+ } else {
389
+ None
390
+ }
391
+ }
356
392
_ => bail ! ( "root of a workspace inferred but wasn't a root: {}" ,
357
393
root_manifest_path. display( ) ) ,
358
394
}
359
- } ;
395
+ }
360
396
361
397
for path in members_paths {
362
398
self . find_path_deps ( & path. join ( "Cargo.toml" ) , & root_manifest_path, false ) ?;
363
399
}
364
400
401
+ if let Some ( default) = default_members_paths {
402
+ for path in default {
403
+ let manifest_path = paths:: normalize_path ( & path. join ( "Cargo.toml" ) ) ;
404
+ if !self . members . contains ( & manifest_path) {
405
+ bail ! ( "package `{}` is listed in workspace’s default-members \
406
+ but is not a member.",
407
+ path. display( ) )
408
+ }
409
+ self . default_members . push ( manifest_path)
410
+ }
411
+ } else if self . is_virtual ( ) {
412
+ self . default_members = self . members . clone ( )
413
+ } else {
414
+ self . default_members . push ( self . current_manifest . clone ( ) )
415
+ }
416
+
365
417
self . find_path_deps ( & root_manifest_path, & root_manifest_path, false )
366
418
}
367
419
@@ -370,7 +422,7 @@ impl<'cfg> Workspace<'cfg> {
370
422
root_manifest : & Path ,
371
423
is_path_dep : bool ) -> CargoResult < ( ) > {
372
424
let manifest_path = paths:: normalize_path ( manifest_path) ;
373
- if self . members . iter ( ) . any ( |p| p == & manifest_path) {
425
+ if self . members . contains ( & manifest_path) {
374
426
return Ok ( ( ) )
375
427
}
376
428
if is_path_dep
@@ -632,11 +684,13 @@ impl WorkspaceRootConfig {
632
684
pub fn new (
633
685
root_dir : & Path ,
634
686
members : & Option < Vec < String > > ,
687
+ default_members : & Option < Vec < String > > ,
635
688
exclude : & Option < Vec < String > > ,
636
689
) -> WorkspaceRootConfig {
637
690
WorkspaceRootConfig {
638
691
root_dir : root_dir. to_path_buf ( ) ,
639
692
members : members. clone ( ) ,
693
+ default_members : default_members. clone ( ) ,
640
694
exclude : exclude. clone ( ) . unwrap_or_default ( ) ,
641
695
}
642
696
}
@@ -665,21 +719,19 @@ impl WorkspaceRootConfig {
665
719
self . members . is_some ( )
666
720
}
667
721
668
- fn members_paths ( & self ) -> CargoResult < Vec < PathBuf > > {
722
+ fn members_paths ( & self , globs : & [ String ] ) -> CargoResult < Vec < PathBuf > > {
669
723
let mut expanded_list = Vec :: new ( ) ;
670
724
671
- if let Some ( globs) = self . members . clone ( ) {
672
- for glob in globs {
673
- let pathbuf = self . root_dir . join ( glob) ;
674
- let expanded_paths = Self :: expand_member_path ( & pathbuf) ?;
675
-
676
- // If glob does not find any valid paths, then put the original
677
- // path in the expanded list to maintain backwards compatibility.
678
- if expanded_paths. is_empty ( ) {
679
- expanded_list. push ( pathbuf) ;
680
- } else {
681
- expanded_list. extend ( expanded_paths) ;
682
- }
725
+ for glob in globs {
726
+ let pathbuf = self . root_dir . join ( glob) ;
727
+ let expanded_paths = Self :: expand_member_path ( & pathbuf) ?;
728
+
729
+ // If glob does not find any valid paths, then put the original
730
+ // path in the expanded list to maintain backwards compatibility.
731
+ if expanded_paths. is_empty ( ) {
732
+ expanded_list. push ( pathbuf) ;
733
+ } else {
734
+ expanded_list. extend ( expanded_paths) ;
683
735
}
684
736
}
685
737
0 commit comments