Skip to content

Commit

Permalink
Canonicalize include paths before emitting
Browse files Browse the repository at this point in the history
This allows `CARGO_MANIFEST_DIR` to be a relative path, which can be
useful in non-cargo build systems.
  • Loading branch information
David Koloski authored and djc committed Nov 19, 2024
1 parent a7e108c commit 88a6e1f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions askama_derive/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@ impl<'a> Generator<'a> {
Source::Source(_) => **path != self.input.path,
};
if path_is_valid {
let path = path.to_str().unwrap();
let canonical_path = path.canonicalize().unwrap();
let include_path = canonical_path.to_str().unwrap();
buf.writeln(
&quote! {
include_bytes!(#path);
include_bytes!(#include_path);
}
.to_string(),
)?;
Expand Down Expand Up @@ -786,10 +787,11 @@ impl<'a> Generator<'a> {

// Make sure the compiler understands that the generated code depends on the template file.
{
let path = path.to_str().unwrap();
let canonical_path = path.canonicalize().unwrap();
let include_path = canonical_path.to_str().unwrap();
buf.writeln(
&quote! {
include_bytes!(#path);
include_bytes!(#include_path);
}
.to_string(),
)?;
Expand Down

0 comments on commit 88a6e1f

Please sign in to comment.