diff options
author | Michael Smith <mikesmiffy128@gmail.com> | 2024-08-03 16:14:15 +0100 |
---|---|---|
committer | Michael Smith <mikesmiffy128@gmail.com> | 2024-08-22 00:01:06 +0100 |
commit | acbd30e0427b16f885f96aed59881ec04eff25bc (patch) | |
tree | 56a9d4506bfb4b4a7c492096ee3e3b7dc95c1896 /compile.bat | |
parent | 44902cb49cd51e2bb2f1cef05cb3c0e799b83434 (diff) |
Prevent errorlevel weirdness in compile.bat
This is an issue I've known about for a little while and kept forgetting
to fix here. It's not been a huge issue for anyone, but still, improving
correctness is always a good thing.
Essentially, if you run a batch file straight through cmd /c, rather
than interactively, exit /b with no number doesn't actually propagate
the errorlevel value correctly, which is obviously bad. To fix this,
just jump to the end on error and then explicitly return the errorlevel.
If everything succeeds, this will of course still return 0, as expected.
Special thanks go to Microsoft for writing this bug decades ago and
never fixing it, probably in the name of backwards compatibility.
Diffstat (limited to 'compile.bat')
-rw-r--r-- | compile.bat | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/compile.bat b/compile.bat index 215fc32..f36d17d 100644 --- a/compile.bat +++ b/compile.bat @@ -1,7 +1,5 @@ :: This file is dedicated to the public domain.
@echo off
-
-:: don't leak vars into the environment
setlocal
if not exist .build\ (
@@ -51,7 +49,7 @@ set objs=%objs% .build/%basename%.o :: predefined bool/true/false before compilers start doing that by default
%CC% -c -flto -mno-stack-arg-probe %cflags% %warnings% -I.build/include ^
-D_CRT_SECURE_NO_WARNINGS -D_DLL -DWIN32_LEAN_AND_MEAN -DNOMINMAX%dmodname% ^
--Dtypeof=__typeof -include stdbool.h -o .build/%basename%.o %1 || exit /b
+-Dtypeof=__typeof -include stdbool.h -o .build/%basename%.o %1 || goto :end
goto :eof
:src
@@ -115,17 +113,17 @@ if %host64%==1 ( %CC% -fuse-ld=lld -shared -O0 -w -o .build/vstdlib.dll src/stubs/vstdlib.c
%HOSTCC% -fuse-ld=lld -municode -O2 %warnings% -D_CRT_SECURE_NO_WARNINGS -include stdbool.h ^
--L.build %lbcryptprimitives_host% -o .build/codegen.exe src/build/codegen.c src/build/cmeta.c src/os.c || exit /b
+-L.build %lbcryptprimitives_host% -o .build/codegen.exe src/build/codegen.c src/build/cmeta.c src/os.c || goto :end
%HOSTCC% -fuse-ld=lld -municode -O2 %warnings% -D_CRT_SECURE_NO_WARNINGS -include stdbool.h ^
--L.build %lbcryptprimitives_host% -o .build/mkgamedata.exe src/build/mkgamedata.c src/kv.c src/os.c || exit /b
+-L.build %lbcryptprimitives_host% -o .build/mkgamedata.exe src/build/mkgamedata.c src/kv.c src/os.c || goto :end
%HOSTCC% -fuse-ld=lld -municode -O2 %warnings% -D_CRT_SECURE_NO_WARNINGS -include stdbool.h ^
--L.build %lbcryptprimitives_host% -o .build/mkentprops.exe src/build/mkentprops.c src/kv.c src/os.c || exit /b
+-L.build %lbcryptprimitives_host% -o .build/mkentprops.exe src/build/mkentprops.c src/kv.c src/os.c || goto :end
.build\codegen.exe%src% || goto :end
.build\mkgamedata.exe gamedata/engine.kv gamedata/gamelib.kv gamedata/inputsystem.kv ^
-gamedata/matchmaking.kv gamedata/vgui2.kv gamedata/vguimatsurface.kv || exit /b
-.build\mkentprops.exe gamedata/entprops.kv || exit /b
-llvm-rc /FO .build\dll.res src\dll.rc || exit /b
-for %%b in (%src%) do ( call :cc %%b || exit /b )
+gamedata/matchmaking.kv gamedata/vgui2.kv gamedata/vguimatsurface.kv || goto :end
+.build\mkentprops.exe gamedata/entprops.kv || goto :end
+llvm-rc /FO .build\dll.res src\dll.rc || goto :end
+for %%b in (%src%) do ( call :cc %%b || goto :end )
:: we need different library names for debugging because Microsoft...
:: actually, it's different anyway because we don't use vcruntime for releases
:: any more. see comment in wincrt.c
@@ -136,20 +134,21 @@ if "%dbg%"=="1" ( )
%CC% -fuse-ld=lld -shared -flto %ldflags% -Wl,/IMPLIB:.build/sst.lib,/Brepro,/nodefaultlib ^
-L.build %clibs% -lkernel32 -luser32 -lbcryptprimitives -lshlwapi -ld3d9 -ldsound ^
--ltier0 -lvstdlib -lntdll -o sst.dll%objs% .build/dll.res || exit /b
+-ltier0 -lvstdlib -lntdll -o sst.dll%objs% .build/dll.res || goto :end
:: get rid of another useless file (can we just not create this???)
del .build\sst.lib
-%HOSTCC% -fuse-ld=lld -O2 -g -include test/test.h -o .build/bitbuf.test.exe test/bitbuf.test.c || exit /b
-.build\bitbuf.test.exe || exit /b
+%HOSTCC% -fuse-ld=lld -O2 -g -include test/test.h -o .build/bitbuf.test.exe test/bitbuf.test.c || goto :end
+.build\bitbuf.test.exe || goto :end
:: special case: test must be 32-bit
-%HOSTCC% -fuse-ld=lld -m32 -O2 -g -L.build -lbcryptprimitives -include test/test.h -o .build/hook.test.exe test/hook.test.c || exit /b
-.build\hook.test.exe || exit /b
-%HOSTCC% -fuse-ld=lld -O2 -g -include test/test.h -o .build/kv.test.exe test/kv.test.c || exit /b
-.build\kv.test.exe || exit /b
-%HOSTCC% -fuse-ld=lld -O2 -g -include test/test.h -o .build/x86.test.exe test/x86.test.c || exit /b
-.build\x86.test.exe || exit /b
-
-endlocal
+%HOSTCC% -fuse-ld=lld -m32 -O2 -g -L.build -lbcryptprimitives -include test/test.h -o .build/hook.test.exe test/hook.test.c || goto :end
+.build\hook.test.exe || goto :end
+%HOSTCC% -fuse-ld=lld -O2 -g -include test/test.h -o .build/kv.test.exe test/kv.test.c || goto :end
+.build\kv.test.exe || goto :end
+%HOSTCC% -fuse-ld=lld -O2 -g -include test/test.h -o .build/x86.test.exe test/x86.test.c || goto :end
+.build\x86.test.exe || goto :end
+
+:end
+exit /b %errorlevel%
:: vi: sw=4 tw=4 noet tw=80 cc=80
|