Including Git commit-id as string inside C files
Code: https://github.com/google/honggfuzz/commit/2310ab5f6954cbe4ebaca25ca0a52c72bd4103c5
Including contents of a text-file as a string in C is not that easy, esp. if it's not surrounded by quotes. One cannot simply write
static const char str[] =
#include "file"
;
and static const char str[] = "
#include "file"
";
will not work either.If you know of a better (cleaner/shorter/less-hacky) way of doing this, and w/o external scripts/bins like `xxd -i` please let me know.
2 comments
[ 1.8 ms ] story [ 18.1 ms ] threadcc -D GIT_COMMIT=\"`git log --format="%H"`\" test.c
- Add this to your .gitattributes file (https://git-scm.com/docs/gitattributes):
- Add this string to the file: - Commit the change AND check out the file.- The string will be changed to: