@@ -33,6 +33,7 @@ pub struct CargoWorkspace {
33
33
workspace_root : AbsPathBuf ,
34
34
target_directory : AbsPathBuf ,
35
35
manifest_path : ManifestPath ,
36
+ is_virtual_workspace : bool ,
36
37
}
37
38
38
39
impl ops:: Index < Package > for CargoWorkspace {
@@ -384,13 +385,20 @@ impl CargoWorkspace {
384
385
. with_context ( || format ! ( "Failed to run `{:?}`" , meta. cargo_command( ) ) )
385
386
}
386
387
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 {
388
392
let mut pkg_by_id = FxHashMap :: default ( ) ;
389
393
let mut packages = Arena :: default ( ) ;
390
394
let mut targets = Arena :: default ( ) ;
391
395
392
396
let ws_members = & meta. workspace_members ;
393
397
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
+
394
402
meta. packages . sort_by ( |a, b| a. id . cmp ( & b. id ) ) ;
395
403
for meta_pkg in meta. packages {
396
404
let cargo_metadata:: Package {
@@ -429,12 +437,13 @@ impl CargoWorkspace {
429
437
let is_local = source. is_none ( ) ;
430
438
let is_member = ws_members. contains ( & id) ;
431
439
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;
433
442
let pkg = packages. alloc ( PackageData {
434
443
id : id. repr . clone ( ) ,
435
444
name,
436
445
version,
437
- manifest : manifest. clone ( ) . try_into ( ) . unwrap ( ) ,
446
+ manifest : manifest. clone ( ) ,
438
447
targets : Vec :: new ( ) ,
439
448
is_local,
440
449
is_member,
@@ -468,7 +477,7 @@ impl CargoWorkspace {
468
477
// modified manifest file into a special target dir which is then used as
469
478
// the source path. We don't want that, we want the original here so map it
470
479
// back
471
- manifest. clone ( )
480
+ manifest. clone ( ) . into ( )
472
481
} else {
473
482
AbsPathBuf :: assert ( src_path)
474
483
} ,
@@ -493,11 +502,14 @@ impl CargoWorkspace {
493
502
packages[ source] . active_features . extend ( node. features ) ;
494
503
}
495
504
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
+ }
501
513
}
502
514
503
515
pub fn packages ( & self ) -> impl ExactSizeIterator < Item = Package > + ' _ {
@@ -579,6 +591,10 @@ impl CargoWorkspace {
579
591
fn is_unique ( & self , name : & str ) -> bool {
580
592
self . packages . iter ( ) . filter ( |( _, v) | v. name == name) . count ( ) == 1
581
593
}
594
+
595
+ pub fn is_virtual_workspace ( & self ) -> bool {
596
+ self . is_virtual_workspace
597
+ }
582
598
}
583
599
584
600
fn find_list_of_build_targets (
0 commit comments