{all,clean,make,race,run}.bat: use || instead of "if errorlevel 1"

"if errorlevel 1" is and old construct that returns true if the
errorlevel is greater than or equal to 1. There are better alternatives
since Windows NT. For example, the || operator runs the RHS operand if
the preceding command failed, determined by checking that the errorlevel
is different from 0. This approach is more robust -it also works with
negative errorlevels- and is less verbose.

Change-Id: I2070d654d8f9dd41a6cd586ba5ad5f4fea0638ed
Reviewed-on: https://go-review.googlesource.com/c/go/+/647136
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
qmuntal 2025-02-06 10:55:59 +01:00 committed by Quim Muntal
parent 302bf36314
commit 580a383103
5 changed files with 13 additions and 27 deletions

View File

@ -11,10 +11,8 @@ echo all.bat must be run from go\src
exit /b 1 exit /b 1
:ok :ok
call .\make.bat --no-banner --no-local call .\make.bat --no-banner --no-local || goto fail
if errorlevel 1 goto fail call .\run.bat --no-rebuild || goto fail
call .\run.bat --no-rebuild
if errorlevel 1 goto fail
"%GOTOOLDIR%/dist" banner "%GOTOOLDIR%/dist" banner
goto :eof goto :eof

View File

@ -6,8 +6,7 @@
setlocal setlocal
go tool dist env -w -p >env.bat go tool dist env -w -p >env.bat || goto fail
if errorlevel 1 goto fail
call .\env.bat call .\env.bat
del env.bat del env.bat
echo. echo.

View File

@ -101,11 +101,9 @@ echo Building Go cmd/dist using %GOROOT_BOOTSTRAP%. (%GOROOT_BOOTSTRAP_VERSION%)
if x%vflag==x-v echo cmd/dist if x%vflag==x-v echo cmd/dist
set GOROOT=%GOROOT_BOOTSTRAP% set GOROOT=%GOROOT_BOOTSTRAP%
set GOBIN= set GOBIN=
"%GOROOT_BOOTSTRAP%\bin\go.exe" build -o cmd\dist\dist.exe .\cmd\dist "%GOROOT_BOOTSTRAP%\bin\go.exe" build -o cmd\dist\dist.exe .\cmd\dist || goto fail
endlocal endlocal
if errorlevel 1 goto fail .\cmd\dist\dist.exe env -w -p >env.bat || goto fail
.\cmd\dist\dist.exe env -w -p >env.bat
if errorlevel 1 goto fail
call .\env.bat call .\env.bat
del env.bat del env.bat
if x%vflag==x-v echo. if x%vflag==x-v echo.
@ -148,8 +146,7 @@ if x%4==x--distpack set bootstrapflags=%bootstrapflags% -distpack
:: Run dist bootstrap to complete make.bash. :: Run dist bootstrap to complete make.bash.
:: Bootstrap installs a proper cmd/dist, built with the new toolchain. :: Bootstrap installs a proper cmd/dist, built with the new toolchain.
:: Throw ours, built with the bootstrap toolchain, away after bootstrap. :: Throw ours, built with the bootstrap toolchain, away after bootstrap.
.\cmd\dist\dist.exe bootstrap -a %vflag% %bootstrapflags% .\cmd\dist\dist.exe bootstrap -a %vflag% %bootstrapflags% || goto fail
if errorlevel 1 goto fail
del .\cmd\dist\dist.exe del .\cmd\dist\dist.exe
goto :eof goto :eof

View File

@ -15,10 +15,8 @@ exit /b 1
:ok :ok
set GOROOT=%CD%\.. set GOROOT=%CD%\..
call .\make.bat --dist-tool >NUL call .\make.bat --dist-tool >NUL || goto fail
if errorlevel 1 goto fail .\cmd\dist\dist.exe env -w -p >env.bat || goto fail
.\cmd\dist\dist.exe env -w -p >env.bat
if errorlevel 1 goto fail
call .\env.bat call .\env.bat
del env.bat del env.bat
@ -27,15 +25,11 @@ echo Race detector is only supported on windows/amd64.
goto fail goto fail
:continue :continue
call .\make.bat --no-banner --no-local call .\make.bat --no-banner --no-local || goto fail
if errorlevel 1 goto fail
echo # go install -race std echo # go install -race std
go install -race std go install -race std || goto fail
if errorlevel 1 goto fail go tool dist test -race || goto fail
go tool dist test -race
if errorlevel 1 goto fail
echo All tests passed. echo All tests passed.
goto :eof goto :eof

View File

@ -12,14 +12,12 @@ goto fail
setlocal setlocal
set GOENV=off set GOENV=off
..\bin\go tool dist env > env.bat ..\bin\go tool dist env > env.bat || goto fail
if errorlevel 1 goto fail
call .\env.bat call .\env.bat
del env.bat del env.bat
set GOPATH=c:\nonexist-gopath set GOPATH=c:\nonexist-gopath
..\bin\go tool dist test --rebuild %* ..\bin\go tool dist test --rebuild %* || goto fail
if errorlevel 1 goto fail
goto :eof goto :eof
:fail :fail