Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix filename conflict #138

Merged
merged 2 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading