Browse Source

Generate version information as part of the build.

Use git (if it's available) to create a major and minor version number
based on the most recent tag name.  If we are not building from a
tagged commit, use the commit count since the last tag as the subminor
version.  If Jenkins is being used for the build, use the build number
as the subsubminor version.
Iain Patterson 9 years ago
parent
commit
44e85d48df
3 changed files with 42 additions and 3 deletions
  1. 1 3
      nssm.h
  2. 8 0
      nssm.vcproj
  3. 33 0
      version.cmd

+ 1 - 3
nssm.h

@@ -21,9 +21,7 @@ void strip_basename(TCHAR *);
 int usage(int);
 
 #define NSSM _T("nssm")
-#define NSSM_VERSION _T("2.21")
-#define NSSM_VERSIONINFO 2,21,0,0
-#define NSSM_DATE _T("2013-11-24")
+#include "version.h"
 
 /*
   Throttle the restart of the service if it stops before this many

+ 8 - 0
nssm.vcproj

@@ -30,6 +30,8 @@
 			>
 			<Tool
 				Name="VCPreBuildEventTool"
+				Description="Setting version information"
+				CommandLine="version.cmd"
 			/>
 			<Tool
 				Name="VCCustomBuildTool"
@@ -122,6 +124,8 @@
 			>
 			<Tool
 				Name="VCPreBuildEventTool"
+				Description="Setting version information"
+				CommandLine="version.cmd"
 			/>
 			<Tool
 				Name="VCCustomBuildTool"
@@ -215,6 +219,8 @@
 			>
 			<Tool
 				Name="VCPreBuildEventTool"
+				Description="Setting version information"
+				CommandLine="version.cmd"
 			/>
 			<Tool
 				Name="VCCustomBuildTool"
@@ -306,6 +312,8 @@
 			>
 			<Tool
 				Name="VCPreBuildEventTool"
+				Description="Setting version information"
+				CommandLine="version.cmd"
 			/>
 			<Tool
 				Name="VCCustomBuildTool"

+ 33 - 0
version.cmd

@@ -0,0 +1,33 @@
+@rem Set default version in case git isn't available.
+set description=0.0-0-prerelease
+@rem Get canonical version from git tags, eg v2.21-24-g2c60e53.
+for /f %%v in ('git describe --tags --long') do set description=%%v
+
+@rem Strip leading v if present, eg 2.21-24-g2c60e53.
+set description=%description:v=%
+set version=%description%
+
+@rem Get the number of commits and commit hash, eg 24-g2c60e53.
+set n=%version:*-=%
+set commit=%n:*-=%
+call set n=%%n:%commit%=%%
+set n=%n:~0,-1%
+
+@rem Strip n and commit, eg 2.21.
+call set version=%%version:%n%-%commit%=%%
+set version=%version:~0,-1%
+
+@rem Find major and minor.
+set minor=%version:*.=%
+call set major=%%version:.%minor%=%%
+
+@rem Don't include n and commit if we match a tag exactly.
+if "%n%" == "0" set description=%major%.%minor%
+
+@rem Ignore the build number if this isn't Jenkins.
+if "%BUILD_NUMBER%" == "" set BUILD_NUMBER=0
+
+@rem Create version.h.
+@echo>version.h #define NSSM_VERSION _T("%description%")
+@echo>>version.h #define NSSM_VERSIONINFO %major%,%minor%,%n%,%BUILD_NUMBER%
+@echo>>version.h #define NSSM_DATE _T("%DATE%")