Jesus 'n Jim A mainly PC (some Mac) site w/Software, Computer Repair Info, How-To's on Using Computers
Technical Support 1-360-521-2060 (my business line cell)
buildnumber(cmd,c++)
Overview
2 programs which implement named file-based counters, one of which (the cmd shell batch file) can set environment variables and it can make as many counters as your environment can handle.
djgpp, and MinGW-w64 compiled executables with sources [DOS 32-bit, windows 32+64-bit]).
They can be downloaded as a single buildnumber.zip file.
It is under the GPL3 license. lsm file.
buildnumber.cmd takes as an argument the projectBaseFileName (the base filename without
the file extension or period (.) and no spaces allowed) you wish to make a counter for,
sets the environment variable _projectBaseFileName_buildnumber in Windows and using the file
"set_projectBaseFileName_buildnumber.cmd" for persistent storage in the current directory.
if no persistent file exists,
an initial number 1 is set both in the file and in the environment variable and stored.
otherwise,
a number from persistent storage which will be incremented and stored back in the file immediately
for example, call buildnumber.cmd phone laramie_project
or simply
call buildnumber phone laramie_project
purpose
this program was meant to be used with gw2.cmd, available from
http://JesusnJim.com/code/compilers/mingw.html although it could be used with make or some other form of make to augment your build process.
how to set an environment variable from your program
For those of you who were wondering how to set the environment from an
external scripting language such as Perl, TCL, VBS, C++, or anything else
with FILE I/O capability, the trick I use to set an environment variable
is to write a file that is a somename.cmd file which contains the command
@SET variablename=value
a space on the end is allowed.
the only thing which can execute a .cmd file and set the environment is
either make or the cmd shell itself. so essentially you would have to:
run your Perl script snippet to write-the-variable-batch-file from the
cmd shell via a batch file,
CALL the batch file
run your other Perl script to finish what you were doing.
so essentially, you have to split your script in half. you will have to
put in some file-based or database persistence if this variable setting
is in the middle of a loop(s). so it's going to get real slow in that
case because it's disk-bound.
The @ in front prevents it from showing on the command-line during
execution.
documentation
the files in the win\ and dos\ directory are as follows:
Tue 05/24/2011 21:12:01.54|C:\prj\buildnum\buildnum-2.0\win\32|>buildnum
buildnum - persistent named file-based counter
usage: buildnum [/?] [-[-]?] [/h[elp]] [-[-]h[elp]] [/v[er[sion]]] [-[-]v[er[sion]]] [-[-]txt] [/txt] [-[-]cmd] [/cmd] [-[-]bat] [/bat] [projectFileBaseName] [
projectFileBaseName ...]
buildnum.exe uses file-based persistent storage to implement a named counter. This particular version of the program cannot change environment variables directl
y, but the --cmd switch can make a batch file which can change an environment variable.
It takes as an argument the projectFileBaseName (the base filename without the file extension or period (.)) you wish to make a counter for and sets the buildnu
mber with either an initial number 1 or a number from persistent storage which will be incremented and stored back in the file immediately in the current direct
ory.
Examples:
buildnum -bat phone -cmd laramie_project -txt buildnum
will set _phone_buildnum.txt to a build number followed by a newline and set set_laramie_project_buildnumber.cmd to the cmd shell command required to set th
e environment variable _laramie_project_buildnumber.
buildnum phone laramie_project
will set set_phone_buildnumber.cmd to the cmd shell command required to set the environment variable _laramie_project_buildnumber and set set_laramie_proje
ct.buildnumber.cmd to the cmd shell command required to set the environment variable _laramie_project_buildnumber.
The program only read the first line and uses my atou64() to read its count and reads an integer64.
integer64 is unsigned and case insensitive. it can be hexadecimal (start with 0x), decimal (plain number or start with 0d), octal (start with 0, 0q, 0o), binar
y (start with 0b), and can be appended with SI units (_B _D _DB _H _HB _K _KB _M _MB _G _GB _T _TB _P _PB _E _EB) or computer units (_Ki _KiB _Mi _MiB _Gi _GiB
_Ti _TiB _Pi _PiB _Ei _EiB) as a multiplier suffix. priority will be given to longer suffixes.
integer64 will be converted to standard unsigned integer decimal.
This program was meant to be used with gw2.cmd, available from http://JesusnJim.com/code/compilers/mingw.html although it could be used with some form of make o
r build system that is Windows-based.
--help or --? or /help or /? will give this help and exit.
--version or --v or /v or /ver or /version will give the version number and exit.
projectFileBaseName must have no . or file extension. The following 3 switches are mutually exclusive and are modes:
--txt switches to .txt file mode where it writes a filename _projectFileBaseName.buildnumber.txt with the contents being the build number followed by a newline.
--cmd (default) switches to .cmd file mode where it writes a filename set_projectFileBaseName.buildnumber.cmd with the contents being @set _projectFileBaseName_
buildnumber= followed by the build number, a space, and a newline.
--bat switches to .bat file mode where it writes a filename _projectFileBaseName.bat with the contents being @set _projectFileBaseName_buildnumber= followed by
the build number, a space, and a newline.
Copyright 2011 Jim Michaels. Under GPL3 License.
Tue 05/24/2011 21:12:05.73|C:\prj\buildnum\buildnum-2.0\win\32|>test
Tue 05/24/2011 21:12:26.82|C:\prj\buildnum\buildnum-2.0\win\32|>cd ..
Tue 05/24/2011 21:12:42.87|C:\prj\buildnum\buildnum-2.0\win|>test
Tue 05/24/2011 21:12:47.43|C:\prj\buildnum\buildnum-2.0\win|>32\buildnum -txt buildnum -bat phone -cmd laramie_project
Tue 05/24/2011 21:12:47.56|C:\prj\buildnum\buildnum-2.0\win|>type _buildnum.txt
4096018
Tue 05/24/2011 21:12:47.56|C:\prj\buildnum\buildnum-2.0\win|>type set_laramie_project_buildnumber.cmd
@set _laramie_project_buildnumber=82000018
Tue 05/24/2011 21:12:47.57|C:\prj\buildnum\buildnum-2.0\win|>type _phone.bat
@set _phone=13
Tue 05/24/2011 21:12:47.57|C:\prj\buildnum\buildnum-2.0\win|>cd ..\dos
Tue 05/24/2011 21:15:18.26|C:\prj\buildnum\buildnum-2.0\dos|>buildnum
buildnum - persistent named file-based counter
usage: buildnum [/?] [-[-]?] [/h[elp]] [-[-]h[elp]] [/v[er[sion]]] [-[-]v[er[sion]]] [-[-]txt] [/txt] [-[-]cmd] [/cmd] [-[-]bat] [/bat] [projectFileBaseName] [
projectFileBaseName ...]
buildnum.exe uses file-based persistent storage to implement a named counter. This particular version of the program cannot change environment variables directl
y, but the --cmd switch can make a batch file which can change an environment variable.
It takes as an argument the projectFileBaseName (the base filename without the file extension or period (.)) you wish to make a counter for and sets the buildnu
mber with either an initial number 1 or a number from persistent storage which will be incremented and stored back in the file immediately in the current direct
ory.
Examples:
buildnum -bat phone -cmd laramie_project -txt buildnum
will set _phone_buildnum.txt to a build number followed by a newline and set set_laramie_project_buildnumber.cmd to the cmd shell command required to set th
e environment variable _laramie_project_buildnumber.
buildnum phone laramie_project
will set set_phone_buildnumber.cmd to the cmd shell command required to set the environment variable _laramie_project_buildnumber and set set_laramie_proje
ct.buildnumber.cmd to the cmd shell command required to set the environment variable _laramie_project_buildnumber.
The program only read the first line and uses my atou64() to read its count and reads an integer64.
integer64 is unsigned and case insensitive. it can be hexadecimal (start with 0x), decimal (plain number or start with 0d), octal (start with 0, 0q, 0o), binar
y (start with 0b), and can be appended with SI units (_B _D _DB _H _HB _K _KB _M _MB _G _GB _T _TB _P _PB _E _EB) or computer units (_Ki _KiB _Mi _MiB _Gi _GiB
_Ti _TiB _Pi _PiB _Ei _EiB) as a multiplier suffix. priority will be given to longer suffixes.
integer64 will be converted to standard unsigned integer decimal.
This program was meant to be used with gw2.cmd, available from http://JesusnJim.com/code/compilers/mingw.html although it could be used with some form of make o
r build system that is Windows-based.
--help or --? or /help or /? will give this help and exit.
--version or --v or /v or /ver or /version will give the version number and exit.
projectFileBaseName must have no . or file extension. The following 3 switches are mutually exclusive and are modes:
--txt switches to .txt file mode where it writes a filename _projectFileBaseName.buildnumber.txt with the contents being the build number followed by a newline.
--cmd (default) switches to .cmd file mode where it writes a filename set_projectFileBaseName.buildnumber.cmd with the contents being @set _projectFileBaseName_
buildnumber= followed by the build number, a space, and a newline.
--bat switches to .bat file mode where it writes a filename _projectFileBaseName.bat with the contents being @set _projectFileBaseName= followed by the build nu
mber, a space, and a newline.
Copyright 2011 Jim Michaels. Under GPL3 License.
Tue 05/24/2011 21:15:24.32|C:\prj\buildnum\BUILDN~1.0\dos|>cd ..
Tue 05/24/2011 21:15:58.84|C:\prj\buildnum\BUILDN~1.0|>buildnum
buildnumber - set build number based on project file basename, persistently
usage:
from cmd shell: call buildnumber.cmd [/?] [-[-]?] [-[-]h[elp]] [/h[elp]] [/v[er[sion]]] [-[-]v[er[sion]]] [projectBaseFileName] [projectBaseFileName ...]
from makefile: buildnumber.cmd [/?] [-[-]?] [-[-]h[elp]] [/h[elp]] [/v[er[sion]]] [-[-]v[er[sion]]] [projectBaseFileName] [projectBaseFileName ...]
this batch file uses delayed expansion to set the environment variable _projectBaseFileName_buildnumber, increment it (initially set to 1), and write it to a fi
le set_projectBaseFileName_buildnumber.cmd for the next time around as persistent storage.
Copyright 2011 Jim Michaels. Under GPL3 License.
Tue 05/24/2011 21:16:06.71|C:\prj\buildnum\BUILDN~1.0|>
I can't use gw2.cmd because of a dependency issue. well, I still could use gw2 since the buildnumber is embedded inside gw2 now.