Skip to content

Commit

Permalink
Merge pull request #138 from levkk/levkk-fix-filename-conflict
Browse files Browse the repository at this point in the history
Fix filename conflict
  • Loading branch information
vthg2themax committed Oct 22, 2023
2 parents 3bb7b3e + af91dc5 commit ef79697
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
2 changes: 2 additions & 0 deletions sailfish-compiler/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 5 additions & 16 deletions sailfish-compiler/src/procmacro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,14 @@ fn resolve_template_file(path: &str, template_dirs: &[PathBuf]) -> Option<PathBu
}

fn filename_hash(path: &Path, config: &Config) -> 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.hash(&mut hasher);
let path_hash = hasher.finish();

path_with_hash
format!("{:016x}-{:016x}", config_hash, path_hash)
}

fn with_compiler<T, F: FnOnce(Compiler) -> Result<T, Error>>(
Expand Down

0 comments on commit ef79697

Please sign in to comment.