derive: track included files with relative path#546
Merged
GuillaumeGomez merged 2 commits intoaskama-rs:masterfrom Jul 31, 2025
Merged
derive: track included files with relative path#546GuillaumeGomez merged 2 commits intoaskama-rs:masterfrom
GuillaumeGomez merged 2 commits intoaskama-rs:masterfrom
Conversation
d54d963 to
940e175
Compare
Collaborator
Is there any reason why it should?
I'd say yes. One less dependency and as long as we mention where the code comes from, it gives us more liberty to adapt it more to ours needs if needed. |
Member
Author
Not really, no. :) If the new import path handling was feature gated, then the new dependencies could be optional. But if we copy the two functions, then there are not new dependencies, so no feature-gate is needed. |
The function `clean()` was copied from the project [`path_clean`] in version 1.0.1 (rev. [`d8948ae`]). License: MIT OR Apache-2.0. Authors: Dan Reeves <hey@danreev.es>, Alex Guerra <alex@heyimalex.com>, Adam Reichold The function `diff_paths()` was copied in from the project [`pathdiff`] in version 0.2.3 (rev. [`5180ff5`]). License: MIT OR Apache-2.0. Copyright 2012-2015 The Rust Project Developers. Please see their commit history for more information. [`path_clean`]: <https://github.com/danreeves/path-clean> [`pathdiff`]: <https://github.com/Manishearth/pathdiff> [`d8948ae`]: <https://github.com/danreeves/path-clean/blob/d8948ae69d349ec33dfe6d6b9c6a0fe30288a117/src/lib.rs#L50-L86> [`5180ff5`]: <https://github.com/Manishearth/pathdiff/blob/5180ff5b23d9d7eef0a14de13a3d814eb5d8d65c/src/lib.rs#L18-L86>
940e175 to
60e2e0a
Compare
To make the compiler understand which files contributed to the generated code, in order to make it aware when a recompilation is needed, we track the file paths using `include_bytes!()` calls in the generated code. This can be a problem for reproducible builds, because the working directory contributes to the file hash. This PR makes Askama generate relative paths if possible. This is always possible on Unix systems, but on Windows hosts absolute paths have to be used if the code is kept on different drives.
60e2e0a to
6035ffb
Compare
GuillaumeGomez
approved these changes
Jul 31, 2025
Collaborator
|
Thanks! |
This was referenced Jul 31, 2025
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
To make the compiler understand which files contributed to the generated code, in order to make it aware when a recompilation is needed, we track the file paths using
include_bytes!()calls in the generated code. This can be a problem for reproducible builds, because the working directory contributes to the file hash.This PR makes Askama generate relative paths if possible. This is always possible on Unix systems, but on Windows hosts absolute paths have to be used if the code is kept on different drives.
Span::local_file()is only stable since rust 1.88, but that's our MSRV for the next release, anyway.Open questions:
[ ] Should this behavior be feature gated?path_clean::clean()andpathdiff:diff_paths()are tiny, and both MIT OR Apache-2.0 licensed. Should we simply copy the code (mentioning the authors, of course)?Resolves #461.
Cc @frankdavid.