version.cmd 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. @rem Set default version in case git isn't available.
  2. set description=0.0-0-prerelease
  3. @rem Get canonical version from git tags, eg v2.21-24-g2c60e53.
  4. for /f %%v in ('git describe --tags --long') do set description=%%v
  5. @rem Strip leading v if present, eg 2.21-24-g2c60e53.
  6. set description=%description:v=%
  7. set version=%description%
  8. @rem Get the number of commits and commit hash, eg 24-g2c60e53.
  9. set n=%version:*-=%
  10. set commit=%n:*-=%
  11. call set n=%%n:%commit%=%%
  12. set n=%n:~0,-1%
  13. @rem Strip n and commit, eg 2.21.
  14. call set version=%%version:%n%-%commit%=%%
  15. set version=%version:~0,-1%
  16. @rem Find major and minor.
  17. set minor=%version:*.=%
  18. call set major=%%version:.%minor%=%%
  19. @rem Build flags.
  20. set flags=0L
  21. @rem Don't include n and commit if we match a tag exactly.
  22. if "%n%" == "0" (set description=%major%.%minor%) else set flags=VS_FF_PRERELEASE
  23. @rem Maybe we couldn't get the git tag.
  24. if "%commit%" == "prerelease" set flags=VS_FF_PRERELEASE
  25. @rem Ignore the build number if this isn't Jenkins.
  26. if "%BUILD_NUMBER%" == "" set BUILD_NUMBER=0
  27. @rem Copyright year provided by Jenkins.
  28. set md=%BUILD_ID:*-=%
  29. call set year=%%BUILD_ID:%md%=%%
  30. set year=%year:~0,-1%
  31. if "%BUILD_ID%" == "" set year=
  32. @rem Create version.h.
  33. @echo>version.h.new #define NSSM_VERSION _T("%description%")
  34. @echo>>version.h.new #define NSSM_VERSIONINFO %major%,%minor%,%n%,%BUILD_NUMBER%
  35. @echo>>version.h.new #define NSSM_DATE _T("%DATE%")
  36. @echo>>version.h.new #define NSSM_FILEFLAGS %flags%
  37. @echo>>version.h.new #define NSSM_COPYRIGHT _T("Public Domain; Author Iain Patterson 2003-%year%")
  38. fc version.h version.h.new >NUL: 2>NUL:
  39. if %ERRORLEVEL% == 0 (del version.h.new) else (move /y version.h.new version.h)