Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatic build ID

We're looking for a way to include some sort of build ID automatically in our builds. This needs to be portable (VC++, g++ on Linux and Mac) and automatic. VC++ is what matters most, since in the other environments we use custom Python build scripts so I can do whatever I want.

We use SVN, so we were looking at using the output of svnversion to write the revision to a header and include it. This has problems : if we put the file in SVN, it will appear as modified every time, but it would be a superfluous commit and in a sense generate an infinite loop of increasing revisions. If we don't put the file in SVN and just create it as a pre-build step, the sources wouldn't be complete, as they'd need the pre-build step or Makefile to generate that file.

We could also use __DATE__ but we can't guarantee the file that uses the __DATE__ (ie writes it to a log file) will be compiled if some other file is modified - except if we "touch" it, but then we'd cause the project to be always out of date. We could touch it as the pre-build step, so it would get touched only if the rest of the project is out of date, thus not causing a spurious compile, but if VC++ computes the dependencies before the pre-build step, this wouldn't work (the file with __DATE__ won't get compiled)

Any interesting ideas?

like image 645
ggambett Avatar asked Jan 02 '09 15:01

ggambett


People also ask

Can I automatically increment the file build version when using Visual Studio?

By default, Visual Studio automatically increments the Revision number of the Publish Version each time you publish the application. You can disable this behavior on the Publish page of the Project Designer.

What is a build number in Linux?

The build number is simply the value contained in the build number file, which is extracted using the standard cat command. The first command checks to see if the build number file exists. If it doesn't a single line of text, a zero is written to it.

How do I change the version number in Visual Studio?

Open the project's Property Pages dialog box. For details, see Set C++ compiler and build properties in Visual Studio. Select the Configuration Properties > Linker > General property page. Modify the Version property.


1 Answers

We're using the output of svnversion, written to a header file and included. We omit the file from the repository and create it in a pre-build step; this has worked quite well for us. (I'm not sure why you object to using a pre-build step?)

We're currently using a Perl script to convert svnversion's output into a header file; I later found out that TortoiseSVN includes a subwcrev command (which has also been ported to Linux) that can do much of the same thing.

like image 135
Josh Kelley Avatar answered Sep 28 '22 01:09

Josh Kelley