-
Notifications
You must be signed in to change notification settings - Fork 696
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 #9899
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
synopsis: Add pre and post build hooks | ||
packages: cabal-install | ||
prs: #9899 | ||
issues: #9892 | ||
significance: significant | ||
|
||
description: { | ||
|
||
- Run a program (named "preBuildHook") before doing a package build and another program | ||
(named "postBuildHook") after the package is built. | ||
- These programs are project local and need to be in the `cabalHooks` directory which is | ||
in the same directory as the `cabal.project` file. | ||
- The absence of these programs will be ignored. | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
Build Hooks | ||
=========== | ||
|
||
Build hooks are programs that are run before (pre-build hook) and | ||
after (post-build hook) a package (including package dependencies) | ||
is built. The hooks are completely generic and can even be absent | ||
(their absence is ignored). Regardless of the return code of the | ||
pre-build hook, the normal build is executed. In the case where | ||
the pre-build hook provides a pre-built version of what the build | ||
step would provide, the build step is still run, but should be | ||
little more than a NOOP. | ||
|
||
Build hooks are project local rather than global to the user | ||
because a single user may want to use one set of hooks in one | ||
project and another set of hooks (or even none at all) for another | ||
project. | ||
|
||
|
||
Possible Use Cases | ||
------------------ | ||
|
||
Possible use cases include: | ||
|
||
* Fine grained benchmarking of individual package build times. | ||
* Build product caching. | ||
|
||
|
||
Location of Hook Files | ||
---------------------- | ||
|
||
The two hook files are `cabalHooks/preBuildHook` and | ||
`cabalHooks/postBuildHook` where the `cabalHooks` directory is in | ||
the same directory as the `cabal.project` file. On UNIX style | ||
systems, these hooks need to be marked as user executable programs. | ||
|
||
|
||
Hook Parameters Exit Codes | ||
-------------------------- | ||
|
||
The pre-build hook is passed three parameters; the unit id (from cabal), | ||
the source directory and the build directory. The post-build hook is | ||
passed the same three parameters, plus the exit code of the pre-build | ||
hook. | ||
|
||
The exit codes for the two hooks are ignored by cabal apart from cabal | ||
capturing the exit code for the pre-build hook and passing it to the | ||
post-build hook. | ||
|
||
|
||
Security Considerations | ||
----------------------- | ||
|
||
These build hooks are generic executable programs. They can potentially | ||
be malicious. For example, one might clone a Haskell project from | ||
say Github, that includes malicious build hooks so that when the user runs | ||
`cabal build all` these hooks will be run as the user. The most obvious | ||
malicious behaviour would be to delete all the user's files. | ||
|
||
For this reason, it is highly advisable to check for the existence | ||
of and the contents of any build hook files. |
This file contains 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
Oops, something went wrong.
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.
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.
I argue we should. The author of the script can always hide errors of whatever commands they're executing inside the hook.
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.
What would you propose?