Rebuild code automatically with "watch" and a makefile
scott.mn
scott.mn
Equivalent and no special tool required:
while true; do make all; sleep 1; done
One problem that becomes apparent with a longer interval and longer rebuild times: if the make takes say 30s, and you're rebuilding every 60s, then your site will be updated every 1.5 minutes instead of every minute. Maybe not what you want.A program you should really check out is trigger-listen [1]. It can run a command every minute regardless of how long the command takes to complete (as long as it takes < 1min). You can also trigger a rebuild whenever you want by writing a byte into a fifo. I use it to rebuild static sites when a certain branch is updated -- just do a trigger-pull in your git post-receive hook.
Easy enough to fix without resorting to a specialized tool:
while true; do make all & sleep 1m; done
(Changing the sleep to a minute instead of a second, which may have been what you intended.)That way you'll kick off a 'make all' once per minute regardless of how long it takes. That in turn might not be what you want if your make takes more than a minute, but then it's also simple enough to extend it thusly:
while true; do make all & sleep 1m & wait; done
which will do the same but avoid having multiple makes running concurrently (if a minute elapses and the previous invocation hasn't finished yet, it waits for it before starting the next one). while true; do make all & sleep 1m; done
Welcome to orphan land. (^C to see.) Don't do this folks. The 'make all' invocations may also potentially overlap and corrupt your builds. To be fair, you fixed that issue here: while true; do make all & sleep 1m & wait; done
But the orphan issue remains. watch:
while true ; do inotifywait -qe close_write $(SRC); $(MAKE) ; done $ make watch &
$ vim
Or do you use separate screens? while inotifywait -qe close_write $(SRC); do $(MAKE); done * http://entrproject.org/
* https://bitbucket.org/eradman/entr/Created a tap for it on homebrew if anyone wants to use it.
brew tap mitchty/entr if you want to test it out.
It tweaks the PATH for child processes so recursive make invocations should work.
I've been lazy and not put yet made an npm package (it's implemented in node.js) or tested cross-platform. Guess I've no reason to be bored tomorrow.
https://github.com/alandipert/fswatch
It uses Mac APIs to monitor the file system and executes your command when it changes.
While computers have become a lot more stable, I still like to save often, and this kind of setup eventually makes you feel less like you want to save.
E.g. in a makefile [2] for http://countw.tf/ (a great way to vent while exploring an old codebase with many err... sub-optimal choices)
debug:
browserify site/scripts/app.js -o site/scripts/app-built.js --debug
watch:
supervisor --watch site/scripts --ignore site/scripts/app-built.js --no-restart-on exit --exec make debug
1: https://github.com/isaacs/node-supervisor watch -d -n 5 "curl -s localhost:8080/some/service | grep status"
Along the same lines as the original post, I also use watch as an ad hoc, pseudo continuous integration tool for executing code that doesn't fit well within a REPL. [1][1] http://codeaweso.me/2012/09/using-watch-as-quick-continuous-...
It's quite similar to watchr in ruby-land, but the executable is easier to use without creating a config file.