Auto Assembly ID

We are looking for a way to include some kind of assembly identifier automatically in our assemblies. This should be portable (VC ++, g ++ on Linux and Mac) and automatic. VC ++ is the most important thing, because in other environments we use our own Python build scripts so that I can do whatever I want.

We use SVN, so we are considering using svnversion output to write the revision to the header and include it. This has problems: if we put the file in SVN, it will appear as changed every time, but it will be an unnecessary commit and, in a sense, generates an endless cycle of increasing revisions. If we don’t put the file in SVN and just create it as a pre-build step, the sources will not be complete, because creating this file will require a preliminary collection or Makefile.

We can also use __DATE__ , but we cannot guarantee that a file that uses __DATE__ (i.e. writes it to a log file) will be compiled if any other file is modified - unless we “touch” it, but then we will make the project always out of date. We could touch it as a pre-build step, so it will be affected only if the rest of the project is out of date, therefore it does not cause false compilation, but if VC ++ calculates the dependencies before the pre-build step, it won’t work (file with __DATE__ will not be compiled)

Any interesting ideas?

+6
c ++ svn visual-c ++ visual-studio
source share
6 answers

We use svnversion output written to the header file and included. We omit the file from the repository and create it at the pre-build stage; it worked for us. (I'm not sure why you mind using the pre-build phase?)

We are currently using a Perl script to convert svnversion output to a header file; Later I learned that TortoiseSVN includes a subwcrev command (which was also ported to Linux) that can do most of the same.

+9
source share

If you don't like the idea of ​​including the file outside the source control that you need for the build, consider a batch file or other build step that programmatically creates the / include file and invokes svnversion in your build process.

basically GENERATE so that the file is not converted or required.

EDIT Probably the best idea is Josh subwcrev.

Before this was implemented, I wrote my own hacked tool to do the same - replace the template file.

+4
source share

It could be that simple:

 % make -DBUILD_NUMBER=`svnlook youngest /path/to/repo` 
+3
source share

I would watch SvnRev . You can use it as a custom pre-build step in VS, or call it from a makefile or something else you need to do, and it generates a header file that you can include in other files that will provide you with what you need There is good documentation on the site.

SubWCRev is another option, although the Linux port is newer, and I don’t know that there is a Mac version. This is very useful for Windows for .NET (which I guess is not a problem for you, but I am adding this for future reference) because it allows you to create a template file that you can use to generate, for example, a properties file for the assembly. NET

+2
source share

Automated assemblies can usually be complete, clean. In this case, you start in a clean directory, and in any case, problems with __DATE__ will not arise. Otherwise, see Paul Beckinam's Idea.

0
source share

Why not bind a GUID to it, almost every language has support for creating it, or if you don’t have one, there are algorithms for this.

(Although if you are using subversion, I personally like Josh's idea!)

-one
source share

All Articles