mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-03 13:23:25 +00:00
Merge pull request #20069 from Veykril/push-mnqkqxomtlxn
Some checks are pending
metrics / build_metrics (push) Waiting to run
metrics / other_metrics (diesel-1.4.8) (push) Blocked by required conditions
metrics / other_metrics (hyper-0.14.18) (push) Blocked by required conditions
metrics / other_metrics (ripgrep-13.0.0) (push) Blocked by required conditions
metrics / other_metrics (self) (push) Blocked by required conditions
metrics / other_metrics (webrender-2022) (push) Blocked by required conditions
metrics / generate_final_metrics (push) Blocked by required conditions
rustdoc / rustdoc (push) Waiting to run
Some checks are pending
metrics / build_metrics (push) Waiting to run
metrics / other_metrics (diesel-1.4.8) (push) Blocked by required conditions
metrics / other_metrics (hyper-0.14.18) (push) Blocked by required conditions
metrics / other_metrics (ripgrep-13.0.0) (push) Blocked by required conditions
metrics / other_metrics (self) (push) Blocked by required conditions
metrics / other_metrics (webrender-2022) (push) Blocked by required conditions
metrics / generate_final_metrics (push) Blocked by required conditions
rustdoc / rustdoc (push) Waiting to run
fix: Fix cargo project manifest not pointing to the workspace root
This commit is contained in:
commit
ab9e7bdc83
1 changed files with 29 additions and 1 deletions
|
|
@ -16,6 +16,7 @@ use paths::{AbsPath, AbsPathBuf, Utf8PathBuf};
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
use span::{Edition, FileId};
|
use span::{Edition, FileId};
|
||||||
|
use toolchain::Tool;
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
use triomphe::Arc;
|
use triomphe::Arc;
|
||||||
|
|
||||||
|
|
@ -29,6 +30,7 @@ use crate::{
|
||||||
project_json::{Crate, CrateArrayIdx},
|
project_json::{Crate, CrateArrayIdx},
|
||||||
sysroot::RustLibSrcWorkspace,
|
sysroot::RustLibSrcWorkspace,
|
||||||
toolchain_info::{QueryConfig, rustc_cfg, target_data_layout, target_tuple, version},
|
toolchain_info::{QueryConfig, rustc_cfg, target_data_layout, target_tuple, version},
|
||||||
|
utf8_stdout,
|
||||||
};
|
};
|
||||||
use tracing::{debug, error, info};
|
use tracing::{debug, error, info};
|
||||||
|
|
||||||
|
|
@ -209,7 +211,7 @@ impl ProjectWorkspace {
|
||||||
progress: &(dyn Fn(String) + Sync),
|
progress: &(dyn Fn(String) + Sync),
|
||||||
) -> Result<ProjectWorkspace, anyhow::Error> {
|
) -> Result<ProjectWorkspace, anyhow::Error> {
|
||||||
progress("Discovering sysroot".to_owned());
|
progress("Discovering sysroot".to_owned());
|
||||||
let workspace_dir = cargo_toml.parent();
|
|
||||||
let CargoConfig {
|
let CargoConfig {
|
||||||
features,
|
features,
|
||||||
rustc_source,
|
rustc_source,
|
||||||
|
|
@ -224,6 +226,7 @@ impl ProjectWorkspace {
|
||||||
no_deps,
|
no_deps,
|
||||||
..
|
..
|
||||||
} = config;
|
} = config;
|
||||||
|
let workspace_dir = cargo_toml.parent();
|
||||||
let mut sysroot = match (sysroot, sysroot_src) {
|
let mut sysroot = match (sysroot, sysroot_src) {
|
||||||
(Some(RustLibSource::Discover), None) => Sysroot::discover(workspace_dir, extra_env),
|
(Some(RustLibSource::Discover), None) => Sysroot::discover(workspace_dir, extra_env),
|
||||||
(Some(RustLibSource::Discover), Some(sysroot_src)) => {
|
(Some(RustLibSource::Discover), Some(sysroot_src)) => {
|
||||||
|
|
@ -238,6 +241,31 @@ impl ProjectWorkspace {
|
||||||
(None, _) => Sysroot::empty(),
|
(None, _) => Sysroot::empty(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Resolve the Cargo.toml to the workspace root as we base the `target` dir off of it.
|
||||||
|
let mut cmd = sysroot.tool(Tool::Cargo, workspace_dir, extra_env);
|
||||||
|
cmd.args(["locate-project", "--workspace", "--manifest-path", cargo_toml.as_str()]);
|
||||||
|
let cargo_toml = &match utf8_stdout(&mut cmd) {
|
||||||
|
Ok(output) => {
|
||||||
|
#[derive(serde_derive::Deserialize)]
|
||||||
|
struct Root {
|
||||||
|
root: Utf8PathBuf,
|
||||||
|
}
|
||||||
|
match serde_json::from_str::<Root>(&output) {
|
||||||
|
Ok(object) => ManifestPath::try_from(AbsPathBuf::assert(object.root))
|
||||||
|
.expect("manifest path should be absolute"),
|
||||||
|
Err(e) => {
|
||||||
|
tracing::error!(%e, %cargo_toml, "failed fetching cargo workspace root");
|
||||||
|
cargo_toml.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
tracing::error!(%e, %cargo_toml, "failed fetching cargo workspace root");
|
||||||
|
cargo_toml.clone()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let workspace_dir = cargo_toml.parent();
|
||||||
|
|
||||||
tracing::info!(workspace = %cargo_toml, src_root = ?sysroot.rust_lib_src_root(), root = ?sysroot.root(), "Using sysroot");
|
tracing::info!(workspace = %cargo_toml, src_root = ?sysroot.rust_lib_src_root(), root = ?sysroot.root(), "Using sysroot");
|
||||||
progress("Querying project metadata".to_owned());
|
progress("Querying project metadata".to_owned());
|
||||||
let toolchain_config = QueryConfig::Cargo(&sysroot, cargo_toml);
|
let toolchain_config = QueryConfig::Cargo(&sysroot, cargo_toml);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue