Skip to content
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

Merged
merged 2 commits into from
Nov 19, 2024

Conversation

Kijewski
Copy link
Collaborator

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.

@Kijewski Kijewski marked this pull request as ready for review November 19, 2024 20:12
This allows `CARGO_MANIFEST_DIR` to be a relative path, which can be
useful in non-cargo build systems.
GuillaumeGomez
GuillaumeGomez previously approved these changes Nov 19, 2024
@Kijewski
Copy link
Collaborator Author

Kijewski commented Nov 19, 2024

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.

@@ -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();
Copy link
Contributor

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?

Copy link
Collaborator Author

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. :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeay \o/

@Kijewski Kijewski merged commit fb2d4eb into rinja-rs:master Nov 19, 2024
36 checks passed
@Kijewski Kijewski deleted the pr-canon-paths branch November 19, 2024 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants