This is a really quick and dirty hack I devised to increment the build number for a plugin each time I compile it.
To start, a Windows batch file is required with the following:
Code:
@echo off
setlocal ENABLEDELAYEDEXPANSION
REM This will get the build number and increment it.
FOR /F "tokens=3 delims= " %%x in (%1) DO (
set /a buildno=%%x+1
echo New build number: !buildno!
)
REM Write a text file with the new number.
set output=#define PLUGIN_BUILD !buildno!
echo !output!>%1
endlocal
The steps this performs are as follows:
1. Opens up a file as defined in the first argument to the batch script (%1).
2. Reads the file to get the current version number. This assumes that there is one line in the file formatted:
#define PLUGIN_BUILD x
3. Increments the build number and echoes it to stdout.
4. Outputs the build number back into the same file, overwriting it.
All you need to do then is to create a file (I've called it
pluginbuild.inc) and paste the following line into it:
Code:
#define PLUGIN_BUILD x
Replace x with your desired build number. Include
pluginbuild.inc wherever you need it and use PLUGIN_BUILD wherever you need to insert the build number.
I use it as a parameter for a more general define:
OOPS. Just found out the following line doesn't work because PLUGIN_BUILD is read verbatim. You can still use PLUGIN_BUILD to format strings etc. though.
Code:
#define PLUGIN_VERSION "1.0.0.PLUGIN_BUILD"
On compile (I use the NppExec plugin for Notepad++), set the batch file to run immediately after spcomp.exe and specify the file you want to update as the argument to the script. My NppExec config is:
Code:
"C:\srcds\tf\tf\addons\sourcemod\scripting\spcomp.exe" $(FULL_CURRENT_PATH)
$(CURRENT_DIRECTORY)\increment_version_on_compile.bat $(CURRENT_DIRECTORY)\pluginbuild.inc
Which produces the output:
Code:
"C:\srcds\tf\tf\addons\sourcemod\scripting\spcomp.exe" C:\path\to\plugin\pluginfile.sp
Process started >>>
SourcePawn Compiler 1.5.3
Copyright (c) 1997-2006, ITB CompuPhase, (C)2004-2008 AlliedModders, LLC
Header size: 7000 bytes
Code size: 72644 bytes
Data size: 14656 bytes
Stack/heap size: 16384 bytes; Total requirements: 110684 bytes
<<< Process finished. (Exit code 0)
C:\path\to\plugin\increment_version_on_compile.bat C:\path\to\plugin\pluginbuild.inc
Process started >>>
New build number: 3
<<< Process finished. (Exit code 0)
================ READY ================
Then my build number is incremented automatically after each compile, stopping me from having to do it myself (which I never remember to do).