diff options
Diffstat (limited to 'crates/proc_macro_srv')
-rw-r--r-- | crates/proc_macro_srv/src/dylib.rs | 11 | ||||
-rw-r--r-- | crates/proc_macro_srv/src/tests/utils.rs | 29 |
2 files changed, 8 insertions, 32 deletions
diff --git a/crates/proc_macro_srv/src/dylib.rs b/crates/proc_macro_srv/src/dylib.rs index cccc53220..5133e7c50 100644 --- a/crates/proc_macro_srv/src/dylib.rs +++ b/crates/proc_macro_srv/src/dylib.rs | |||
@@ -188,7 +188,9 @@ impl Expander { | |||
188 | /// Copy the dylib to temp directory to prevent locking in Windows | 188 | /// Copy the dylib to temp directory to prevent locking in Windows |
189 | #[cfg(windows)] | 189 | #[cfg(windows)] |
190 | fn ensure_file_with_lock_free_access(path: &Path) -> io::Result<PathBuf> { | 190 | fn ensure_file_with_lock_free_access(path: &Path) -> io::Result<PathBuf> { |
191 | use std::{ffi::OsString, time::SystemTime}; | 191 | use std::collections::hash_map::RandomState; |
192 | use std::ffi::OsString; | ||
193 | use std::hash::{BuildHasher, Hasher}; | ||
192 | 194 | ||
193 | let mut to = std::env::temp_dir(); | 195 | let mut to = std::env::temp_dir(); |
194 | 196 | ||
@@ -199,10 +201,11 @@ fn ensure_file_with_lock_free_access(path: &Path) -> io::Result<PathBuf> { | |||
199 | ) | 201 | ) |
200 | })?; | 202 | })?; |
201 | 203 | ||
202 | // generate a time deps unique number | 204 | // Generate a unique number by abusing `HashMap`'s hasher. |
203 | let t = SystemTime::now().duration_since(std::time::UNIX_EPOCH).expect("Time went backwards"); | 205 | // Maybe this will also "inspire" a libs team member to finally put `rand` in libstd. |
206 | let t = RandomState::new().build_hasher().finish(); | ||
204 | 207 | ||
205 | let mut unique_name = OsString::from(t.as_millis().to_string()); | 208 | let mut unique_name = OsString::from(t.to_string()); |
206 | unique_name.push(file_name); | 209 | unique_name.push(file_name); |
207 | 210 | ||
208 | to.push(unique_name); | 211 | to.push(unique_name); |
diff --git a/crates/proc_macro_srv/src/tests/utils.rs b/crates/proc_macro_srv/src/tests/utils.rs index 2e950c113..2c093aa0a 100644 --- a/crates/proc_macro_srv/src/tests/utils.rs +++ b/crates/proc_macro_srv/src/tests/utils.rs | |||
@@ -7,35 +7,8 @@ use proc_macro_api::ListMacrosTask; | |||
7 | use std::str::FromStr; | 7 | use std::str::FromStr; |
8 | 8 | ||
9 | pub mod fixtures { | 9 | pub mod fixtures { |
10 | use cargo_metadata::Message; | ||
11 | use std::path::PathBuf; | ||
12 | use std::process::Command; | ||
13 | |||
14 | // Use current project metadata to get the proc-macro dylib path | ||
15 | pub fn proc_macro_test_dylib_path() -> std::path::PathBuf { | 10 | pub fn proc_macro_test_dylib_path() -> std::path::PathBuf { |
16 | let name = "proc_macro_test"; | 11 | proc_macro_test::PROC_MACRO_TEST_LOCATION.into() |
17 | let version = "0.0.0"; | ||
18 | let command = Command::new(toolchain::cargo()) | ||
19 | .args(&["check", "--tests", "--message-format", "json"]) | ||
20 | .output() | ||
21 | .unwrap() | ||
22 | .stdout; | ||
23 | |||
24 | for message in Message::parse_stream(command.as_slice()) { | ||
25 | match message.unwrap() { | ||
26 | Message::CompilerArtifact(artifact) => { | ||
27 | if artifact.target.kind.contains(&"proc-macro".to_string()) { | ||
28 | let repr = format!("{} {}", name, version); | ||
29 | if artifact.package_id.repr.starts_with(&repr) { | ||
30 | return PathBuf::from(&artifact.filenames[0]); | ||
31 | } | ||
32 | } | ||
33 | } | ||
34 | _ => (), // Unknown message | ||
35 | } | ||
36 | } | ||
37 | |||
38 | panic!("No proc-macro dylib for {} found!", name); | ||
39 | } | 12 | } |
40 | } | 13 | } |
41 | 14 | ||