-
Notifications
You must be signed in to change notification settings - Fork 704
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
Add pre and post build hooks #10799
base: master
Are you sure you want to change the base?
Add pre and post build hooks #10799
Conversation
d48220c
to
815c21e
Compare
concat | ||
[ "The following file does not appear in the hooks-security file.\n" | ||
, " hook file : " | ||
, fpath | ||
, "\n" | ||
, " file hash : " | ||
, hash | ||
, "\n" | ||
, "After checking the contents of that file, it should be added to the\n" | ||
, "hooks-security file with either AcceptAlways or better yet an AcceptHash.\n" | ||
, "The hooks-security file is (probably) located at: " | ||
, hsPath |
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.
How does this line look? Can you print a command that likely inserts the right value?
> echo "..." >> hsPath
?
3853088
to
5f7b47f
Compare
t seems to me this approach is very overfitted to a particular usecase. Why are there pre/post hooks on just the build phase, why not the haddock phase or the test phase for example? Why are the particular options chosen to be passed to the script? Therefore I don't think this should be merged into cabal in the current state. If this approach is to be taken then I think a broader community consensus needs to be arrived at. In order to solve the problems mentioned in the ticket I would supply a wrapped GHC which could answer queries to --make a package by downloading relevant files from a cache and placing them into the output directory. If this is operating on a company specific cache, the GHC provided by the nix-shell to developers can already be wrapped to support fetching from the cache. It will also work uniformly with all the other commands which may build things rather than overfitted to the build phase. It also means that ALL the relevant options are passed to the wrapper rather than only a few. If the approach of committing a wrapper to the repo for all to use is preferred then the wrapper should accept the configured ghc to be used as the first argument, so invocations look like
@mpickering Sorry, by mistake I edited your comment rather than responding to it (did not even know I could do that). Hopefully I have restored it. |
More can be added if needed. Its trivial.
We did have a "wrapper" solution that did a cabal build all --dry-run and then inspected the plan.json file. That solution was considerably slower (about 50%) than this solution. |
@mpickering, thanks for the feedback—I appreciate it. You're suggesting wrapping GHC for file-level caching across all build commands, which makes sense. However, I believe Cabal is the right place for package-level hooks, as it manages package orchestration (e.g., fetching from Hackage). These hooks are generic, supporting use cases beyond caching, like build-time profiling. That said, the current implementation is limited (build phase only, specific options). I'm open to discussing:
I agree broader consensus is needed before merging. Happy to collaborate further—looking forward to your thoughts! |
@mpickering Adding hooks for the "haddock" and "test" phases seems to provide very little utility above your "wrapper" suggestion for the "build" phase. Neither the "haddock" nor the "test" phases have anywhere near the complexity of the "build" phase. What we get by hooking the "build" phase is direct access to the Yes , this |
d5a3b9c
to
bfecc42
Compare
Why are these yet more magic named files rather than being specified in the |
Three reasons:
|
bfecc42
to
755e002
Compare
Run a program (named "preBuildHook") before doing a package build and another program (named "postBuildHook") after the package is built. The exit code from the pre-build hook is passed to the post-build hook. The commit includes documentation for the hooks and the security safeguards implemented to avoid the running of malicious hook files.
755e002
to
39ec78c
Compare
Work to do:
|
These are currently the extension mechanisms to the cabal ecosystem (which I know about).
This PR, proposes a 4th means of extension, "build hooks" to run in "cabal-install" just before PBBuildPhase. What are the motivations for "build hooks" over the existing mechanisms?
Therefore, could we instead consider a design which augments 2 or 3 in a way which allows local modification. Another alternative designAllow a project to contain a component containing
SummaryOtherwise, It seems hard to justify how another extension point at exactly the same place as custom setup and hooks. If you observe the current implementation, the hooks run immediately before I think steps to moving this project forward are
Personal opinionMy personal opinion, is that
|
Here's another way to think about it: Remember that Cabal distinguishes the role of package author vs package builder. So lets look at the existing hooks in that light @mpickering lists:
So 2 & 3 are for the package author. 1 is for the package builder. The proposal here is also for the package builder. I think it's not crazy to have hooks designed for the package builder. And perhaps 1 is not sufficient. However, I think it should be coherent with the rest of the package builder design. We have a If we have a single root to start from (and then specify or include other files) then we have a much better handle on what is going on. Spreading things out over random magic file names makes it very hard for users who are not intimately familiar with the latest cabal to figure out what is going on, or where they should edit things, or where to find out where they should edit things. An explicit link from the |
Idea, in the
This gives us extension points for the future. We can add more hooks. We can add more attributes to control how/when/whatever the hooks are executed. We can arrange for it to support conditional syntax if that ever becomes necessary. etc. And it's all explicit and discoverable. At least, one can see that a project is using it. And other |
Thank you for shaking up the design of this new feature. Shall I copy some of this discussion to the actual design ticket for others to see, with a back-link, e.g., maybe this summary #10799 (comment)? |
@Mikolaj I think the summary misses some crucial observations from @dcoutts. Let me try to come up with a summary with @erikd that included @mpickering's and @dcoutts's comments. |
Run a program (named "preBuildHook") before doing a package build and another program (named "postBuildHook") after the package is built. The exit code from the pre-build hook is passed to the post-build hook.
The commit includes documentation for the hooks and the security safeguards implemented to avoid the running of malicious hook files.
A previous version of this functionality but without the hook security features was submitted in #9899 .
Please read Github PR Conventions and then fill in one of these two templates.
Include the following checklist in your PR:
significance: significant
in the changelog file.