A feature I've been missing in visual C++ (well v6 at least, don't know about 7) is hardcoding a build number in the program that automatically increments each time it is build. MASM of course lacks this feature as well.
So I coded a little tool that reads a small text configuration file, increments the build number and writes a COFF object file (.obj) with two (or one, depending on the configuration) symbols which you can use in your program like this:

extern current_build_value:DWORD
extern current_build_string:BYTE

current_build_value is simply a dword containing the version number. current_build_string is a null terminated string of which the format depends on the configuration file.

The configuration file looks like this:

build_string=Build #%n on %d %t.

(note: the lines have to start with 'setting=' in that form, no spaces. After the = sign, spaces are allowed. Also, all lines without settings are ignored and removed when the file is updated).

current_build is the current build number. This value is automatically incremented. If it's ommitted, a warning is shown and the value is set to 1.

build_value can be 0 or 1 (or any number actually). If it's 0, the current_build_value symbol is not included in the object file. If it's not 0, the symbol is included. If the setting is omitted, it defaults to 0. When the setting is 0, it will be removed when the config file is updated.

build_string is the format for the current_build_string symbol. If it's omitted, the symbol is not included in the object file. Otherwise, the string is used to format the symbol string. Three special characters can be used: %n for the current build number, %d for the current date (yyyy-mm-dd), %t for the current time (hh:mm:ss).

Furthermore, bnsym has a few command line options:

[b]-c [config file][/b]
Specifies the configuration file to use. If ommitted, it defaults to bnconfig.dat.

[b]-o [output file][/b]
Specifies the output file to use. If ommitted, it defaults to bn_data.obj.

Silent mode. Only shows errors.

The program is still a beta version and some things have to be done yet (like a /? option) but it's working.

Finally, I have a question for VC users: I tried to run the tool automatically on each build using the pre-link step. However, when incremental linking is used, it doesn't use the new object file, but sticks with what it had already. Is there a way around this? Even if I delete the object afterwards, it still uses an old one. The only way to use the new object file is to do a full link.


edit: updated attachment, fixed a small bug concering the build time.

edit2: attachment removed, fixed timestamp bug, see my second post.
Posted on 2002-07-06 07:25:54 by Thomas
I think you can add the .obj as an "external dependency" or sth...
I had a similar problem, but I think I eventually found out how to
fix it by messing a lot around with build rules :)
Posted on 2002-07-06 09:06:17 by f0dder
Great work, Thomas. I've been thinking of making something like this a long time ago, but never got around to it.
Posted on 2002-07-06 09:57:04 by comrade
I already found the problem, my tool always sets the .obj's timestamp to zero. So the linker couldn't tell if it had changed.
I fixed it, the new version is in the attachment below.

Posted on 2002-07-06 11:15:05 by Thomas
lol, i just made a program that will read a ini file and increase the number in it and then save it. its ran when i use the .bat to compile my project, all i have to do is read the ini file and change the build number to the one in the ini file next time.
Posted on 2002-07-06 11:18:08 by Qages