Build/Uplaod event handler

I would like to have some way how to do something (run script) before/after build or before/after upload. I mean something similar to hooks in git or svn.

There could be these four:

pre-build – run script before build. If result is not 0 stop otherwise continue to build. E.g.: increment version (build) number in the code, check something in code, etc.

post-build – run script if compiler succeeded. E.g.: commit code to versioning system.

pre-upload – run script before upload. If result is not 0 stop otherwise continue to upload. E.g.: kill some external program that use serial port.

post-upload – run script if upload succeeded. E.g.: run some external program that communicates with Arduino over serial port and do something with it.

I think this is not possible right now or do I miss something?

There is at least a post-build hook used by the Teensy uploader. I don't know much about it.