Extract pre and post build scripts

- Extracted pre-build and post-build scripts to tools\
- Updated the pre-build script to overwrite git.h only if commit hash has changed
- Improved post build scripts error handling and debugging symbols support
This commit is contained in:
izawartka 2026-08-02 20:59:17 +02:00
parent ad0db92a90
commit 28d96b104e
5 changed files with 169 additions and 292 deletions

View File

@ -5,5 +5,6 @@
<GTA2_EXE>gta2.exe</GTA2_EXE>
<GTA2_ASI_DIR>$(GTA2_DIR)\scripts</GTA2_ASI_DIR>
<GTA2_ASI_FILENAME>gta2-seuko-mod.asi</GTA2_ASI_FILENAME>
<GTA2_ASI_PDB_FILENAME>gta2-seuko-mod.pdb</GTA2_ASI_PDB_FILENAME>
</PropertyGroup>
</Project>

View File

@ -127,62 +127,10 @@
<ModuleDefinitionFile>src\dinput8.def</ModuleDefinitionFile>
</Link>
<PostBuildEvent>
<Command>@echo off
echo Dinput8 proxy mode enabled
if "$(GTA2_DIR)"=="" (
echo ERROR: GTA2_DIR is not set. Make sure to set it in GTA2.props file.
exit /b 1
)
if "$(GTA2_EXE)"=="" (
echo ERROR: GTA2_EXE is not set. Make sure to set it in GTA2.props file.
exit /b 1
)
if not exist "$(GTA2_DIR)\" (
echo ERROR: GTA2_DIR "$(GTA2_DIR)" specified in GTA2.props does not exist.
exit /b 1
)
if not exist "$(GTA2_DIR)\$(GTA2_EXE)" (
echo ERROR: "$(GTA2_EXE)" not found in "$(GTA2_DIR)". Check GTA2.props file.
exit /b 1
)
echo Copying "$(TargetPath)" to "$(GTA2_DIR)"
copy /Y "$(TargetPath)" "$(GTA2_DIR)\"
if errorlevel 1 exit /b 1
if exist "$(TargetDir)$(TargetName).pdb" (
copy /Y "$(TargetDir)$(TargetName).pdb" "$(GTA2_DIR)\"
)
exit /b 0
</Command>
<Command>call "$(ProjectDir)tools\post-build-dinput8.bat" "$(GTA2_DIR)" "$(GTA2_EXE)" "$(TargetPath)" "$(TargetDir)" "$(TargetName)"</Command>
</PostBuildEvent>
<PreBuildEvent>
<Command>set GIT_HASH=unknown
set GIT_DIRTY=false
for /f %%i in ('git rev-parse --short HEAD 2^&gt;nul') do set GIT_HASH=%%i
for /f %%i in ('git status --porcelain 2^&gt;nul') do (
set GIT_DIRTY=true
goto :dirty_done
)
:dirty_done
echo #pragma once&gt; "$(ProjectDir)src\git.h"
echo // Auto-generated. Do not edit.&gt;&gt; "$(ProjectDir)src\git.h"
echo.&gt;&gt; "$(ProjectDir)src\git.h"
echo #define GIT_COMMIT_HASH "%GIT_HASH%"&gt;&gt; "$(ProjectDir)src\git.h"
echo #define GIT_IS_DIRTY %GIT_DIRTY%&gt;&gt; "$(ProjectDir)src\git.h"
echo Created $(ProjectDir)src\git.h with commit %GIT_HASH% (dirty=%GIT_DIRTY%)
</Command>
<Command>call "$(ProjectDir)tools\update-git-header.bat" "$(ProjectDir)"</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugAsi|Win32'">
@ -209,73 +157,10 @@ echo Created $(ProjectDir)src\git.h with commit %GIT_HASH% (dirty=%GIT_DIRTY%)
</ModuleDefinitionFile>
</Link>
<PostBuildEvent>
<Command>@echo off
echo ASI mode enabled
if "$(GTA2_DIR)"=="" (
echo ERROR: GTA2_DIR is not set. Make sure to set it in GTA2.props file.
exit /b 1
)
if "$(GTA2_EXE)"=="" (
echo ERROR: GTA2_EXE is not set. Make sure to set it in GTA2.props file.
exit /b 1
)
if not exist "$(GTA2_DIR)\" (
echo ERROR: GTA2_DIR "$(GTA2_DIR)" specified in GTA2.props does not exist.
exit /b 1
)
if not exist "$(GTA2_DIR)\$(GTA2_EXE)" (
echo ERROR: "$(GTA2_EXE)" not found in "$(GTA2_DIR)". Check GTA2.props file.
exit /b 1
)
if "$(GTA2_ASI_DIR)"=="" (
echo ERROR: GTA2_ASI_DIR is not set. To build in ASI mode, make sure to set it in GTA2.props file.
exit /b 1
)
if "$(GTA2_ASI_FILENAME)"=="" (
echo ERROR: GTA2_ASI_FILENAME is not set. To build in ASI mode, make sure to set it in GTA2.props file.
exit /b 1
)
if not exist "$(GTA2_ASI_DIR)\" (
echo ERROR: GTA2_ASI_DIR "$(GTA2_ASI_DIR)" does not exist. Check GTA2.props file.
exit /b 1
)
echo Copying "$(TargetPath)" to "$(GTA2_ASI_DIR)\$(GTA2_ASI_FILENAME)"
copy /Y "$(TargetPath)" "$(GTA2_ASI_DIR)\$(GTA2_ASI_FILENAME)"
if errorlevel 1 exit /b 1
exit /b 0
</Command>
<Command>call "$(ProjectDir)tools\post-build-asi.bat" "$(GTA2_DIR)" "$(GTA2_EXE)" "$(GTA2_ASI_DIR)" "$(GTA2_ASI_FILENAME)" "$(GTA2_ASI_PDB_FILENAME)" "$(TargetPath)" "$(TargetDir)" "$(TargetName)"</Command>
</PostBuildEvent>
<PreBuildEvent>
<Command>set GIT_HASH=unknown
set GIT_DIRTY=false
for /f %%i in ('git rev-parse --short HEAD 2^&gt;nul') do set GIT_HASH=%%i
for /f %%i in ('git status --porcelain 2^&gt;nul') do (
set GIT_DIRTY=true
goto :dirty_done
)
:dirty_done
echo #pragma once&gt; "$(ProjectDir)src\git.h"
echo // Auto-generated. Do not edit.&gt;&gt; "$(ProjectDir)src\git.h"
echo.&gt;&gt; "$(ProjectDir)src\git.h"
echo #define GIT_COMMIT_HASH "%GIT_HASH%"&gt;&gt; "$(ProjectDir)src\git.h"
echo #define GIT_IS_DIRTY %GIT_DIRTY%&gt;&gt; "$(ProjectDir)src\git.h"
echo Created $(ProjectDir)src\git.h with commit %GIT_HASH% (dirty=%GIT_DIRTY%)
</Command>
<Command>call "$(ProjectDir)tools\update-git-header.bat" "$(ProjectDir)"</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@ -303,62 +188,10 @@ echo Created $(ProjectDir)src\git.h with commit %GIT_HASH% (dirty=%GIT_DIRTY%)
<ModuleDefinitionFile>src\dinput8.def</ModuleDefinitionFile>
</Link>
<PostBuildEvent>
<Command>@echo off
echo Dinput8 proxy mode enabled
if "$(GTA2_DIR)"=="" (
echo ERROR: GTA2_DIR is not set. Make sure to set it in GTA2.props file.
exit /b 1
)
if "$(GTA2_EXE)"=="" (
echo ERROR: GTA2_EXE is not set. Make sure to set it in GTA2.props file.
exit /b 1
)
if not exist "$(GTA2_DIR)\" (
echo ERROR: GTA2_DIR "$(GTA2_DIR)" specified in GTA2.props does not exist.
exit /b 1
)
if not exist "$(GTA2_DIR)\$(GTA2_EXE)" (
echo ERROR: "$(GTA2_EXE)" not found in "$(GTA2_DIR)". Check GTA2.props file.
exit /b 1
)
echo Copying "$(TargetPath)" to "$(GTA2_DIR)"
copy /Y "$(TargetPath)" "$(GTA2_DIR)\"
if errorlevel 1 exit /b 1
if exist "$(TargetDir)$(TargetName).pdb" (
copy /Y "$(TargetDir)$(TargetName).pdb" "$(GTA2_DIR)\"
)
exit /b 0
</Command>
<Command>call "$(ProjectDir)tools\post-build-dinput8.bat" "$(GTA2_DIR)" "$(GTA2_EXE)" "$(TargetPath)" "$(TargetDir)" "$(TargetName)"</Command>
</PostBuildEvent>
<PreBuildEvent>
<Command>set GIT_HASH=unknown
set GIT_DIRTY=false
for /f %%i in ('git rev-parse --short HEAD 2^&gt;nul') do set GIT_HASH=%%i
for /f %%i in ('git status --porcelain 2^&gt;nul') do (
set GIT_DIRTY=true
goto :dirty_done
)
:dirty_done
echo #pragma once&gt; "$(ProjectDir)src\git.h"
echo // Auto-generated. Do not edit.&gt;&gt; "$(ProjectDir)src\git.h"
echo.&gt;&gt; "$(ProjectDir)src\git.h"
echo #define GIT_COMMIT_HASH "%GIT_HASH%"&gt;&gt; "$(ProjectDir)src\git.h"
echo #define GIT_IS_DIRTY %GIT_DIRTY%&gt;&gt; "$(ProjectDir)src\git.h"
echo Created $(ProjectDir)src\git.h with commit %GIT_HASH% (dirty=%GIT_DIRTY%)
</Command>
<Command>call "$(ProjectDir)tools\update-git-header.bat" "$(ProjectDir)"</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseAsi|Win32'">
@ -388,73 +221,10 @@ echo Created $(ProjectDir)src\git.h with commit %GIT_HASH% (dirty=%GIT_DIRTY%)
</ModuleDefinitionFile>
</Link>
<PostBuildEvent>
<Command>@echo off
echo ASI mode enabled
if "$(GTA2_DIR)"=="" (
echo ERROR: GTA2_DIR is not set. Make sure to set it in GTA2.props file.
exit /b 1
)
if "$(GTA2_EXE)"=="" (
echo ERROR: GTA2_EXE is not set. Make sure to set it in GTA2.props file.
exit /b 1
)
if not exist "$(GTA2_DIR)\" (
echo ERROR: GTA2_DIR "$(GTA2_DIR)" specified in GTA2.props does not exist.
exit /b 1
)
if not exist "$(GTA2_DIR)\$(GTA2_EXE)" (
echo ERROR: "$(GTA2_EXE)" not found in "$(GTA2_DIR)". Check GTA2.props file.
exit /b 1
)
if "$(GTA2_ASI_DIR)"=="" (
echo ERROR: GTA2_ASI_DIR is not set. To build in ASI mode, make sure to set it in GTA2.props file.
exit /b 1
)
if "$(GTA2_ASI_FILENAME)"=="" (
echo ERROR: GTA2_ASI_FILENAME is not set. To build in ASI mode, make sure to set it in GTA2.props file.
exit /b 1
)
if not exist "$(GTA2_ASI_DIR)\" (
echo ERROR: GTA2_ASI_DIR "$(GTA2_ASI_DIR)" does not exist. Check GTA2.props file.
exit /b 1
)
echo Copying "$(TargetPath)" to "$(GTA2_ASI_DIR)\$(GTA2_ASI_FILENAME)"
copy /Y "$(TargetPath)" "$(GTA2_ASI_DIR)\$(GTA2_ASI_FILENAME)"
if errorlevel 1 exit /b 1
exit /b 0
</Command>
<Command>call "$(ProjectDir)tools\post-build-asi.bat" "$(GTA2_DIR)" "$(GTA2_EXE)" "$(GTA2_ASI_DIR)" "$(GTA2_ASI_FILENAME)" "$(GTA2_ASI_PDB_FILENAME)" "$(TargetPath)" "$(TargetDir)" "$(TargetName)"</Command>
</PostBuildEvent>
<PreBuildEvent>
<Command>set GIT_HASH=unknown
set GIT_DIRTY=false
for /f %%i in ('git rev-parse --short HEAD 2^&gt;nul') do set GIT_HASH=%%i
for /f %%i in ('git status --porcelain 2^&gt;nul') do (
set GIT_DIRTY=true
goto :dirty_done
)
:dirty_done
echo #pragma once&gt; "$(ProjectDir)src\git.h"
echo // Auto-generated. Do not edit.&gt;&gt; "$(ProjectDir)src\git.h"
echo.&gt;&gt; "$(ProjectDir)src\git.h"
echo #define GIT_COMMIT_HASH "%GIT_HASH%"&gt;&gt; "$(ProjectDir)src\git.h"
echo #define GIT_IS_DIRTY %GIT_DIRTY%&gt;&gt; "$(ProjectDir)src\git.h"
echo Created $(ProjectDir)src\git.h with commit %GIT_HASH% (dirty=%GIT_DIRTY%)
</Command>
<Command>call "$(ProjectDir)tools\update-git-header.bat" "$(ProjectDir)"</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseWithLogging|Win32'">
@ -483,62 +253,10 @@ echo Created $(ProjectDir)src\git.h with commit %GIT_HASH% (dirty=%GIT_DIRTY%)
<ModuleDefinitionFile>src\dinput8.def</ModuleDefinitionFile>
</Link>
<PostBuildEvent>
<Command>@echo off
echo Dinput8 proxy mode enabled
if "$(GTA2_DIR)"=="" (
echo ERROR: GTA2_DIR is not set. Make sure to set it in GTA2.props file.
exit /b 1
)
if "$(GTA2_EXE)"=="" (
echo ERROR: GTA2_EXE is not set. Make sure to set it in GTA2.props file.
exit /b 1
)
if not exist "$(GTA2_DIR)\" (
echo ERROR: GTA2_DIR "$(GTA2_DIR)" specified in GTA2.props does not exist.
exit /b 1
)
if not exist "$(GTA2_DIR)\$(GTA2_EXE)" (
echo ERROR: "$(GTA2_EXE)" not found in "$(GTA2_DIR)". Check GTA2.props file.
exit /b 1
)
echo Copying "$(TargetPath)" to "$(GTA2_DIR)"
copy /Y "$(TargetPath)" "$(GTA2_DIR)\"
if errorlevel 1 exit /b 1
if exist "$(TargetDir)$(TargetName).pdb" (
copy /Y "$(TargetDir)$(TargetName).pdb" "$(GTA2_DIR)\"
)
exit /b 0
</Command>
<Command>call "$(ProjectDir)tools\post-build-dinput8.bat" "$(GTA2_DIR)" "$(GTA2_EXE)" "$(TargetPath)" "$(TargetDir)" "$(TargetName)"</Command>
</PostBuildEvent>
<PreBuildEvent>
<Command>set GIT_HASH=unknown
set GIT_DIRTY=false
for /f %%i in ('git rev-parse --short HEAD 2^&gt;nul') do set GIT_HASH=%%i
for /f %%i in ('git status --porcelain 2^&gt;nul') do (
set GIT_DIRTY=true
goto :dirty_done
)
:dirty_done
echo #pragma once&gt; "$(ProjectDir)src\git.h"
echo // Auto-generated. Do not edit.&gt;&gt; "$(ProjectDir)src\git.h"
echo.&gt;&gt; "$(ProjectDir)src\git.h"
echo #define GIT_COMMIT_HASH "%GIT_HASH%"&gt;&gt; "$(ProjectDir)src\git.h"
echo #define GIT_IS_DIRTY %GIT_DIRTY%&gt;&gt; "$(ProjectDir)src\git.h"
echo Created $(ProjectDir)src\git.h with commit %GIT_HASH% (dirty=%GIT_DIRTY%)
</Command>
<Command>call "$(ProjectDir)tools\update-git-header.bat" "$(ProjectDir)"</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>

68
tools/post-build-asi.bat Normal file
View File

@ -0,0 +1,68 @@
@echo off
setlocal
set GTA2_DIR=%~1
set GTA2_EXE=%~2
set GTA2_ASI_DIR=%~3
set GTA2_ASI_FILENAME=%~4
set GTA2_ASI_PDB_FILENAME=%~5
set TARGET_PATH=%~6
set TARGET_DIR=%~7
set TARGET_NAME=%~8
echo ASI mode enabled
if "%GTA2_DIR%"=="" (
echo ERROR: GTA2_DIR is not set.
exit /b 1
)
if "%GTA2_EXE%"=="" (
echo ERROR: GTA2_EXE is not set.
exit /b 1
)
if not exist "%GTA2_DIR%\" (
echo ERROR: GTA2_DIR "%GTA2_DIR%" does not exist.
exit /b 1
)
if not exist "%GTA2_DIR%\%GTA2_EXE%" (
echo ERROR: "%GTA2_EXE%" not found in "%GTA2_DIR%".
exit /b 1
)
if "%GTA2_ASI_DIR%"=="" (
echo ERROR: GTA2_ASI_DIR is not set.
exit /b 1
)
if "%GTA2_ASI_FILENAME%"=="" (
echo ERROR: GTA2_ASI_FILENAME is not set.
exit /b 1
)
if not exist "%GTA2_ASI_DIR%\" (
echo ERROR: GTA2_ASI_DIR "%GTA2_ASI_DIR%" does not exist.
exit /b 1
)
echo Copying "%TARGET_PATH%" to "%GTA2_ASI_DIR%\%GTA2_ASI_FILENAME%"
copy /Y "%TARGET_PATH%" "%GTA2_ASI_DIR%\%GTA2_ASI_FILENAME%" >nul
if errorlevel 1 (
echo ERROR: Failed to copy to "%GTA2_ASI_DIR%\%GTA2_ASI_FILENAME%"
exit /b 1
)
@REM if not "%GTA2_ASI_PDB_FILENAME%"=="" (
@REM if exist "%TARGET_DIR%\%TARGET_NAME%.pdb" (
@REM echo Copying "%TARGET_DIR%\%TARGET_NAME%.pdb" to "%GTA2_ASI_DIR%\%GTA2_ASI_PDB_FILENAME%"
@REM copy /Y "%TARGET_DIR%\%TARGET_NAME%.pdb" "%GTA2_ASI_DIR%\%GTA2_ASI_PDB_FILENAME%" >nul
@REM if errorlevel 1 (
@REM echo ERROR: Failed to copy to "%GTA2_ASI_DIR%\%GTA2_ASI_PDB_FILENAME%"
@REM exit /b 1
@REM )
@REM )
@REM )
exit /b 0

View File

@ -0,0 +1,48 @@
@echo off
setlocal
set GTA2_DIR=%~1
set GTA2_EXE=%~2
set TARGET_PATH=%~3
set TARGET_DIR=%~4
set TARGET_NAME=%~5
echo Dinput8 proxy mode enabled
if "%GTA2_DIR%"=="" (
echo ERROR: GTA2_DIR is not set.
exit /b 1
)
if "%GTA2_EXE%"=="" (
echo ERROR: GTA2_EXE is not set.
exit /b 1
)
if not exist "%GTA2_DIR%\" (
echo ERROR: GTA2_DIR "%GTA2_DIR%" does not exist.
exit /b 1
)
if not exist "%GTA2_DIR%\%GTA2_EXE%" (
echo ERROR: "%GTA2_EXE%" not found in "%GTA2_DIR%".
exit /b 1
)
echo Copying "%TARGET_PATH%" to "%GTA2_DIR%\%TARGET_NAME%.dll"
copy /Y "%TARGET_PATH%" "%GTA2_DIR%\%TARGET_NAME%.dll" >nul
if errorlevel 1 (
echo ERROR: Failed to copy to "%GTA2_DIR%\%TARGET_NAME%.dll"
exit /b 1
)
@REM if exist "%TARGET_DIR%\%TARGET_NAME%.pdb" (
@REM echo Copying "%TARGET_DIR%\%TARGET_NAME%.pdb" to "%GTA2_DIR%\%TARGET_NAME%.pdb"
@REM copy /Y "%TARGET_DIR%\%TARGET_NAME%.pdb" "%GTA2_DIR%\%TARGET_NAME%.pdb" >nul
@REM if errorlevel 1 (
@REM echo ERROR: Failed to copy to "%GTA2_DIR%\%TARGET_NAME%.pdb"
@REM exit /b 1
@REM )
@REM )
exit /b 0

View File

@ -0,0 +1,42 @@
@echo off
setlocal
set PROJECT_DIR=%~1
set HEADER=%PROJECT_DIR%src\git.h
set TEMP=%TEMP%\git.h.tmp
set GIT_HASH=unknown
set GIT_DIRTY=false
for /f %%i in ('git rev-parse --short HEAD 2^>nul') do set GIT_HASH=%%i
for /f %%i in ('git status --porcelain 2^>nul') do (
set GIT_DIRTY=true
goto dirty_done
)
:dirty_done
(
echo #pragma once
echo // Auto-generated. Do not edit.
echo.
echo #define GIT_COMMIT_HASH "%GIT_HASH%"
echo #define GIT_IS_DIRTY %GIT_DIRTY%
) > "%TEMP%"
if exist "%HEADER%" (
fc /b "%HEADER%" "%TEMP%" >nul
if not errorlevel 1 (
del "%TEMP%"
echo git.h unchanged
exit /b 0
)
)
move /Y "%TEMP%" "%HEADER%" >nul
echo Updated git.h (%GIT_HASH%, dirty=%GIT_DIRTY%)
exit /b 0