From cc5d843a1478ee4a9350e3a6689fe43d11bd98d4 Mon Sep 17 00:00:00 2001 From: David Koloski Date: Mon, 18 Nov 2024 20:37:18 +0000 Subject: [PATCH] Canonicalize include paths before emitting This allows `CARGO_MANIFEST_DIR` to be a relative path, which can be useful in non-cargo build systems. --- askama_derive/src/generator.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index 47ec57c7..811ae6a8 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -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( "e! { - include_bytes!(#path); + include_bytes!(#include_path); } .to_string(), )?; @@ -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( "e! { - include_bytes!(#path); + include_bytes!(#include_path); } .to_string(), )?;