Author Topic: Integrating svnversion into the build process  (Read 6035 times)

Crypticode

  • Guest
Integrating svnversion into the build process
« on: June 15, 2006, 04:34:08 pm »
Hi, could someone explain me how i can do this:

http://subversion.tigris.org/faq.html#version-value-in-source

in Code::Blocks ? I dont get it right ... :/

Thanks in advance

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Integrating svnversion into the build process
« Reply #1 on: June 15, 2006, 04:58:18 pm »
You can use a keyword such as $Revision$ anywhere in your sources and set the svn:keywords property accordingly, then Subversion will replace that string with the current revision.

This can be done inside any source file or the makefile, you can then do whatever you want... use string manipulation in your source, or feed it to some tool (sed?) from inside the makefile... whatever.
Note that the revision shown will be the revision of the file that contains the keyword, this is not necessarily HEAD.

Another way is to call svn info from the makefile or from a special tool and extract the revision from the output. This is more complicated but always accurate.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Crypticode

  • Guest
Re: Integrating svnversion into the build process
« Reply #2 on: June 15, 2006, 05:04:56 pm »
Thanks...

Quote
Note that the revision shown will be the revision of the file that contains the keyword, this is not necessarily HEAD.

If you only had read the link i provided... i want to know HOW i can call the program svnversion.exe from within the makefile code::blocks generates... Please read the link and tell me your suggestions again, cause i failed in setting these 2 -Defines in every way i tried :(

Crypticode

  • Guest
Re: Integrating svnversion into the build process
« Reply #3 on: June 15, 2006, 05:24:51 pm »
Oops, never mind. It works now, simply with backticks.

@ All who care...
If you have Subversion installed on your system just add the following to "Build Options/Other options" for your Target:

Code
-DSVN_REV=`svnversion -n .`

You can then use the extracted Revision number in your program like:

Code
#define _STR(x) #x
#define STR(x) _STR(x)

printf("Revision: %s\n", STR(SVN_REV))


Note that the revision string is "extracted" when your Project folder is no "working SVN copy"

:D
« Last Edit: June 15, 2006, 05:27:30 pm by Crypticode »

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Integrating svnversion into the build process
« Reply #4 on: June 15, 2006, 05:29:53 pm »
I did read that. svnversion is another tool that can be used instead of svn info.

It is the same thing, except that svn info runs about 10 times faster, which is why I prefer it.

What they do in that example is nothing more but echo some C code into a file (with output redirection) and run svnversion -n in backticks during that.
This will produce a souce file with code that looks like char *SVN_version = "12342";
There is no deep magic behind that :)

The defines are another way of doing it, but are not needed if you produce the source file. I don't know about the $(shell ...) syntax, but a guess would be that you need to replace "shell" with "sh" or "bash". If it were me, I'd use the other solution, it confirmedly works without any problems.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."