-
Notifications
You must be signed in to change notification settings - Fork 12
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
Canonicalize include paths before emitting #258
Conversation
This allows `CARGO_MANIFEST_DIR` to be a relative path, which can be useful in non-cargo build systems.
c9f8191
to
0a04195
Compare
Drawback: Before this PR, the crate root could reside in a non-UTF-8 path without issues, and only everything inside it had to have a sane encoding. With the PR, the whole path has to be sane. But I guess that's okay. As a user, I don't think I would expect things to be working if my path was broken. |
rinja_derive/src/generator.rs
Outdated
@@ -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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we actually need to convert it to string? Can't we just use its Debug
impl?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! No, it seems to work just fine without it. And instead of panicking if the path could not be resolved, we can simply use the relative path. I think that's quite elegant. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeay \o/
This allows
CARGO_MANIFEST_DIR
to be a relative path, which can be useful in non-cargo build systems.Cherry-picked from https://github.com/djc/askama/pull/1107.