Question

I'd like to embed the Git revision (SHA1) in my executables at build time. I can do it locally like this:

 git log -1 --format='%h' >version
 objcopy --input binary --output elf64-x86-64 version version.o
 # link version.o into the executable

The problem is, I'm using NetBeans (on Windows) to build remotely (on Linux). It's a bit of a paradox: the git command seems to need to run on the local machine (where the source is), but the objcopy command needs to run on the remote server (where the build happens). This is a problem because while NetBeans does let me edit the project's Makefile to insert a pre-build step, I can't figure out how or where to put the git command so that it runs on the local machine before the remote build steps.

I tried making a separate NetBeans project to run the git command on localhost, thinking that I'd then make the "real" project depend on that, but NetBeans doesn't seem to allow me to create a project that "does nothing" (i.e. it has no source files, and does not produce a library nor an executable--it would only generate the version text file).

I'm using NetBeans 7.3 for C++ with the "Automatic Copying" option for remote builds. A possible solution might be to use the NFS/Samba mode with the Git repository stored on the server, but that would be fairly disruptive because the project has multiple developers using Automatic Copying for a long time already. So it would be great to have a solution to generate some files locally in NetBeans before starting the remote build.

Was it helpful?

Solution

One solution would be to have that version file already up-to-date when you launch your Netbeans job.

A post-commit hook could generate that file at the right place, for your Netbean job to read.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top