Git describe build dependency

I use git describe --tags --dirty --long to get a string that is used in my library as const char [] to find out (for example, by printing) git -revision when it has only binary code.

I am creating a file (gitref.c) that compiled with all other files. I recently realized that when I change the git revision in my clone and then restart the gitref.c build gitref.c , it does not regenerate. This is normal - there is no addiction.

I found out that dependency on .git / HEAD is a good start, and works in most cases. Is this addiction enough? If not, what is the way to add a dependency (file-)?

EDIT : Thanks @BenJackson: when tagging this is not enough - HEAD does not change.

+4
source share
1 answer

IMHO, the only solution to this is to consider this file always deprecated with a fake dependency. Every time you compile, it must be restored. A slightly more elegant solution is to always generate gitref.c.tmp and then copy it to gitref.c only if the files are different (for example, in * NIX, as a system, you can use cmp to compare them byte-by-bye). If they match, just delete the temporary file.

EDIT : the following Makefile snippet works for me

 PHONY: gitref_dummy gitref_dummy: gitref.c: gitref_dummy @echo "const char *gitref = \"$$(git describe --tags --dirty --long)\";" > \ gitref.c.tmp @cmp -s gitref.c.tmp gitref.c || \ (echo "Updating gitref.c"; mv gitref.c.tmp gitref.c) @rm -f gitref.c.tmp 
+1
source

All Articles