{all,clean,make,race,run}.bat: remove %GOBUILDEXIT% and %GOBUILDFAIL%

%GOBUILDEXIT% is used to avoid closing the terminal window when the
build or the tests fail on a dev machine. It is only set in CI to get
a non-zero exit code in case of failure.

%GOBUILDFAIL% is used to pass the exit code from a child batch file to
the parent batch file. It is set to 1 in the child batch file if the
build or the tests fail.

These two variables add complexity to the batch files and impose some
limitations on how they are implemented. For example, the child files
can't use setlocal, as it would make the parent file unable to read the
%GOBUILDFAIL% variable.

This CL removes these two variables and replaces them with unconditional
calls to "exit /b 1" in case of failure, which is more idiomatic and
composable. The trick is that the "/b" parameter makes the exit only
apply to the current batch file, not the entire shell session (unless
the bat file is the root, in which case the parameter is ignored), so
the parent batch file can continue executing, potentially checking the
errorlevel of the child batch file (which we always set to 1).

Change-Id: Ib053fb181ab14d58679551e03485700de77878d7
Reviewed-on: https://go-review.googlesource.com/c/go/+/647115
Auto-Submit: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
qmuntal 2025-02-06 09:07:08 +01:00 committed by Gopher Robot
parent 7a2f757c52
commit 09fdcdc97d
5 changed files with 17 additions and 36 deletions

View File

@ -8,15 +8,15 @@ setlocal
if exist make.bat goto ok
echo all.bat must be run from go\src
:: cannot exit: would kill parent command interpreter
goto end
exit /b 1
:ok
call .\make.bat --no-banner --no-local
if %GOBUILDFAIL%==1 goto end
if errorlevel 1 goto fail
call .\run.bat --no-rebuild --no-local
if %GOBUILDFAIL%==1 goto end
if errorlevel 1 goto fail
"%GOTOOLDIR%/dist" banner
goto :eof
:end
if x%GOBUILDEXIT%==x1 exit %GOBUILDFAIL%
:fail
exit /b 1

View File

@ -6,8 +6,6 @@
setlocal
set GOBUILDFAIL=0
go tool dist env -w -p >env.bat
if errorlevel 1 goto fail
call .\env.bat
@ -23,10 +21,7 @@ goto fail
"%GOBIN%\go" tool dist clean
"%GOBIN%\go" clean -i cmd
goto end
goto :eof
:fail
set GOBUILDFAIL=1
:end
if x%GOBUILDEXIT%==x1 exit %GOBUILDFAIL%
exit /b 1

View File

@ -47,8 +47,6 @@ if x%4==x--no-local goto nolocal
setlocal
:nolocal
set GOBUILDFAIL=0
if exist make.bat goto ok
echo Must run make.bat from Go src directory.
goto fail
@ -180,5 +178,4 @@ echo ERROR: Cannot find %GOROOT_BOOTSTRAP%\bin\go.exe
echo Set GOROOT_BOOTSTRAP to a working Go tree ^>= Go %bootgo%.
:fail
set GOBUILDFAIL=1
if x%GOBUILDEXIT%==x1 exit %GOBUILDFAIL%
exit /b 1

View File

@ -11,8 +11,7 @@ setlocal
if exist make.bat goto ok
echo race.bat must be run from go\src
:: cannot exit: would kill parent command interpreter
goto end
exit /b 1
:ok
set GOROOT=%CD%\..
@ -29,7 +28,7 @@ goto fail
:continue
call .\make.bat --no-banner --no-local
if %GOBUILDFAIL%==1 goto end
if errorlevel 1 goto fail
echo # go install -race std
go install -race std
if errorlevel 1 goto fail
@ -37,15 +36,9 @@ if errorlevel 1 goto fail
go tool dist test -race
if errorlevel 1 goto fail
goto succ
echo All tests passed.
goto :eof
:fail
set GOBUILDFAIL=1
echo Fail.
goto end
:succ
echo All tests passed.
:end
if x%GOBUILDEXIT%==x1 exit %GOBUILDFAIL%
exit /b 1

View File

@ -16,8 +16,6 @@ if x%2==x--no-local goto nolocal
setlocal
:nolocal
set GOBUILDFAIL=0
set GOENV=off
..\bin\go tool dist env > env.bat
if errorlevel 1 goto fail
@ -29,14 +27,12 @@ set GOPATH=c:\nonexist-gopath
if x%1==x--no-rebuild goto norebuild
..\bin\go tool dist test --rebuild
if errorlevel 1 goto fail
goto end
goto :eof
:norebuild
..\bin\go tool dist test
if errorlevel 1 goto fail
goto end
goto :eof
:fail
set GOBUILDFAIL=1
:end
exit /b 1