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: Bump cargo_metadata --- crates/project_model/Cargo.toml | 10 +++++----- crates/project_model/src/build_data.rs | 23 ++++++++++------------- crates/project_model/src/cargo_workspace.rs | 9 ++++++--- 3 files changed, 21 insertions(+), 21 deletions(-) (limited to 'crates/project_model') diff --git a/crates/project_model/Cargo.toml b/crates/project_model/Cargo.toml index 293cb5bfe..fe3258332 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 295b5f8ef..728a258ea 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 1d8d34a0b..f7241b711 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(), -- cgit v1.2.3