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 Kijewski committed Nov 19, 2024
1 parent f86fedd commit c9f8191
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions rinja_derive/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,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.write(format_args!(
"const _: &[rinja::helpers::core::primitive::u8] =\
rinja::helpers::core::include_bytes!({path:#?});",
rinja::helpers::core::include_bytes!({include_path:#?});",
));
}
}
Expand Down

0 comments on commit c9f8191

Please sign in to comment.