Skip to content

Commit 0a04195

Browse files
David KoloskiKijewski
authored andcommitted
Canonicalize include paths before emitting
This allows `CARGO_MANIFEST_DIR` to be a relative path, which can be useful in non-cargo build systems.
1 parent f86fedd commit 0a04195

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

rinja_derive/src/generator.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,11 @@ impl<'a> Generator<'a> {
172172
Source::Source(_) => path != &*self.input.path,
173173
};
174174
if path_is_valid {
175-
let path = path.to_str().unwrap();
175+
let canonical_path = path.canonicalize().unwrap();
176+
let include_path = canonical_path.to_str().unwrap();
176177
buf.write(format_args!(
177178
"const _: &[rinja::helpers::core::primitive::u8] =\
178-
rinja::helpers::core::include_bytes!({path:#?});",
179+
rinja::helpers::core::include_bytes!({include_path:#?});",
179180
));
180181
}
181182
}

rinja_derive/src/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ fn check_if_let() {
191191

192192
// In this test we make sure that every used template gets referenced exactly once.
193193
let path = Path::new(env!("CARGO_MANIFEST_DIR")).join("templates");
194-
let path1 = path.join("include1.html");
195-
let path2 = path.join("include2.html");
196-
let path3 = path.join("include3.html");
194+
let path1 = path.join("include1.html").canonicalize().unwrap();
195+
let path2 = path.join("include2.html").canonicalize().unwrap();
196+
let path3 = path.join("include3.html").canonicalize().unwrap();
197197
compare(
198198
r#"{% include "include1.html" %}"#,
199199
&format!(

0 commit comments

Comments
 (0)