aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_proc_macro_srv
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2020-04-25 05:29:49 +0100
committerEdwin Cheng <[email protected]>2020-04-26 10:17:37 +0100
commit5a5bba5a4655be4ee7978f8577ce3351526655a5 (patch)
tree6700f48922cd6f1c917a257fb8cd0c950f3b6316 /crates/ra_proc_macro_srv
parent3e24444aee9db36d8de530dee9c0283ce793c6fd (diff)
Copy dylib to temp directory
Diffstat (limited to 'crates/ra_proc_macro_srv')
-rw-r--r--crates/ra_proc_macro_srv/src/dylib.rs19
1 files changed, 18 insertions, 1 deletions
diff --git a/crates/ra_proc_macro_srv/src/dylib.rs b/crates/ra_proc_macro_srv/src/dylib.rs
index 476bc5c01..018cc7bb8 100644
--- a/crates/ra_proc_macro_srv/src/dylib.rs
+++ b/crates/ra_proc_macro_srv/src/dylib.rs
@@ -2,7 +2,7 @@
2 2
3use crate::{proc_macro::bridge, rustc_server::TokenStream}; 3use crate::{proc_macro::bridge, rustc_server::TokenStream};
4use std::fs::File; 4use std::fs::File;
5use std::path::Path; 5use std::path::{Path, PathBuf};
6 6
7use goblin::{mach::Mach, Object}; 7use goblin::{mach::Mach, Object};
8use libloading::Library; 8use libloading::Library;
@@ -123,6 +123,9 @@ impl Expander {
123 .canonicalize() 123 .canonicalize()
124 .unwrap_or_else(|err| panic!("Cannot canonicalize {}: {:?}", lib.display(), err)); 124 .unwrap_or_else(|err| panic!("Cannot canonicalize {}: {:?}", lib.display(), err));
125 125
126 // Copy the dylib to temp directory to prevent locking in Windows
127 let lib = copy_to_temp_dir(&lib).map_err(|e| e.to_string())?;
128
126 let library = ProcMacroLibraryImpl::open(&lib).map_err(|e| e.to_string())?; 129 let library = ProcMacroLibraryImpl::open(&lib).map_err(|e| e.to_string())?;
127 130
128 Ok(Expander { inner: library }) 131 Ok(Expander { inner: library })
@@ -195,3 +198,17 @@ impl Expander {
195 .collect() 198 .collect()
196 } 199 }
197} 200}
201
202fn copy_to_temp_dir(path: &Path) -> io::Result<PathBuf> {
203 let mut to = std::env::temp_dir();
204 let file_name = path.file_name().ok_or_else(|| {
205 io::Error::new(
206 io::ErrorKind::InvalidInput,
207 format!("File path is invalid: {}", path.display()),
208 )
209 })?;
210
211 to.push(file_name);
212 std::fs::copy(path, &to)?;
213 Ok(to)
214}