aboutsummaryrefslogtreecommitdiff
path: root/crates/project_model/src/cargo_workspace.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-12-31 13:04:29 +0000
committerGitHub <[email protected]>2020-12-31 13:04:29 +0000
commitfda022592ba9c773039037af12294821d772f2b1 (patch)
tree208ae5e739173de50c3b809698e3156f14ef6235 /crates/project_model/src/cargo_workspace.rs
parent53e2cdf18e155ad61262fed5dcd3d73ef343c042 (diff)
parent27a0fd23d8a9d99867d16b19b597bc6ba9d24748 (diff)
Merge #7107
7107: add working dir to cargo metadata fail messages r=matklad a=lf- Context: I was having an error in my workspace config that I couldn't figure out without this added output. In particular, I have a Code workspace with a docs folder and one of my top level crates [which each have their own custom target], which was picking up the Cargo workspace level Cargo.toml incorrectly [which in my project should not ever be used for the editor], and ultimately had to override it with `linkedProjects`. Here's a sample of the changed output: ``` [INFO rust_analyzer::main_loop] handle_event(Workspaces([Err(Failed to read Cargo metadata from Cargo.toml file /home/jade/dev/mu/Cargo.toml, cargo 1.50.0-nightly (75d5d8cff 2020-12-22) Caused by: 0: Failed to run `cargo metadata --manifest-path /home/jade/dev/mu/Cargo.toml` in `/home/jade/dev/mu` 1: Error during execution of `cargo metadata`: error: target path "../../riscv64imac-mu-shoo-elf.json" is not a valid file Caused by: No such file or directory (os error 2) ), Err(Failed to read Cargo metadata from Cargo.toml file /home/jade/dev/mu/shoo/Cargo.toml, cargo 1.50.0-nightly (75d5d8cff 2020-12-22) Caused by: 0: Failed to run `cargo metadata --manifest-path /home/jade/dev/mu/shoo/Cargo.toml` in `/home/jade/dev/mu/shoo` 1: Error during execution of `cargo metadata`: error: target path "../../riscv64imac-mu-shoo-elf.json" is not a valid file Caused by: No such file or directory (os error 2) )])) ``` Co-authored-by: lf- <[email protected]>
Diffstat (limited to 'crates/project_model/src/cargo_workspace.rs')
-rw-r--r--crates/project_model/src/cargo_workspace.rs18
1 files changed, 17 insertions, 1 deletions
diff --git a/crates/project_model/src/cargo_workspace.rs b/crates/project_model/src/cargo_workspace.rs
index bb3b6f2ef..b991b59a6 100644
--- a/crates/project_model/src/cargo_workspace.rs
+++ b/crates/project_model/src/cargo_workspace.rs
@@ -1,6 +1,7 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use std::{ 3use std::{
4 convert::TryInto,
4 ffi::OsStr, 5 ffi::OsStr,
5 ops, 6 ops,
6 path::{Path, PathBuf}, 7 path::{Path, PathBuf},
@@ -196,8 +197,23 @@ impl CargoWorkspace {
196 if let Some(target) = target { 197 if let Some(target) = target {
197 meta.other_options(vec![String::from("--filter-platform"), target]); 198 meta.other_options(vec![String::from("--filter-platform"), target]);
198 } 199 }
200
199 let mut meta = meta.exec().with_context(|| { 201 let mut meta = meta.exec().with_context(|| {
200 format!("Failed to run `cargo metadata --manifest-path {}`", cargo_toml.display()) 202 let cwd: Option<AbsPathBuf> =
203 std::env::current_dir().ok().and_then(|p| p.try_into().ok());
204
205 let workdir = cargo_toml
206 .parent()
207 .map(|p| p.to_path_buf())
208 .or(cwd)
209 .map(|dir| dir.to_string_lossy().to_string())
210 .unwrap_or_else(|| "<failed to get path>".into());
211
212 format!(
213 "Failed to run `cargo metadata --manifest-path {}` in `{}`",
214 cargo_toml.display(),
215 workdir
216 )
201 })?; 217 })?;
202 218
203 let mut out_dir_by_id = FxHashMap::default(); 219 let mut out_dir_by_id = FxHashMap::default();