mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 15:15:24 +00:00
Reduce deps
This commit is contained in:
parent
37a01de42c
commit
8d27829781
4 changed files with 40 additions and 39 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1103,7 +1103,6 @@ dependencies = [
|
||||||
"ra_arena",
|
"ra_arena",
|
||||||
"ra_cfg",
|
"ra_cfg",
|
||||||
"ra_db",
|
"ra_db",
|
||||||
"ra_flycheck",
|
|
||||||
"ra_proc_macro",
|
"ra_proc_macro",
|
||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
|
@ -243,7 +243,7 @@ impl fmt::Display for CargoError {
|
||||||
}
|
}
|
||||||
impl error::Error for CargoError {}
|
impl error::Error for CargoError {}
|
||||||
|
|
||||||
pub fn run_cargo(
|
fn run_cargo(
|
||||||
args: &[String],
|
args: &[String],
|
||||||
current_dir: Option<&Path>,
|
current_dir: Option<&Path>,
|
||||||
on_message: &mut dyn FnMut(cargo_metadata::Message) -> bool,
|
on_message: &mut dyn FnMut(cargo_metadata::Message) -> bool,
|
||||||
|
|
|
@ -16,7 +16,6 @@ cargo_metadata = "0.9.1"
|
||||||
ra_arena = { path = "../ra_arena" }
|
ra_arena = { path = "../ra_arena" }
|
||||||
ra_db = { path = "../ra_db" }
|
ra_db = { path = "../ra_db" }
|
||||||
ra_cfg = { path = "../ra_cfg" }
|
ra_cfg = { path = "../ra_cfg" }
|
||||||
ra_flycheck = { path = "../ra_flycheck" }
|
|
||||||
ra_proc_macro = { path = "../ra_proc_macro" }
|
ra_proc_macro = { path = "../ra_proc_macro" }
|
||||||
|
|
||||||
serde = { version = "1.0.104", features = ["derive"] }
|
serde = { version = "1.0.104", features = ["derive"] }
|
||||||
|
|
|
@ -1,16 +1,17 @@
|
||||||
//! FIXME: write short doc here
|
//! FIXME: write short doc here
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
|
env,
|
||||||
ffi::OsStr,
|
ffi::OsStr,
|
||||||
ops,
|
ops,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
|
process::Command,
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use cargo_metadata::{BuildScript, CargoOpt, Message, MetadataCommand, PackageId};
|
use cargo_metadata::{BuildScript, CargoOpt, Message, MetadataCommand, PackageId};
|
||||||
use ra_arena::{Arena, Idx};
|
use ra_arena::{Arena, Idx};
|
||||||
use ra_db::Edition;
|
use ra_db::Edition;
|
||||||
use ra_flycheck::run_cargo;
|
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
@ -163,7 +164,7 @@ impl CargoWorkspace {
|
||||||
let mut out_dir_by_id = FxHashMap::default();
|
let mut out_dir_by_id = FxHashMap::default();
|
||||||
let mut proc_macro_dylib_paths = FxHashMap::default();
|
let mut proc_macro_dylib_paths = FxHashMap::default();
|
||||||
if cargo_features.load_out_dirs_from_check {
|
if cargo_features.load_out_dirs_from_check {
|
||||||
let resources = load_extern_resources(cargo_toml, cargo_features);
|
let resources = load_extern_resources(cargo_toml, cargo_features)?;
|
||||||
out_dir_by_id = resources.out_dirs;
|
out_dir_by_id = resources.out_dirs;
|
||||||
proc_macro_dylib_paths = resources.proc_dylib_paths;
|
proc_macro_dylib_paths = resources.proc_dylib_paths;
|
||||||
}
|
}
|
||||||
|
@ -272,53 +273,51 @@ pub struct ExternResources {
|
||||||
proc_dylib_paths: FxHashMap<PackageId, PathBuf>,
|
proc_dylib_paths: FxHashMap<PackageId, PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_extern_resources(cargo_toml: &Path, cargo_features: &CargoFeatures) -> ExternResources {
|
pub fn load_extern_resources(
|
||||||
let mut args: Vec<String> = vec![
|
cargo_toml: &Path,
|
||||||
"check".to_string(),
|
cargo_features: &CargoFeatures,
|
||||||
"--message-format=json".to_string(),
|
) -> Result<ExternResources> {
|
||||||
"--manifest-path".to_string(),
|
let mut cmd = Command::new(cargo_binary());
|
||||||
cargo_toml.display().to_string(),
|
cmd.args(&["check", "--message-format=json", "--manifest-path"]).arg(cargo_toml);
|
||||||
];
|
|
||||||
|
|
||||||
if cargo_features.all_features {
|
if cargo_features.all_features {
|
||||||
args.push("--all-features".to_string());
|
cmd.arg("--all-features");
|
||||||
} else if cargo_features.no_default_features {
|
} else if cargo_features.no_default_features {
|
||||||
// FIXME: `NoDefaultFeatures` is mutual exclusive with `SomeFeatures`
|
// FIXME: `NoDefaultFeatures` is mutual exclusive with `SomeFeatures`
|
||||||
// https://github.com/oli-obk/cargo_metadata/issues/79
|
// https://github.com/oli-obk/cargo_metadata/issues/79
|
||||||
args.push("--no-default-features".to_string());
|
cmd.arg("--no-default-features");
|
||||||
} else {
|
} else {
|
||||||
args.extend(cargo_features.features.iter().cloned());
|
cmd.args(&cargo_features.features);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut acc = ExternResources::default();
|
let output = cmd.output()?;
|
||||||
let res = run_cargo(&args, cargo_toml.parent(), &mut |message| {
|
|
||||||
match message {
|
|
||||||
Message::BuildScriptExecuted(BuildScript { package_id, out_dir, .. }) => {
|
|
||||||
acc.out_dirs.insert(package_id, out_dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
Message::CompilerArtifact(message) => {
|
let mut res = ExternResources::default();
|
||||||
if message.target.kind.contains(&"proc-macro".to_string()) {
|
|
||||||
let package_id = message.package_id;
|
let stdout = String::from_utf8(output.stdout)?;
|
||||||
// Skip rmeta file
|
for line in stdout.lines() {
|
||||||
if let Some(filename) =
|
if let Ok(message) = serde_json::from_str::<cargo_metadata::Message>(&line) {
|
||||||
message.filenames.iter().filter(|name| is_dylib(name)).next()
|
match message {
|
||||||
{
|
Message::BuildScriptExecuted(BuildScript { package_id, out_dir, .. }) => {
|
||||||
acc.proc_dylib_paths.insert(package_id, filename.clone());
|
res.out_dirs.insert(package_id, out_dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
Message::CompilerArtifact(message) => {
|
||||||
|
if message.target.kind.contains(&"proc-macro".to_string()) {
|
||||||
|
let package_id = message.package_id;
|
||||||
|
// Skip rmeta file
|
||||||
|
if let Some(filename) =
|
||||||
|
message.filenames.iter().filter(|name| is_dylib(name)).next()
|
||||||
|
{
|
||||||
|
res.proc_dylib_paths.insert(package_id, filename.clone());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Message::CompilerMessage(_) => (),
|
||||||
|
Message::Unknown => (),
|
||||||
}
|
}
|
||||||
Message::CompilerMessage(_) => (),
|
|
||||||
Message::Unknown => (),
|
|
||||||
}
|
}
|
||||||
true
|
|
||||||
});
|
|
||||||
|
|
||||||
if let Err(err) = res {
|
|
||||||
log::error!("Failed to load outdirs: {:?}", err);
|
|
||||||
}
|
}
|
||||||
|
Ok(res)
|
||||||
acc
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: File a better way to know if it is a dylib
|
// FIXME: File a better way to know if it is a dylib
|
||||||
|
@ -328,3 +327,7 @@ fn is_dylib(path: &Path) -> bool {
|
||||||
Some(ext) => matches!(ext.as_str(), "dll" | "dylib" | "so"),
|
Some(ext) => matches!(ext.as_str(), "dll" | "dylib" | "so"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn cargo_binary() -> String {
|
||||||
|
env::var("CARGO").unwrap_or_else(|_| "cargo".to_string())
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue