]> Cypherpunks repositories - gostls13.git/commitdiff
{all,clean,make,race,run}.bat: simplify error handling
authorqmuntal <quimmuntal@gmail.com>
Tue, 11 Feb 2025 08:17:08 +0000 (09:17 +0100)
committerGopher Robot <gobot@golang.org>
Tue, 11 Feb 2025 17:45:10 +0000 (09:45 -0800)
The bat files can use "if" + parentheses to make it easier to
understand how the if-case is handled rather than the more cryptic
"if" + "goto".

While here, replace some "goto"s with direct "exit" calls.

Change-Id: I20e1804439b5088f8f1e5cbf8676f3d58560109d
Reviewed-on: https://go-review.googlesource.com/c/go/+/648375
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: 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>
src/all.bat
src/clean.bat
src/make.bat
src/race.bat
src/run.bat

index cb4536284e1a58ff52c0192361f7ba34588db57f..4c681d15eb643e5100b5b986fa6e3e434b7d7367 100644 (file)
@@ -6,15 +6,11 @@
 \r
 setlocal\r
 \r
-if exist make.bat goto ok\r
-echo all.bat must be run from go\src\r
-exit /b 1\r
-:ok\r
+if not exist make.bat (\r
+    echo all.bat must be run from go\src\r
+    exit /b 1\r
+)\r
 \r
-call .\make.bat --no-banner || goto fail\r
-call .\run.bat --no-rebuild || goto fail\r
+call .\make.bat --no-banner || exit /b 1\r
+call .\run.bat --no-rebuild || exit /b 1\r
 ..\bin\go tool dist banner\r
-goto :eof\r
-\r
-:fail\r
-exit /b 1\r
index 51fa857b7c7ac7e251508c66e597e947a538705e..2e03806305b433295f7c7222c6afc2eb03cdcdf6 100644 (file)
@@ -6,21 +6,16 @@
 \r
 setlocal\r
 \r
-go tool dist env -w -p >env.bat || goto fail\r
+go tool dist env -w -p >env.bat || exit /b 1\r
 call .\env.bat\r
 del env.bat\r
 echo.\r
 \r
-if exist %GOTOOLDIR%\dist.exe goto distok\r
-echo cannot find %GOTOOLDIR%\dist; nothing to clean\r
-goto fail\r
-:distok\r
+if not exist %GOTOOLDIR%\dist.exe (\r
+    echo cannot find %GOTOOLDIR%\dist.exe; nothing to clean\r
+    exit /b 1\r
+)\r
 \r
 "%GOBIN%\go" clean -i std\r
 "%GOBIN%\go" tool dist clean\r
 "%GOBIN%\go" clean -i cmd\r
-\r
-goto :eof\r
-\r
-:fail\r
-exit /b 1\r
index 0d5dd2761a7155a827d76521909afcd1340f6eab..890829131ba3170076159673f5cc21192f82a366 100644 (file)
 \r
 setlocal\r
 \r
-if exist make.bat goto ok\r
-echo Must run make.bat from Go src directory.\r
-goto fail\r
-:ok\r
+if not exist make.bat (\r
+       echo Must run make.bat from Go src directory.\r
+       exit /b 1\r
+)\r
 \r
 :: Clean old generated file that will cause problems in the build.\r
 del /F ".\pkg\runtime\runtime_defs.go" 2>NUL\r
@@ -78,7 +78,11 @@ if "x%GOROOT_BOOTSTRAP%"=="x" if exist "%HOMEDRIVE%%HOMEPATH%\sdk\go%bootgo%" se
 if "x%GOROOT_BOOTSTRAP%"=="x" set GOROOT_BOOTSTRAP=%HOMEDRIVE%%HOMEPATH%\Go1.4\r
 \r
 :bootstrapset\r
-if not exist "%GOROOT_BOOTSTRAP%\bin\go.exe" goto bootstrapfail\r
+if not exist "%GOROOT_BOOTSTRAP%\bin\go.exe" (\r
+       echo ERROR: Cannot find %GOROOT_BOOTSTRAP%\bin\go.exe\r
+       echo Set GOROOT_BOOTSTRAP to a working Go tree ^>= Go %bootgo%.\r
+       exit /b 1\r
+)\r
 set GOROOT=%GOROOT_TEMP%\r
 set GOROOT_TEMP=\r
 \r
@@ -90,9 +94,9 @@ echo Building Go cmd/dist using %GOROOT_BOOTSTRAP%. (%GOROOT_BOOTSTRAP_VERSION%)
 if x%vflag==x-v echo cmd/dist\r
 set GOROOT=%GOROOT_BOOTSTRAP%\r
 set GOBIN=\r
-"%GOROOT_BOOTSTRAP%\bin\go.exe" build -o cmd\dist\dist.exe .\cmd\dist || goto fail\r
+"%GOROOT_BOOTSTRAP%\bin\go.exe" build -o cmd\dist\dist.exe .\cmd\dist || exit /b 1\r
 endlocal\r
-.\cmd\dist\dist.exe env -w -p >env.bat || goto fail\r
+.\cmd\dist\dist.exe env -w -p >env.bat || exit /b 1\r
 call .\env.bat\r
 del env.bat\r
 if x%vflag==x-v echo.\r
@@ -109,7 +113,7 @@ if x%4==x--dist-tool goto copydist
 :: Run dist bootstrap to complete make.bash.\r
 :: Bootstrap installs a proper cmd/dist, built with the new toolchain.\r
 :: Throw ours, built with the bootstrap toolchain, away after bootstrap.\r
-.\cmd\dist\dist.exe bootstrap -a %* || goto fail\r
+.\cmd\dist\dist.exe bootstrap -a %* || exit /b 1\r
 del .\cmd\dist\dist.exe\r
 goto :eof\r
 \r
@@ -131,11 +135,3 @@ set GOOS=
 set GOARCH=\r
 set GOEXPERIMENT=\r
 set GOFLAGS=\r
-goto :eof\r
-\r
-:bootstrapfail\r
-echo ERROR: Cannot find %GOROOT_BOOTSTRAP%\bin\go.exe\r
-echo Set GOROOT_BOOTSTRAP to a working Go tree ^>= Go %bootgo%.\r
-\r
-:fail\r
-exit /b 1\r
index 7f1e0a1987230f7cb4362b81a7324a20b2b60157..60fcfb90c76275edd8161801a6148c37e008944f 100644 (file)
@@ -9,30 +9,22 @@
 \r
 setlocal\r
 \r
-if exist make.bat goto ok\r
-echo race.bat must be run from go\src\r
-exit /b 1\r
-:ok\r
+if not exist make.bat (\r
+    echo race.bat must be run from go\src\r
+    exit /b 1\r
+)\r
 \r
 set GOROOT=%CD%\..\r
-call .\make.bat --dist-tool >NUL || goto fail\r
-.\cmd\dist\dist.exe env -w -p >env.bat || goto fail\r
+call .\make.bat --dist-tool >NUL || exit /b 1\r
+.\cmd\dist\dist.exe env -w -p >env.bat || exit /b 1\r
 call .\env.bat\r
 del env.bat\r
 \r
-if %GOHOSTARCH% == amd64 goto continue\r
-echo Race detector is only supported on windows/amd64.\r
-goto fail\r
+if not %GOHOSTARCH% == amd64 (\r
+    echo Race detector is only supported on windows/amd64.\r
+    exit /b 1\r
+)\r
 \r
-:continue\r
-call .\make.bat --no-banner || goto fail\r
-echo # go install -race std\r
-go install -race std || goto fail\r
-go tool dist test -race || goto fail\r
-\r
-echo All tests passed.\r
-goto :eof\r
-\r
-:fail\r
-echo Fail.\r
-exit /b 1\r
+call .\make.bat --no-banner || exit /b 1\r
+go install -race std || exit /b 1\r
+go tool dist test -race || exit /b 1\r
index 3e7b1a1b0c25b0fef1aa26e04ec1e60a9ec4f5c1..b6a101b2ff0faeed8375cb24ad014bda85d5cbe6 100644 (file)
@@ -4,21 +4,17 @@
 \r
 @echo off\r
 \r
-if exist ..\bin\go.exe goto ok\r
-echo Must run run.bat from Go src directory after installing cmd/go.\r
-goto fail\r
-:ok\r
+if not exist ..\bin\go.exe (\r
+    echo Must run run.bat from Go src directory after installing cmd/go.\r
+    exit /b 1\r
+)\r
 \r
 setlocal\r
 \r
 set GOENV=off\r
-..\bin\go tool dist env > env.bat || goto fail\r
+..\bin\go tool dist env > env.bat || exit /b 1\r
 call .\env.bat\r
 del env.bat\r
 \r
 set GOPATH=c:\nonexist-gopath\r
-..\bin\go tool dist test --rebuild %* || goto fail\r
-goto :eof\r
-\r
-:fail\r
-exit /b 1\r
+..\bin\go tool dist test --rebuild %* || exit /b 1\r