Make embedded files be resolved by project root#266
Merged
snoyberg merged 4 commits intoyesodweb:masterfrom Apr 25, 2022
SupercedeTech:templates-relative-to-project-root
Merged
Make embedded files be resolved by project root#266snoyberg merged 4 commits intoyesodweb:masterfrom SupercedeTech:templates-relative-to-project-root
snoyberg merged 4 commits intoyesodweb:masterfrom
SupercedeTech:templates-relative-to-project-root
Conversation
Because file embedding runs IO in the Template Haskell `Q` monad, relative file paths are resolved by the compiler's working directory. Ordinarily, this is the root of the project being built - but if the compiler is e.g. building a dependency, it can also be different. This change makes it so that template files are always embedded relative to the project that contains the code embedding them, rather than the working directory of the compiler - this means that dependencies in a multi-project codebase can embed files correctly.
ivb-supercede
commented
Apr 20, 2022
Comment on lines
+288
to
+299
| fp <- makeRelativeToProject rawFp | ||
| qRunIO (readUtf8FileString fp) | ||
|
|
||
| -- | Embed file's content, converting newlines | ||
| -- and track file via ghc dependencies, recompiling on changes | ||
| -- | ||
| -- @since 2.0.19 | ||
| readFileRecompileQ :: FilePath -> Q String | ||
| readFileRecompileQ fp = addDependentFile fp >> readFileQ fp | ||
| readFileRecompileQ rawFp = do | ||
| fp <- makeRelativeToProject rawFp | ||
| addDependentFile fp | ||
| qRunIO (readUtf8FileString fp) |
Contributor
Author
There was a problem hiding this comment.
I couldn't figure out a nice way to unify these. I didn't want to make readUtf8FileString run in Q, since it didn't seem concerned with being a TH function.
snoyberg
requested changes
Apr 20, 2022
Member
snoyberg
left a comment
There was a problem hiding this comment.
LGTM. Can you bump the minor version number and add a note in the changelog?
Contributor
Author
|
Just noticed messages have the same issue, so I'll fix those too. |
This is for the same motivation as the change to template resolution, which is support for multi-project repositories.
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.
Because file embedding runs IO in the Template Haskell
Qmonad, relative file paths are resolved by the compiler's working directory. Ordinarily, this is the root of the project being built - but if the compiler is e.g. building a dependency, it can also be different.This change makes it so that template files are always embedded relative to the project that contains the code embedding them, rather than the working directory of the compiler - this means that dependencies in a multi-project codebase can embed files correctly.