Skip to content

Commit

Permalink
Fix build.bat/bootstrap.bat exit code
Browse files Browse the repository at this point in the history
1. cmd.exe quirk 1: `exit /b 1` sets error code `0` for **the process**, even though it sets `errorlevel` to `1`.
2. `bootstrap.bat` needs to check that `build.bat` succeded (cmd.exe quirk 2: `echo off` doesn't change `errorlevel`).
3. `build.bat` overrides exit code with call to `dir *.exe`.
4. `setlocal` will rollback `pushd` on exit (that also helps with Ctrl+C).
  • Loading branch information
Kojoley authored and grafikrobot committed Apr 21, 2024
1 parent 0513ee6 commit 752527a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
16 changes: 7 additions & 9 deletions bootstrap.bat
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ REM (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.t

:b2_build
ECHO Building the B2 engine..
setlocal
pushd src\engine
call .\build.bat %*
@ECHO OFF
popd
if exist ".\src\engine\b2.exe" (
if not errorlevel 1 (
if exist b2.exe (
popd
copy .\src\engine\b2.exe . > nul
goto :b2_built)
goto :b2_built))
goto :b2_failure


Expand All @@ -25,15 +27,11 @@ ECHO Building is done. To install, run:
ECHO.
ECHO .\b2 --prefix=DIR install
ECHO.
goto :end
exit /b 0


:b2_failure
ECHO.
ECHO Failed to build the B2 engine.
ECHO.
goto :end


:end
exit /b %ERRORLEVEL%
cmd /c exit 1
3 changes: 2 additions & 1 deletion src/engine/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ set B2_CXXFLAGS=%B2_CXXFLAGS% -DNDEBUG

@echo ON
%B2_CXX% %CXXFLAGS% %B2_CXXFLAGS% %B2_SOURCES% %B2_CXX_LINK%
@if errorlevel 1 goto :Finish
dir *.exe

:Finish
@exit /b %ERRORLEVEL%
@cmd /c exit %ERRORLEVEL%
2 changes: 1 addition & 1 deletion src/engine/config_toolset.bat
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,6 @@ goto :eof
:Embed_Minafest_Via_Windres
if not defined B2_DONT_EMBED_MANIFEST (
where windres >NUL 2>NUL
if %ERRORLEVEL% NEQ 0 ( call; ) else ( set "B2_CXX=windres --input res.rc --output res.o && %B2_CXX% -Wl,res.o" )
if errorlevel 1 ( call; ) else ( set "B2_CXX=windres --input res.rc --output res.o && %B2_CXX% -Wl,res.o" )
)
goto :eof

0 comments on commit 752527a

Please sign in to comment.