Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/project-model/src/cargo_workspace.rs')
| -rw-r--r-- | crates/project-model/src/cargo_workspace.rs | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/crates/project-model/src/cargo_workspace.rs b/crates/project-model/src/cargo_workspace.rs index cb5738a3b4..4ae3426ed9 100644 --- a/crates/project-model/src/cargo_workspace.rs +++ b/crates/project-model/src/cargo_workspace.rs @@ -33,6 +33,7 @@ pub struct CargoWorkspace { workspace_root: AbsPathBuf, target_directory: AbsPathBuf, manifest_path: ManifestPath, + is_virtual_workspace: bool, } impl ops::Index<Package> for CargoWorkspace { @@ -384,13 +385,20 @@ impl CargoWorkspace { .with_context(|| format!("Failed to run `{:?}`", meta.cargo_command())) } - pub fn new(mut meta: cargo_metadata::Metadata, manifest_path: ManifestPath) -> CargoWorkspace { + pub fn new( + mut meta: cargo_metadata::Metadata, + ws_manifest_path: ManifestPath, + ) -> CargoWorkspace { let mut pkg_by_id = FxHashMap::default(); let mut packages = Arena::default(); let mut targets = Arena::default(); let ws_members = &meta.workspace_members; + let workspace_root = AbsPathBuf::assert(meta.workspace_root); + let target_directory = AbsPathBuf::assert(meta.target_directory); + let mut is_virtual_workspace = true; + meta.packages.sort_by(|a, b| a.id.cmp(&b.id)); for meta_pkg in meta.packages { let cargo_metadata::Package { @@ -429,12 +437,13 @@ impl CargoWorkspace { let is_local = source.is_none(); let is_member = ws_members.contains(&id); - let manifest = AbsPathBuf::assert(manifest_path); + let manifest = ManifestPath::try_from(AbsPathBuf::assert(manifest_path)).unwrap(); + is_virtual_workspace &= manifest != ws_manifest_path; let pkg = packages.alloc(PackageData { id: id.repr.clone(), name, version, - manifest: manifest.clone().try_into().unwrap(), + manifest: manifest.clone(), targets: Vec::new(), is_local, is_member, @@ -468,7 +477,7 @@ impl CargoWorkspace { // modified manifest file into a special target dir which is then used as // the source path. We don't want that, we want the original here so map it // back - manifest.clone() + manifest.clone().into() } else { AbsPathBuf::assert(src_path) }, @@ -493,11 +502,14 @@ impl CargoWorkspace { packages[source].active_features.extend(node.features); } - let workspace_root = AbsPathBuf::assert(meta.workspace_root); - - let target_directory = AbsPathBuf::assert(meta.target_directory); - - CargoWorkspace { packages, targets, workspace_root, target_directory, manifest_path } + CargoWorkspace { + packages, + targets, + workspace_root, + target_directory, + manifest_path: ws_manifest_path, + is_virtual_workspace, + } } pub fn packages(&self) -> impl ExactSizeIterator<Item = Package> + '_ { @@ -579,6 +591,10 @@ impl CargoWorkspace { fn is_unique(&self, name: &str) -> bool { self.packages.iter().filter(|(_, v)| v.name == name).count() == 1 } + + pub fn is_virtual_workspace(&self) -> bool { + self.is_virtual_workspace + } } fn find_list_of_build_targets( |