From b20708f6ee652310083957c519e35a4a4e73496d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Tue, 2 Mar 2021 14:27:29 +0200 Subject: [PATCH] Bump cargo_metadata --- Cargo.lock | 26 +++++++++++++------ crates/flycheck/Cargo.toml | 4 +-- crates/flycheck/src/lib.rs | 5 ++-- crates/proc_macro_srv/Cargo.toml | 2 +- crates/proc_macro_srv/src/tests/utils.rs | 3 ++- crates/project_model/Cargo.toml | 10 +++---- crates/project_model/src/build_data.rs | 23 +++++++--------- crates/project_model/src/cargo_workspace.rs | 9 ++++--- .../rust-analyzer/src/diagnostics/to_proto.rs | 2 +- 9 files changed, 47 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0476a15eb1..54ad92bb14 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -111,6 +111,15 @@ version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae44d1a3d5a19df61dd0c8beb138458ac2a53a7ac09eba97d55592540004306b" +[[package]] +name = "camino" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bb47ab72bdba43021afa16dc1ef4d80c980d366b17ed37ea8d2ebe2087075b9" +dependencies = [ + "serde", +] + [[package]] name = "cargo-platform" version = "0.1.1" @@ -122,10 +131,11 @@ dependencies = [ [[package]] name = "cargo_metadata" -version = "0.12.3" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7714a157da7991e23d90686b9524b9e12e0407a108647f52e9328f4b3d51ac7f" +checksum = "081e3f0755c1f380c2d010481b6fa2e02973586d5f2b24eebb7a2a1d98b143d8" dependencies = [ + "camino", "cargo-platform", "semver", "semver-parser", @@ -779,9 +789,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.86" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c" +checksum = "265d751d31d6780a3f956bb5b8022feba2d94eeee5a84ba64f4212eedca42213" [[package]] name = "libloading" @@ -1005,9 +1015,9 @@ checksum = "a9a7ab5d64814df0fe4a4b5ead45ed6c5f181ee3ff04ba344313a6c80446c5d4" [[package]] name = "once_cell" -version = "1.7.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10acf907b94fc1b1a152d08ef97e7759650268cf986bf127f387e602b02c7e5a" +checksum = "ea78b9742c52ac729753c1590e9adc5248ea9bdaf974597efd46c74cfaa5fb54" [[package]] name = "oorandom" @@ -1122,9 +1132,9 @@ checksum = "d70072c20945e1ab871c472a285fc772aefd4f5407723c206242f2c6f94595d6" [[package]] name = "pin-project-lite" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "439697af366c49a6d0a010c56a0d97685bc140ce0d377b13a2ea2aa42d64a827" +checksum = "0cf491442e4b033ed1c722cb9f0df5fcfcf4de682466c46469c36bc47dc5548a" [[package]] name = "proc-macro-hack" diff --git a/crates/flycheck/Cargo.toml b/crates/flycheck/Cargo.toml index 1d19c78869..2a1a21b28b 100644 --- a/crates/flycheck/Cargo.toml +++ b/crates/flycheck/Cargo.toml @@ -12,9 +12,9 @@ doctest = false [dependencies] crossbeam-channel = "0.5.0" log = "0.4.8" -cargo_metadata = "0.12.2" +cargo_metadata = "0.13" serde_json = "1.0.48" jod-thread = "0.1.1" toolchain = { path = "../toolchain", version = "0.0.0" } -stdx = { path = "../stdx", version = "0.0.0" } +stdx = { path = "../stdx", version = "0.0.0" } diff --git a/crates/flycheck/src/lib.rs b/crates/flycheck/src/lib.rs index e04208006f..e2a59497aa 100644 --- a/crates/flycheck/src/lib.rs +++ b/crates/flycheck/src/lib.rs @@ -194,7 +194,7 @@ impl FlycheckActor { cargo_metadata::Message::BuildScriptExecuted(_) | cargo_metadata::Message::BuildFinished(_) | cargo_metadata::Message::TextLine(_) - | cargo_metadata::Message::Unknown => {} + | _ => {} }, } } @@ -329,8 +329,7 @@ impl CargoActor { // Skip certain kinds of messages to only spend time on what's useful match &message { cargo_metadata::Message::CompilerArtifact(artifact) if artifact.fresh => (), - cargo_metadata::Message::BuildScriptExecuted(_) - | cargo_metadata::Message::Unknown => (), + cargo_metadata::Message::BuildScriptExecuted(_) => (), _ => self.sender.send(message).unwrap(), } } diff --git a/crates/proc_macro_srv/Cargo.toml b/crates/proc_macro_srv/Cargo.toml index 6c8c289801..4c1b3036ae 100644 --- a/crates/proc_macro_srv/Cargo.toml +++ b/crates/proc_macro_srv/Cargo.toml @@ -20,7 +20,7 @@ proc_macro_api = { path = "../proc_macro_api", version = "0.0.0" } test_utils = { path = "../test_utils", version = "0.0.0" } [dev-dependencies] -cargo_metadata = "0.12.2" +cargo_metadata = "0.13" # used as proc macro test targets serde_derive = "1.0.106" diff --git a/crates/proc_macro_srv/src/tests/utils.rs b/crates/proc_macro_srv/src/tests/utils.rs index 196abb8fc2..22813052df 100644 --- a/crates/proc_macro_srv/src/tests/utils.rs +++ b/crates/proc_macro_srv/src/tests/utils.rs @@ -8,6 +8,7 @@ use test_utils::assert_eq_text; mod fixtures { use cargo_metadata::Message; + use std::path::PathBuf; use std::process::Command; // Use current project metadata to get the proc-macro dylib path @@ -24,7 +25,7 @@ mod fixtures { if artifact.target.kind.contains(&"proc-macro".to_string()) { let repr = format!("{} {}", crate_name, version); if artifact.package_id.repr.starts_with(&repr) { - return artifact.filenames[0].clone(); + return PathBuf::from(&artifact.filenames[0]); } } } diff --git a/crates/project_model/Cargo.toml b/crates/project_model/Cargo.toml index 293cb5bfe1..fe3258332a 100644 --- a/crates/project_model/Cargo.toml +++ b/crates/project_model/Cargo.toml @@ -12,7 +12,7 @@ doctest = false [dependencies] log = "0.4.8" rustc-hash = "1.1.0" -cargo_metadata = "0.12.2" +cargo_metadata = "0.13" serde = { version = "1.0.106", features = ["derive"] } serde_json = "1.0.48" anyhow = "1.0.26" @@ -22,7 +22,7 @@ la-arena = { version = "0.2.0", path = "../../lib/arena" } cfg = { path = "../cfg", version = "0.0.0" } base_db = { path = "../base_db", version = "0.0.0" } toolchain = { path = "../toolchain", version = "0.0.0" } -proc_macro_api = { path = "../proc_macro_api", version = "0.0.0" } -paths = { path = "../paths", version = "0.0.0" } -stdx = { path = "../stdx", version = "0.0.0" } -profile = { path = "../profile", version = "0.0.0" } +proc_macro_api = { path = "../proc_macro_api", version = "0.0.0" } +paths = { path = "../paths", version = "0.0.0" } +stdx = { path = "../stdx", version = "0.0.0" } +profile = { path = "../profile", version = "0.0.0" } diff --git a/crates/project_model/src/build_data.rs b/crates/project_model/src/build_data.rs index 295b5f8eff..728a258eae 100644 --- a/crates/project_model/src/build_data.rs +++ b/crates/project_model/src/build_data.rs @@ -1,14 +1,14 @@ //! Handles build script specific information use std::{ - ffi::OsStr, io::BufReader, - path::{Path, PathBuf}, + path::PathBuf, process::{Command, Stdio}, sync::Arc, }; use anyhow::Result; +use cargo_metadata::camino::Utf8Path; use cargo_metadata::{BuildScript, Message}; use itertools::Itertools; use paths::{AbsPath, AbsPathBuf}; @@ -162,8 +162,8 @@ fn collect_from_workspace( let res = res.entry(package_id.repr.clone()).or_default(); // cargo_metadata crate returns default (empty) path for // older cargos, which is not absolute, so work around that. - if out_dir != PathBuf::default() { - let out_dir = AbsPathBuf::assert(out_dir); + if !out_dir.as_str().is_empty() { + let out_dir = AbsPathBuf::assert(PathBuf::from(out_dir.into_os_string())); res.out_dir = Some(out_dir); res.cfgs = cfgs; } @@ -178,7 +178,7 @@ fn collect_from_workspace( // Skip rmeta file if let Some(filename) = message.filenames.iter().find(|name| is_dylib(name)) { - let filename = AbsPathBuf::assert(filename.clone()); + let filename = AbsPathBuf::assert(PathBuf::from(&filename)); let res = res.entry(package_id.repr.clone()).or_default(); res.proc_macro_dylib_path = Some(filename); } @@ -187,9 +187,9 @@ fn collect_from_workspace( Message::CompilerMessage(message) => { progress(message.target.name.clone()); } - Message::Unknown => (), Message::BuildFinished(_) => {} Message::TextLine(_) => {} + _ => {} } } } @@ -209,8 +209,8 @@ fn collect_from_workspace( } // FIXME: File a better way to know if it is a dylib -fn is_dylib(path: &Path) -> bool { - match path.extension().and_then(OsStr::to_str).map(|it| it.to_string().to_lowercase()) { +fn is_dylib(path: &Utf8Path) -> bool { + match path.extension().map(|e| e.to_string().to_lowercase()) { None => false, Some(ext) => matches!(ext.as_str(), "dll" | "dylib" | "so"), } @@ -227,9 +227,7 @@ fn inject_cargo_env(package: &cargo_metadata::Package, build_data: &mut BuildDat let mut manifest_dir = package.manifest_path.clone(); manifest_dir.pop(); - if let Some(cargo_manifest_dir) = manifest_dir.to_str() { - env.push(("CARGO_MANIFEST_DIR".into(), cargo_manifest_dir.into())); - } + env.push(("CARGO_MANIFEST_DIR".into(), manifest_dir.into_string())); // Not always right, but works for common cases. env.push(("CARGO".into(), "cargo".into())); @@ -251,7 +249,6 @@ fn inject_cargo_env(package: &cargo_metadata::Package, build_data: &mut BuildDat env.push(("CARGO_PKG_REPOSITORY".into(), package.repository.clone().unwrap_or_default())); env.push(("CARGO_PKG_LICENSE".into(), package.license.clone().unwrap_or_default())); - let license_file = - package.license_file.as_ref().map(|buf| buf.display().to_string()).unwrap_or_default(); + let license_file = package.license_file.as_ref().map(|buf| buf.to_string()).unwrap_or_default(); env.push(("CARGO_PKG_LICENSE_FILE".into(), license_file)); } diff --git a/crates/project_model/src/cargo_workspace.rs b/crates/project_model/src/cargo_workspace.rs index 1d8d34a0b8..f7241b7113 100644 --- a/crates/project_model/src/cargo_workspace.rs +++ b/crates/project_model/src/cargo_workspace.rs @@ -1,5 +1,6 @@ //! FIXME: write short doc here +use std::path::PathBuf; use std::{convert::TryInto, ops, process::Command, sync::Arc}; use anyhow::{Context, Result}; @@ -249,11 +250,12 @@ impl CargoWorkspace { let edition = edition .parse::() .with_context(|| format!("Failed to parse edition {}", edition))?; + let pkg = packages.alloc(PackageData { id: id.repr.clone(), name: name.clone(), version: version.to_string(), - manifest: AbsPathBuf::assert(manifest_path.clone()), + manifest: AbsPathBuf::assert(PathBuf::from(&manifest_path)), targets: Vec::new(), is_member, edition, @@ -268,7 +270,7 @@ impl CargoWorkspace { let tgt = targets.alloc(TargetData { package: pkg, name: meta_tgt.name.clone(), - root: AbsPathBuf::assert(meta_tgt.src_path.clone()), + root: AbsPathBuf::assert(PathBuf::from(&meta_tgt.src_path)), kind: TargetKind::new(meta_tgt.kind.as_slice()), is_proc_macro, }); @@ -305,7 +307,8 @@ impl CargoWorkspace { packages[source].active_features.extend(node.features); } - let workspace_root = AbsPathBuf::assert(meta.workspace_root); + let workspace_root = + AbsPathBuf::assert(PathBuf::from(meta.workspace_root.into_os_string())); let build_data_config = BuildDataConfig::new( cargo_toml.to_path_buf(), config.clone(), diff --git a/crates/rust-analyzer/src/diagnostics/to_proto.rs b/crates/rust-analyzer/src/diagnostics/to_proto.rs index 0ed87fe3e0..0ad832c0ee 100644 --- a/crates/rust-analyzer/src/diagnostics/to_proto.rs +++ b/crates/rust-analyzer/src/diagnostics/to_proto.rs @@ -29,7 +29,7 @@ fn diagnostic_severity( }, DiagnosticLevel::Note => lsp_types::DiagnosticSeverity::Information, DiagnosticLevel::Help => lsp_types::DiagnosticSeverity::Hint, - DiagnosticLevel::Unknown => return None, + _ => return None, }; Some(res) }