@@ -405,6 +405,26 @@ impl<'cfg> Workspace<'cfg> {
405
405
self . custom_metadata . as_ref ( )
406
406
}
407
407
408
+ pub fn load_workspace_config ( & mut self ) -> CargoResult < Option < WorkspaceRootConfig > > {
409
+ // If we didn't find a root, it must mean there is no [workspace] section, and thus no
410
+ // metadata.
411
+ if let Some ( root_path) = & self . root_manifest {
412
+ let root_package = self . packages . load ( root_path) ?;
413
+ match root_package. workspace_config ( ) {
414
+ WorkspaceConfig :: Root ( ref root_config) => {
415
+ return Ok ( Some ( root_config. clone ( ) ) ) ;
416
+ }
417
+
418
+ _ => anyhow:: bail!(
419
+ "root of a workspace inferred but wasn't a root: {}" ,
420
+ root_path. display( )
421
+ ) ,
422
+ }
423
+ }
424
+
425
+ Ok ( None )
426
+ }
427
+
408
428
/// Finds the root of a workspace for the crate whose manifest is located
409
429
/// at `manifest_path`.
410
430
///
@@ -478,25 +498,10 @@ impl<'cfg> Workspace<'cfg> {
478
498
Ok ( None )
479
499
}
480
500
481
- /// After the root of a workspace has been located, loads the `workspace.metadata` table from
482
- /// the workspace root file.
483
- ///
484
- /// If no workspace was defined, then no changes occur.
485
- fn load_workspace_metadata ( & mut self ) -> CargoResult < ( ) > {
486
- // If we didn't find a root, it must mean there is no [workspace] section, and thus no
487
- // metadata.
488
- if let Some ( root_path) = & self . root_manifest {
489
- let root_package = self . packages . load ( root_path) ?;
490
- match root_package. workspace_config ( ) {
491
- WorkspaceConfig :: Root ( ref root_config) => {
492
- self . custom_metadata = root_config. custom_metadata . clone ( ) ;
493
- }
494
-
495
- _ => anyhow:: bail!(
496
- "root of a workspace inferred but wasn't a root: {}" ,
497
- root_path. display( )
498
- ) ,
499
- }
501
+ /// After the root of a workspace has been located, sets the custom_metadata, if it exists.
502
+ pub fn load_workspace_metadata ( & mut self ) -> CargoResult < ( ) > {
503
+ if let Some ( workspace_config) = self . load_workspace_config ( ) ? {
504
+ self . custom_metadata = workspace_config. custom_metadata ;
500
505
}
501
506
502
507
Ok ( ( ) )
@@ -510,8 +515,8 @@ impl<'cfg> Workspace<'cfg> {
510
515
/// will transitively follow all `path` dependencies looking for members of
511
516
/// the workspace.
512
517
fn find_members ( & mut self ) -> CargoResult < ( ) > {
513
- let root_manifest_path = match self . root_manifest {
514
- Some ( ref path ) => path . clone ( ) ,
518
+ let workspace_config = match self . load_workspace_config ( ) ? {
519
+ Some ( workspace_config ) => workspace_config ,
515
520
None => {
516
521
debug ! ( "find_members - only me as a member" ) ;
517
522
self . members . push ( self . current_manifest . clone ( ) ) ;
@@ -524,30 +529,20 @@ impl<'cfg> Workspace<'cfg> {
524
529
}
525
530
} ;
526
531
527
- let members_paths;
528
- let default_members_paths;
529
- {
530
- let root_package = self . packages . load ( & root_manifest_path) ?;
531
- match * root_package. workspace_config ( ) {
532
- WorkspaceConfig :: Root ( ref root_config) => {
533
- members_paths = root_config
534
- . members_paths ( root_config. members . as_ref ( ) . unwrap_or ( & vec ! [ ] ) ) ?;
535
- default_members_paths = if root_manifest_path == self . current_manifest {
536
- if let Some ( ref default) = root_config. default_members {
537
- Some ( root_config. members_paths ( default) ?)
538
- } else {
539
- None
540
- }
541
- } else {
542
- None
543
- } ;
544
- }
545
- _ => anyhow:: bail!(
546
- "root of a workspace inferred but wasn't a root: {}" ,
547
- root_manifest_path. display( )
548
- ) ,
532
+ // self.root_manifest must be Some to have retrieved workspace_config
533
+ let root_manifest_path = self . root_manifest . clone ( ) . unwrap ( ) ;
534
+
535
+ let members_paths =
536
+ workspace_config. members_paths ( workspace_config. members . as_ref ( ) . unwrap_or ( & vec ! [ ] ) ) ?;
537
+ let default_members_paths = if root_manifest_path == self . current_manifest {
538
+ if let Some ( ref default) = workspace_config. default_members {
539
+ Some ( workspace_config. members_paths ( default) ?)
540
+ } else {
541
+ None
549
542
}
550
- }
543
+ } else {
544
+ None
545
+ } ;
551
546
552
547
for path in members_paths {
553
548
self . find_path_deps ( & path. join ( "Cargo.toml" ) , & root_manifest_path, false ) ?;
0 commit comments