Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including SVN revision of a project in C source code

How to include SVN revision of my project (not file revision) in C source code or in Makefile?

like image 661
developer Avatar asked Apr 13 '12 15:04

developer


2 Answers

We use a line like this in our makefile:

REPO_REV := $(shell svnversion -n)

That stores the revision number of the working copy into a make variable. To use it in C code, you can have your makefile use that value to define a macro on the compiler command line (something like -DREPO_REV=$(REPO_REV) for gcc).

like image 179
bta Avatar answered Nov 07 '22 20:11

bta


From the SVN book:

New users are often confused by how the $Rev$ keyword works. Since the repository has a single, globally increasing revision number, many people assume that it is this number that is reflected by the $Rev$ keyword's value. But $Rev$ expands to show the last revision in which the file changed, not the last revision to which it was updated. Understanding this clears the confusion, but frustration often remains—without the support of a Subversion keyword to do so, how can you automatically get the global revision number into your files?

To do this, you need external processing. Subversion ships with a tool called svnversion, which was designed for just this purpose. It crawls your working copy and generates as output the revision(s) it finds. You can use this program, plus some additional tooling, to embed that revision information into your files. For more information on svnversion, see the section called “svnversion—Subversion Working Copy Version Info” in Chapter 9, Subversion Complete Reference.

like image 4
Oliver Charlesworth Avatar answered Nov 07 '22 21:11

Oliver Charlesworth