2015-08-04 21:52:48 +00:00
|
|
|
::@echo off
|
|
|
|
:: This file GENERATES the automatic GIT revision/version tag.
|
|
|
|
:: It uses the git.exe program to create an "svnrev.h" file for whichever
|
|
|
|
:: project is being compiled, during the project's pre-build step.
|
|
|
|
::
|
|
|
|
:: The git.exe program is part of the msysgit installation.
|
|
|
|
::
|
|
|
|
:: MsysGit can be downloaded from http://msysgit.github.io/
|
2022-11-25 22:18:20 +00:00
|
|
|
::
|
2015-08-04 21:52:48 +00:00
|
|
|
:: Usage: preBuild.cmd ProjectSrcDir VspropsDir
|
|
|
|
::
|
|
|
|
:: ProjectSrcDir - $(ProjectDir)\.. - Top-level Directory of project source code.
|
|
|
|
|
2022-01-21 14:05:13 +00:00
|
|
|
SETLOCAL ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
|
2015-08-04 21:52:48 +00:00
|
|
|
|
2015-09-11 23:20:23 +00:00
|
|
|
IF EXIST "%ProgramFiles(x86)%\Git\bin\git.exe" SET "GITPATH=%ProgramFiles(x86)%\Git\bin"
|
|
|
|
IF EXIST "%ProgramFiles%\Git\bin\git.exe" SET "GITPATH=%ProgramFiles%\Git\bin"
|
|
|
|
IF EXIST "%ProgramW6432%\Git\bin\git.exe" SET "GITPATH=%ProgramW6432%\Git\bin"
|
|
|
|
IF DEFINED GITPATH SET "PATH=%PATH%;%GITPATH%"
|
2015-08-04 21:52:48 +00:00
|
|
|
|
2024-01-07 09:36:40 +00:00
|
|
|
git describe --tags > NUL 2>NUL
|
|
|
|
if !ERRORLEVEL! EQU 0 (
|
|
|
|
FOR /F %%i IN ('"git describe --tags 2> NUL"') do (
|
|
|
|
set GIT_REV=%%i
|
|
|
|
)
|
|
|
|
) else (
|
|
|
|
FOR /F %%i IN ('"git rev-parse --short HEAD 2> NUL"') do (
|
|
|
|
set GIT_REV=%%i
|
|
|
|
)
|
2021-10-18 04:09:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
FOR /F "tokens=* USEBACKQ" %%i IN (`git tag --points-at HEAD`) DO (
|
|
|
|
set GIT_TAG=%%i
|
2016-11-08 21:44:39 +00:00
|
|
|
)
|
|
|
|
|
2022-05-12 15:54:02 +00:00
|
|
|
FOR /F "tokens=* USEBACKQ" %%i IN (`git rev-parse HEAD`) DO (
|
|
|
|
set GIT_HASH=%%i
|
|
|
|
)
|
|
|
|
|
2024-01-07 09:36:40 +00:00
|
|
|
FOR /F "tokens=* USEBACKQ" %%i IN (`git log -1 "--format=%%cd" "--date=local"`) DO (
|
|
|
|
set GIT_DATE=%%i
|
|
|
|
)
|
2015-08-04 21:52:48 +00:00
|
|
|
|
2024-01-07 09:36:40 +00:00
|
|
|
SET SIGNATURELINE=// R[%GIT_REV%] H[%GIT_HASH%] T[%GIT_TAG%]
|
2022-05-28 05:21:14 +00:00
|
|
|
SET /P EXISTINGLINE=<"%CD%\svnrev.h"
|
|
|
|
|
|
|
|
IF "%EXISTINGLINE%"=="%SIGNATURELINE%" (
|
|
|
|
goto cleanup
|
|
|
|
)
|
|
|
|
|
|
|
|
ECHO Updating "%CD%\svnrev.h"...
|
|
|
|
echo %SIGNATURELINE%> "%CD%\svnrev.h"
|
|
|
|
|
2024-01-07 09:36:40 +00:00
|
|
|
echo #define GIT_HASH "%GIT_HASH%" >> "%CD%\svnrev.h"
|
|
|
|
echo #define GIT_TAG "%GIT_TAG%" >> "%CD%\svnrev.h"
|
|
|
|
echo #define GIT_DATE "%GIT_DATE%" >> "%CD%\svnrev.h"
|
2015-08-04 21:52:48 +00:00
|
|
|
|
2024-01-07 09:36:40 +00:00
|
|
|
echo %GIT_TAG%|FINDSTR /R "^v[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$" > NUL
|
|
|
|
if !ERRORLEVEL! EQU 0 (
|
|
|
|
echo #define GIT_REV "%GIT_TAG%" >> "%CD%\svnrev.h"
|
|
|
|
echo #define GIT_TAGGED_COMMIT 1 >> "%CD%\svnrev.h"
|
|
|
|
FOR /F "tokens=1,2,3 delims=v." %%a in ("%GIT_TAG%") DO (
|
|
|
|
echo #define GIT_TAG_HI %%a >> "%CD%\svnrev.h"
|
|
|
|
echo #define GIT_TAG_MID %%b >> "%CD%\svnrev.h"
|
|
|
|
echo #define GIT_TAG_LO %%c >> "%CD%\svnrev.h"
|
|
|
|
)
|
2015-08-04 21:52:48 +00:00
|
|
|
) else (
|
2024-01-07 09:36:40 +00:00
|
|
|
:: Local branches
|
|
|
|
echo #define GIT_REV "%GIT_REV%" >> "%CD%\svnrev.h"
|
|
|
|
echo #define GIT_TAGGED_COMMIT 0 >> "%CD%\svnrev.h"
|
|
|
|
echo %GIT_REV%|FINDSTR /R "^v[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]-*" > NUL
|
|
|
|
if !ERRORLEVEL! EQU 0 (
|
|
|
|
FOR /F "tokens=1,2,3 delims=v." %%a in ("%GIT_REV%") DO (
|
|
|
|
echo #define GIT_TAG_HI %%a >> "%CD%\svnrev.h"
|
|
|
|
echo #define GIT_TAG_MID %%b >> "%CD%\svnrev.h"
|
|
|
|
FOR /F "tokens=1 delims=-" %%d in ("%%c%") DO (
|
|
|
|
echo #define GIT_TAG_LO %%d >> "%CD%\svnrev.h"
|
|
|
|
)
|
2022-01-21 14:05:13 +00:00
|
|
|
)
|
2021-10-18 04:09:42 +00:00
|
|
|
) else (
|
2024-01-07 09:36:40 +00:00
|
|
|
echo #define GIT_TAG_HI 0 >> "%CD%\svnrev.h"
|
|
|
|
echo #define GIT_TAG_MID 0 >> "%CD%\svnrev.h"
|
|
|
|
echo #define GIT_TAG_LO 0 >> "%CD%\svnrev.h"
|
2021-10-18 04:09:42 +00:00
|
|
|
)
|
2015-08-04 21:52:48 +00:00
|
|
|
)
|
|
|
|
|
2022-05-28 05:21:14 +00:00
|
|
|
:cleanup
|
2015-08-04 21:52:48 +00:00
|
|
|
ENDLOCAL
|
|
|
|
:: Always return an errorlevel of 0 -- this allows compilation to continue if SubWCRev failed.
|
|
|
|
exit /B 0
|