blah blah blah is here! blah blah » Close

up1down
link

This question is in the context of ANSI C. Is there a method to automate tracking of the build? I'd like to have access to the build number at runtime. As of now I have to manually edit a define statement like so:

#define BUILD_NUMBER 1703


Obviously I can't do this every time I rebuild a project. So the next thought is to write a simple application that reads in the build from a simple header file, increments it and writes it back to the file. This application would then be called using a pre-build hook. That's the best I can do at automating this task but I was wondering if there was something much simpler that I was overlooking. I realize this answer might be specific to the development environment so I guess I am looking for a fairly general answer.

last answered one year ago

1 answers

link

The only features which ANSI C has which might be helpful are the predefined __DATE__ and __TIME__ macros which give the date and time of the current build.

A fairly simple way of proceeding would be to create a text file in the application directory containing a table which associated a build number with the date and time of compilation.

You'd then need a standard function which was always called first from your main() or dllmain() function. This function would read the text file and, if there were no build number associated with the current date/time of compilation, it would increment the last build number used and add a new entry to the table.

If there had been no previous builds, then this function could of course create the text file and add the first entry.

You'd then need another standard function to read the current build number from the file as and when needed. Alternatively, the first function could be written to return the build number which you could then cache in a global variable.

An advantage of this system is that you'd have a full history of previous builds. You could also retain and run earlier builds without upsetting the system.

However, if you'd prefer something more sophisticated, then I'm sure somebody will have written an automated tool for whatever compiler/IDE you're using or, of course, you could use a version control system.

eeboy
499

Thanks! I am using SVN but I would not consider myself an advanced user. Does SVN have a utility that allows for this functionality?

vulpes
17279

I'm no SVN expert either but it appears that you can get a 'release' number for each file in the project but not for the project as a whole. I found an article on Code Project (http://www.codeproject.com/KB/architecture/svn_visual_studio.aspx) which shows how you can get a 'top level' revision number but, frankly, I prefer the simpler solutions we've already come up with.

Feedback