From 4c554d1a576959c2d0a64858fb7df9f739f4293f Mon Sep 17 00:00:00 2001 From: Lev Date: Sat, 21 Oct 2023 14:09:00 -0700 Subject: [PATCH 1/2] Fix filename conflict --- sailfish-compiler/src/compiler.rs | 2 ++ sailfish-compiler/src/procmacro.rs | 22 ++++++---------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/sailfish-compiler/src/compiler.rs b/sailfish-compiler/src/compiler.rs index 69dbb2a..16a39d6 100644 --- a/sailfish-compiler/src/compiler.rs +++ b/sailfish-compiler/src/compiler.rs @@ -83,6 +83,8 @@ impl Compiler { let mut f = fs::File::create(output) .chain_err(|| format!("Failed to create artifact: {:?}", output))?; + writeln!(f, "// Template compiled from: {}", input.display()) + .chain_err(|| format!("Failed to write artifact into {:?}", output))?; writeln!(f, "{}", rustfmt_block(&*string).unwrap_or(string)) .chain_err(|| format!("Failed to write artifact into {:?}", output))?; drop(f); diff --git a/sailfish-compiler/src/procmacro.rs b/sailfish-compiler/src/procmacro.rs index 409bcbe..2424c0d 100644 --- a/sailfish-compiler/src/procmacro.rs +++ b/sailfish-compiler/src/procmacro.rs @@ -105,25 +105,14 @@ fn resolve_template_file(path: &str, template_dirs: &[PathBuf]) -> Option String { - use std::fmt::Write; - - let mut path_with_hash = String::with_capacity(16); - - if let Some(n) = path.file_name() { - let mut filename = &*n.to_string_lossy(); - if let Some(p) = filename.find('.') { - filename = &filename[..p]; - } - path_with_hash.push_str(filename); - path_with_hash.push('-'); - } - let mut hasher = DefaultHasher::new(); config.hash(&mut hasher); - let hash = hasher.finish(); - let _ = write!(path_with_hash, "{:016x}", hash); + let config_hash = hasher.finish(); - path_with_hash + path.hash(&mut hasher); + let path_hash = hasher.finish(); + + format!("{:016x}-{:016x}", config_hash, path_hash) } fn with_compiler Result>( @@ -249,6 +238,7 @@ fn derive_template_impl(tokens: TokenStream) -> Result let lock = Lock::new(&lock_path); match lock { Ok(lock) => { + let (tsource, report) = compiler.resolve_file(&input_file)?; let output_filetime = filetime(&output_file); From af91dc5243768f5dc98875cc647d6c97117088c5 Mon Sep 17 00:00:00 2001 From: Lev Date: Sat, 21 Oct 2023 14:10:31 -0700 Subject: [PATCH 2/2] remove space --- sailfish-compiler/src/procmacro.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/sailfish-compiler/src/procmacro.rs b/sailfish-compiler/src/procmacro.rs index 2424c0d..983c1c5 100644 --- a/sailfish-compiler/src/procmacro.rs +++ b/sailfish-compiler/src/procmacro.rs @@ -238,7 +238,6 @@ fn derive_template_impl(tokens: TokenStream) -> Result let lock = Lock::new(&lock_path); match lock { Ok(lock) => { - let (tsource, report) = compiler.resolve_file(&input_file)?; let output_filetime = filetime(&output_file);