Skip to content

Commit

Permalink
support three-part version for RAProject64
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamiras committed Mar 6, 2019
1 parent d41c878 commit 1f1f3eb
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions RAProject64/Source/Project64/MakeBuildVer.bat
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
@echo off

rem === Get the most recent tag matching our prefix ===
git describe --tags --match "RAProject64.*" > Temp.txt
set /p ACTIVE_TAG=<Temp.txt
set VERSION_NUM=%ACTIVE_TAG:~12,3%
set VERSION_REVISION=%ACTIVE_TAG:~16,-9%
if "%VERSION_REVISION%"=="" set VERSION_REVISION=0
for /f "tokens=1,2 delims=-" %%a in ("%ACTIVE_TAG:~12%") do set VERSION_TAG=%%a&set VERSION_REVISION=%%b
if "%VERSION_REVISION%" == "" set VERSION_REVISION=0

rem === Extract the major/minor/patch version from the tag (append 0s if necessary) ===
for /f "tokens=1,2,3 delims=." %%a in ("%VERSION_TAG%.0.0") do set VERSION_NUM=%%a.%%b.%%c

rem === If there are any local modifications, increment revision ===
setlocal
git diff HEAD > Temp.txt
for /F "usebackq" %%A in ('"Temp.txt"') do set DIFF_FILE_SIZE=%%~zA
if %DIFF_FILE_SIZE% GTR 0 (
set ACTIVE_TAG=Unstaged changes
set VERSION_MODIFIED=1
) else (
set VERSION_MODIFIED=0
set /A VERSION_REVISION=VERSION_REVISION+1
)

@echo Tag: %ACTIVE_TAG% (%VERSION_NUM%)
@echo #define RAPROJECT64_VERSION "0.%VERSION_NUM%.%VERSION_REVISION%.%VERSION_MODIFIED%" > BuildVer2.h
rem === Generate a new version file ===
@echo Tag: %ACTIVE_TAG% (%VERSION_TAG%)
@echo #define RAPROJECT64_VERSION "%VERSION_NUM%.%VERSION_REVISION%" > BuildVer2.h

rem === Update the existing file only if the new file differs ===
if not exist BuildVer.h goto nonexistant
fc BuildVer.h BuildVer2.h > nul
if errorlevel 1 goto different
Expand All @@ -30,4 +34,5 @@ del BuildVer.h
move BuildVer2.h BuildVer.h > nul
:done

del Temp.txt
rem === Clean up after ourselves ===
del Temp.txt

0 comments on commit 1f1f3eb

Please sign in to comment.