From 580a383103f2bc67955a146a2d45b7c0c98dae8a Mon Sep 17 00:00:00 2001 From: qmuntal Date: Thu, 6 Feb 2025 10:55:59 +0100 Subject: [PATCH] {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 LUCI-TryBot-Result: Go LUCI Reviewed-by: Damien Neil --- src/all.bat | 6 ++---- src/clean.bat | 3 +-- src/make.bat | 9 +++------ src/race.bat | 16 +++++----------- src/run.bat | 6 ++---- 5 files changed, 13 insertions(+), 27 deletions(-) diff --git a/src/all.bat b/src/all.bat index 0c4d5de70c..483151b893 100644 --- a/src/all.bat +++ b/src/all.bat @@ -11,10 +11,8 @@ echo all.bat must be run from go\src exit /b 1 :ok -call .\make.bat --no-banner --no-local -if errorlevel 1 goto fail -call .\run.bat --no-rebuild -if errorlevel 1 goto fail +call .\make.bat --no-banner --no-local || goto fail +call .\run.bat --no-rebuild || goto fail "%GOTOOLDIR%/dist" banner goto :eof diff --git a/src/clean.bat b/src/clean.bat index ceba3a56cf..51fa857b7c 100644 --- a/src/clean.bat +++ b/src/clean.bat @@ -6,8 +6,7 @@ setlocal -go tool dist env -w -p >env.bat -if errorlevel 1 goto fail +go tool dist env -w -p >env.bat || goto fail call .\env.bat del env.bat echo. diff --git a/src/make.bat b/src/make.bat index 3a72a59470..57e4e5f80c 100644 --- a/src/make.bat +++ b/src/make.bat @@ -101,11 +101,9 @@ echo Building Go cmd/dist using %GOROOT_BOOTSTRAP%. (%GOROOT_BOOTSTRAP_VERSION%) if x%vflag==x-v echo cmd/dist set GOROOT=%GOROOT_BOOTSTRAP% 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 -if errorlevel 1 goto fail -.\cmd\dist\dist.exe env -w -p >env.bat -if errorlevel 1 goto fail +.\cmd\dist\dist.exe env -w -p >env.bat || goto fail call .\env.bat del env.bat 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. :: Bootstrap installs a proper cmd/dist, built with the new toolchain. :: Throw ours, built with the bootstrap toolchain, away after bootstrap. -.\cmd\dist\dist.exe bootstrap -a %vflag% %bootstrapflags% -if errorlevel 1 goto fail +.\cmd\dist\dist.exe bootstrap -a %vflag% %bootstrapflags% || goto fail del .\cmd\dist\dist.exe goto :eof diff --git a/src/race.bat b/src/race.bat index 64510b6012..2f6ba91475 100644 --- a/src/race.bat +++ b/src/race.bat @@ -15,10 +15,8 @@ exit /b 1 :ok set GOROOT=%CD%\.. -call .\make.bat --dist-tool >NUL -if errorlevel 1 goto fail -.\cmd\dist\dist.exe env -w -p >env.bat -if errorlevel 1 goto fail +call .\make.bat --dist-tool >NUL || goto fail +.\cmd\dist\dist.exe env -w -p >env.bat || goto fail call .\env.bat del env.bat @@ -27,15 +25,11 @@ echo Race detector is only supported on windows/amd64. goto fail :continue -call .\make.bat --no-banner --no-local -if errorlevel 1 goto fail +call .\make.bat --no-banner --no-local || goto fail echo # go install -race std -go install -race std -if errorlevel 1 goto fail +go install -race std || goto fail +go tool dist test -race || goto fail -go tool dist test -race - -if errorlevel 1 goto fail echo All tests passed. goto :eof diff --git a/src/run.bat b/src/run.bat index 6a0ffe3af9..3e7b1a1b0c 100644 --- a/src/run.bat +++ b/src/run.bat @@ -12,14 +12,12 @@ goto fail setlocal set GOENV=off -..\bin\go tool dist env > env.bat -if errorlevel 1 goto fail +..\bin\go tool dist env > env.bat || goto fail call .\env.bat del env.bat set GOPATH=c:\nonexist-gopath -..\bin\go tool dist test --rebuild %* -if errorlevel 1 goto fail +..\bin\go tool dist test --rebuild %* || goto fail goto :eof :fail