@@ -33,6 +33,7 @@ pub struct CargoWorkspace {
3333 workspace_root : AbsPathBuf ,
3434 target_directory : AbsPathBuf ,
3535 manifest_path : ManifestPath ,
36+ is_virtual_workspace : bool ,
3637}
3738
3839impl ops:: Index < Package > for CargoWorkspace {
@@ -384,13 +385,20 @@ impl CargoWorkspace {
384385 . with_context ( || format ! ( "Failed to run `{:?}`" , meta. cargo_command( ) ) )
385386 }
386387
387- pub fn new ( mut meta : cargo_metadata:: Metadata , manifest_path : ManifestPath ) -> CargoWorkspace {
388+ pub fn new (
389+ mut meta : cargo_metadata:: Metadata ,
390+ ws_manifest_path : ManifestPath ,
391+ ) -> CargoWorkspace {
388392 let mut pkg_by_id = FxHashMap :: default ( ) ;
389393 let mut packages = Arena :: default ( ) ;
390394 let mut targets = Arena :: default ( ) ;
391395
392396 let ws_members = & meta. workspace_members ;
393397
398+ let workspace_root = AbsPathBuf :: assert ( meta. workspace_root ) ;
399+ let target_directory = AbsPathBuf :: assert ( meta. target_directory ) ;
400+ let mut is_virtual_workspace = true ;
401+
394402 meta. packages . sort_by ( |a, b| a. id . cmp ( & b. id ) ) ;
395403 for meta_pkg in meta. packages {
396404 let cargo_metadata:: Package {
@@ -429,12 +437,13 @@ impl CargoWorkspace {
429437 let is_local = source. is_none ( ) ;
430438 let is_member = ws_members. contains ( & id) ;
431439
432- let manifest = AbsPathBuf :: assert ( manifest_path) ;
440+ let manifest = ManifestPath :: try_from ( AbsPathBuf :: assert ( manifest_path) ) . unwrap ( ) ;
441+ is_virtual_workspace &= manifest != ws_manifest_path;
433442 let pkg = packages. alloc ( PackageData {
434443 id : id. repr . clone ( ) ,
435444 name,
436445 version,
437- manifest : manifest. clone ( ) . try_into ( ) . unwrap ( ) ,
446+ manifest : manifest. clone ( ) ,
438447 targets : Vec :: new ( ) ,
439448 is_local,
440449 is_member,
@@ -468,7 +477,7 @@ impl CargoWorkspace {
468477 // modified manifest file into a special target dir which is then used as
469478 // the source path. We don't want that, we want the original here so map it
470479 // back
471- manifest. clone ( )
480+ manifest. clone ( ) . into ( )
472481 } else {
473482 AbsPathBuf :: assert ( src_path)
474483 } ,
@@ -493,11 +502,14 @@ impl CargoWorkspace {
493502 packages[ source] . active_features . extend ( node. features ) ;
494503 }
495504
496- let workspace_root = AbsPathBuf :: assert ( meta. workspace_root ) ;
497-
498- let target_directory = AbsPathBuf :: assert ( meta. target_directory ) ;
499-
500- CargoWorkspace { packages, targets, workspace_root, target_directory, manifest_path }
505+ CargoWorkspace {
506+ packages,
507+ targets,
508+ workspace_root,
509+ target_directory,
510+ manifest_path : ws_manifest_path,
511+ is_virtual_workspace,
512+ }
501513 }
502514
503515 pub fn packages ( & self ) -> impl ExactSizeIterator < Item = Package > + ' _ {
@@ -579,6 +591,10 @@ impl CargoWorkspace {
579591 fn is_unique ( & self , name : & str ) -> bool {
580592 self . packages . iter ( ) . filter ( |( _, v) | v. name == name) . count ( ) == 1
581593 }
594+
595+ pub fn is_virtual_workspace ( & self ) -> bool {
596+ self . is_virtual_workspace
597+ }
582598}
583599
584600fn find_list_of_build_targets (
0 commit comments