mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
Update crate graph to only use subcrates of rustc_driver
This commit is contained in:
parent
7513867aa2
commit
b46605cfcd
1 changed files with 38 additions and 38 deletions
|
@ -2,11 +2,7 @@
|
||||||
//! metadata` or `rust-project.json`) into representation stored in the salsa
|
//! metadata` or `rust-project.json`) into representation stored in the salsa
|
||||||
//! database -- `CrateGraph`.
|
//! database -- `CrateGraph`.
|
||||||
|
|
||||||
use std::{
|
use std::{collections::VecDeque, fmt, fs, path::Path, process::Command};
|
||||||
fmt, fs,
|
|
||||||
path::{Component, Path},
|
|
||||||
process::Command,
|
|
||||||
};
|
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use base_db::{CrateDisplayName, CrateGraph, CrateId, CrateName, Edition, Env, FileId, ProcMacro};
|
use base_db::{CrateDisplayName, CrateGraph, CrateId, CrateName, Edition, Env, FileId, ProcMacro};
|
||||||
|
@ -446,22 +442,24 @@ fn cargo_to_crate_graph(
|
||||||
let mut rustc_pkg_crates = FxHashMap::default();
|
let mut rustc_pkg_crates = FxHashMap::default();
|
||||||
|
|
||||||
// If the user provided a path to rustc sources, we add all the rustc_private crates
|
// If the user provided a path to rustc sources, we add all the rustc_private crates
|
||||||
// and create dependencies on them for the crates in the current workspace
|
// and create dependencies on them for the crates which opt-in to that
|
||||||
if let Some(rustc_workspace) = rustc {
|
if let Some(rustc_workspace) = rustc {
|
||||||
for pkg in rustc_workspace.packages() {
|
// rustc-dev crates start from 'rustc_driver'
|
||||||
|
// Therefore, we collect all crates which are transitive dependencies of rustc_driver
|
||||||
|
if let Some(root_pkg) = rustc_workspace
|
||||||
|
.packages()
|
||||||
|
.find(|package| rustc_workspace[*package].name == "rustc_driver")
|
||||||
|
{
|
||||||
|
let mut queue = VecDeque::new();
|
||||||
|
queue.push_back(root_pkg);
|
||||||
|
while let Some(pkg) = queue.pop_front() {
|
||||||
|
for dep in &rustc_workspace[pkg].dependencies {
|
||||||
|
queue.push_back(dep.pkg);
|
||||||
|
}
|
||||||
for &tgt in rustc_workspace[pkg].targets.iter() {
|
for &tgt in rustc_workspace[pkg].targets.iter() {
|
||||||
if rustc_workspace[tgt].kind != TargetKind::Lib {
|
if rustc_workspace[tgt].kind != TargetKind::Lib {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Exclude alloc / core / std
|
|
||||||
if rustc_workspace[tgt]
|
|
||||||
.root
|
|
||||||
.components()
|
|
||||||
.any(|c| c == Component::Normal("library".as_ref()))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(file_id) = load(&rustc_workspace[tgt].root) {
|
if let Some(file_id) = load(&rustc_workspace[tgt].root) {
|
||||||
let crate_id = add_target_crate_root(
|
let crate_id = add_target_crate_root(
|
||||||
&mut crate_graph,
|
&mut crate_graph,
|
||||||
|
@ -480,6 +478,7 @@ fn cargo_to_crate_graph(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Now add a dep edge from all targets of upstream to the lib
|
// Now add a dep edge from all targets of upstream to the lib
|
||||||
// target of downstream.
|
// target of downstream.
|
||||||
for pkg in rustc_workspace.packages() {
|
for pkg in rustc_workspace.packages() {
|
||||||
|
@ -493,7 +492,7 @@ fn cargo_to_crate_graph(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add dependencies for all the crates of the current workspace to rustc_private libraries
|
// Add dependencies for all crates which opt in to rustc_private libraries
|
||||||
for dep in rustc_workspace.packages() {
|
for dep in rustc_workspace.packages() {
|
||||||
let name = CrateName::normalize_dashes(&rustc_workspace[dep].name);
|
let name = CrateName::normalize_dashes(&rustc_workspace[dep].name);
|
||||||
|
|
||||||
|
@ -507,13 +506,14 @@ fn cargo_to_crate_graph(
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for &from in pkg_crates.get(&pkg).into_iter().flatten() {
|
for &from in pkg_crates.get(&pkg).into_iter().flatten() {
|
||||||
|
// Avoid creating duplicate dependencies
|
||||||
if !crate_graph[from].dependencies.iter().any(|d| d.name == name) {
|
if !crate_graph[from].dependencies.iter().any(|d| d.name == name) {
|
||||||
add_dep(&mut crate_graph, from, name.clone(), to);
|
add_dep(&mut crate_graph, from, name.clone(), to);
|
||||||
} else {
|
} else {
|
||||||
// eprintln!(
|
eprintln!(
|
||||||
// "Skipped {} for {:?}",
|
"Skipped {} for {:?}",
|
||||||
// &name, &crate_graph[from].display_name
|
&name, &crate_graph[from].display_name
|
||||||
// );
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue