diff --git a/Cargo.lock b/Cargo.lock index d27a36c9e1e..0649ff66db1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -170,6 +170,18 @@ dependencies = [ "serde_json 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "cargo_metadata" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "cc" version = "1.0.28" @@ -1344,7 +1356,7 @@ name = "rls" version = "1.33.0" dependencies = [ "cargo 0.34.0 (git+https://github.com/rust-lang/cargo?rev=907c0febe7045fa02dff2a35c5e36d3bd59ea50d)", - "cargo_metadata 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cargo_metadata 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "clippy_lints 0.0.212 (git+https://github.com/rust-lang/rust-clippy?rev=280069ddc750d8a20d075c76322c45d5db4a48f8)", "crossbeam-channel 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2228,6 +2240,7 @@ dependencies = [ "checksum bytesize 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "716960a18f978640f25101b5cbf1c6f6b0d3192fab36a2d98ca96f0ecbe41010" "checksum cargo 0.34.0 (git+https://github.com/rust-lang/cargo?rev=907c0febe7045fa02dff2a35c5e36d3bd59ea50d)" = "" "checksum cargo_metadata 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "e5d1b4d380e1bab994591a24c2bdd1b054f64b60bef483a8c598c7c345bc3bbe" +"checksum cargo_metadata 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "95932a7ed5f2308fc00a46d2aa8eb1b06b402c896c2df424916ee730ba610c2e" "checksum cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4a8b715cb4597106ea87c7c84b2f1d452c7492033765df7f32651e66fcf749" "checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4" "checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e" diff --git a/Cargo.toml b/Cargo.toml index 8e8c79bac7b..0f250976d8d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ test = false [dependencies] cargo = { git = "https://github.com/rust-lang/cargo", rev = "907c0febe7045fa02dff2a35c5e36d3bd59ea50d" } -cargo_metadata = "0.6" +cargo_metadata = "0.7" clippy_lints = { git = "https://github.com/rust-lang/rust-clippy", rev = "280069ddc750d8a20d075c76322c45d5db4a48f8", optional = true } env_logger = "0.6" failure = "0.1.1" diff --git a/src/build/cargo_plan.rs b/src/build/cargo_plan.rs index 035f5818035..3bdf7e3cd45 100644 --- a/src/build/cargo_plan.rs +++ b/src/build/cargo_plan.rs @@ -35,12 +35,10 @@ use cargo::core::{PackageId, Target, TargetKind}; use cargo::util::ProcessBuilder; use cargo_metadata; use log::{error, trace}; -use url::Url; -use crate::build::PackageArg; -use crate::build::plan::{BuildKey, BuildGraph, JobQueue, WorkStatus}; +use crate::build::plan::{BuildGraph, BuildKey, JobQueue, WorkStatus}; use crate::build::rustc::src_path; -use crate::lsp_data::parse_file_path; +use crate::build::PackageArg; /// Main key type by which `Unit`s will be distinguished in the build plan. /// In Target we're mostly interested in TargetKind (Lib, Bin, ...) and name @@ -455,19 +453,16 @@ impl PackageMap { // Find each package in the workspace and record the root directory and package name. fn discover_package_paths(manifest_path: &Path) -> HashMap { trace!("read metadata {:?}", manifest_path); - let metadata = match cargo_metadata::metadata(Some(manifest_path)) { - Ok(metadata) => metadata, - Err(_) => return HashMap::new(), - }; - metadata - .workspace_members - .into_iter() - .map(|wm| { - assert!(wm.url().starts_with("path+")); - let url = Url::parse(&wm.url()[5..]).expect("Bad URL"); - let path = parse_file_path(&url).expect("URL not a path"); - (path, wm.name().into()) - }).collect() + cargo_metadata::MetadataCommand::new() + .manifest_path(manifest_path) + .exec() + .iter() + .flat_map(|meta| meta.workspace_members.iter().map(move |id| &meta[id])) + .filter_map(|pkg| { + let dir = pkg.manifest_path.parent()?.to_path_buf(); + Some((dir, pkg.name.clone())) + }) + .collect() } /// Given modified set of files, returns a set of corresponding dirty packages.