aboutsummaryrefslogtreecommitdiff
path: root/crates/project_model/src/build_data.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/project_model/src/build_data.rs')
-rw-r--r--crates/project_model/src/build_data.rs23
1 files changed, 10 insertions, 13 deletions
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 @@
1//! Handles build script specific information 1//! Handles build script specific information
2 2
3use std::{ 3use std::{
4 ffi::OsStr,
5 io::BufReader, 4 io::BufReader,
6 path::{Path, PathBuf}, 5 path::PathBuf,
7 process::{Command, Stdio}, 6 process::{Command, Stdio},
8 sync::Arc, 7 sync::Arc,
9}; 8};
10 9
11use anyhow::Result; 10use anyhow::Result;
11use cargo_metadata::camino::Utf8Path;
12use cargo_metadata::{BuildScript, Message}; 12use cargo_metadata::{BuildScript, Message};
13use itertools::Itertools; 13use itertools::Itertools;
14use paths::{AbsPath, AbsPathBuf}; 14use paths::{AbsPath, AbsPathBuf};
@@ -162,8 +162,8 @@ fn collect_from_workspace(
162 let res = res.entry(package_id.repr.clone()).or_default(); 162 let res = res.entry(package_id.repr.clone()).or_default();
163 // cargo_metadata crate returns default (empty) path for 163 // cargo_metadata crate returns default (empty) path for
164 // older cargos, which is not absolute, so work around that. 164 // older cargos, which is not absolute, so work around that.
165 if out_dir != PathBuf::default() { 165 if !out_dir.as_str().is_empty() {
166 let out_dir = AbsPathBuf::assert(out_dir); 166 let out_dir = AbsPathBuf::assert(PathBuf::from(out_dir.into_os_string()));
167 res.out_dir = Some(out_dir); 167 res.out_dir = Some(out_dir);
168 res.cfgs = cfgs; 168 res.cfgs = cfgs;
169 } 169 }
@@ -178,7 +178,7 @@ fn collect_from_workspace(
178 // Skip rmeta file 178 // Skip rmeta file
179 if let Some(filename) = message.filenames.iter().find(|name| is_dylib(name)) 179 if let Some(filename) = message.filenames.iter().find(|name| is_dylib(name))
180 { 180 {
181 let filename = AbsPathBuf::assert(filename.clone()); 181 let filename = AbsPathBuf::assert(PathBuf::from(&filename));
182 let res = res.entry(package_id.repr.clone()).or_default(); 182 let res = res.entry(package_id.repr.clone()).or_default();
183 res.proc_macro_dylib_path = Some(filename); 183 res.proc_macro_dylib_path = Some(filename);
184 } 184 }
@@ -187,9 +187,9 @@ fn collect_from_workspace(
187 Message::CompilerMessage(message) => { 187 Message::CompilerMessage(message) => {
188 progress(message.target.name.clone()); 188 progress(message.target.name.clone());
189 } 189 }
190 Message::Unknown => (),
191 Message::BuildFinished(_) => {} 190 Message::BuildFinished(_) => {}
192 Message::TextLine(_) => {} 191 Message::TextLine(_) => {}
192 _ => {}
193 } 193 }
194 } 194 }
195 } 195 }
@@ -209,8 +209,8 @@ fn collect_from_workspace(
209} 209}
210 210
211// FIXME: File a better way to know if it is a dylib 211// FIXME: File a better way to know if it is a dylib
212fn is_dylib(path: &Path) -> bool { 212fn is_dylib(path: &Utf8Path) -> bool {
213 match path.extension().and_then(OsStr::to_str).map(|it| it.to_string().to_lowercase()) { 213 match path.extension().map(|e| e.to_string().to_lowercase()) {
214 None => false, 214 None => false,
215 Some(ext) => matches!(ext.as_str(), "dll" | "dylib" | "so"), 215 Some(ext) => matches!(ext.as_str(), "dll" | "dylib" | "so"),
216 } 216 }
@@ -227,9 +227,7 @@ fn inject_cargo_env(package: &cargo_metadata::Package, build_data: &mut BuildDat
227 227
228 let mut manifest_dir = package.manifest_path.clone(); 228 let mut manifest_dir = package.manifest_path.clone();
229 manifest_dir.pop(); 229 manifest_dir.pop();
230 if let Some(cargo_manifest_dir) = manifest_dir.to_str() { 230 env.push(("CARGO_MANIFEST_DIR".into(), manifest_dir.into_string()));
231 env.push(("CARGO_MANIFEST_DIR".into(), cargo_manifest_dir.into()));
232 }
233 231
234 // Not always right, but works for common cases. 232 // Not always right, but works for common cases.
235 env.push(("CARGO".into(), "cargo".into())); 233 env.push(("CARGO".into(), "cargo".into()));
@@ -251,7 +249,6 @@ fn inject_cargo_env(package: &cargo_metadata::Package, build_data: &mut BuildDat
251 env.push(("CARGO_PKG_REPOSITORY".into(), package.repository.clone().unwrap_or_default())); 249 env.push(("CARGO_PKG_REPOSITORY".into(), package.repository.clone().unwrap_or_default()));
252 env.push(("CARGO_PKG_LICENSE".into(), package.license.clone().unwrap_or_default())); 250 env.push(("CARGO_PKG_LICENSE".into(), package.license.clone().unwrap_or_default()));
253 251
254 let license_file = 252 let license_file = package.license_file.as_ref().map(|buf| buf.to_string()).unwrap_or_default();
255 package.license_file.as_ref().map(|buf| buf.display().to_string()).unwrap_or_default();
256 env.push(("CARGO_PKG_LICENSE_FILE".into(), license_file)); 253 env.push(("CARGO_PKG_LICENSE_FILE".into(), license_file));
257} 254}