Wednesday, 27 January 2010

Developing using Eclipse CDT, remote Linux server and rsync


For quite a while I used to have a huge pain in my arse — namely, programming in C++ for Linux on my Mac.

I think I said this before, but I like IDEs — especially, I like Eclipse: it saves my time and allows me to develop stuff much faster and more efficiently, it is also great when you’re learning some new code (and if you have a very large project at hands, that means pretty much all the time).

The problem was, I should still build the project on Linux. That means I was doomed to put all the sources on the network drive, which was accessible both from my Mac and from Linux server, and build it all there. Not convenient and slow. Very slow, in fact — builds were taking ages and ages. Other guys were using stuff like vim and emacs, and I didn’t find it useful at all: these tools are old, and give you next to none help when it comes to writing the code. So I kept struggling with using Eclipse in this hostile environment, until I come out with the idea, which is best of all described by these few lines of Makefile:

rsync -rvz .
ssh 'cd /path/to/project && build'

test: build
ssh 'cd /path/to/project && make test'

Now, when I finish editing the files (or want to check something) I simply do on my local machine:

 kirillov:/local/source/dir $ make test 

And voila — all sources are synchronised, built and tested! An extra benefit of this approach is that I have no object files, .d files, executable files and other useless stuff in my dev-folder (and, consequently, visible in my project). An only downside is, if your source tree is very large, rsync can take a good deal of time (that is why I’m syncing only my subproject in my real Makefile).