Skip to content

Commit

Permalink
{all,clean,make,race,run}.bat: simplify error handling
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
qmuntal authored and gopherbot committed Feb 11, 2025
1 parent 450f3f6 commit e9eb88a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 67 deletions.
16 changes: 6 additions & 10 deletions src/all.bat
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@

setlocal

if exist make.bat goto ok
echo all.bat must be run from go\src
exit /b 1
:ok
if not exist make.bat (
echo all.bat must be run from go\src
exit /b 1
)

call .\make.bat --no-banner || goto fail
call .\run.bat --no-rebuild || goto fail
call .\make.bat --no-banner || exit /b 1
call .\run.bat --no-rebuild || exit /b 1
..\bin\go tool dist banner
goto :eof

:fail
exit /b 1
15 changes: 5 additions & 10 deletions src/clean.bat
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,16 @@

setlocal

go tool dist env -w -p >env.bat || goto fail
go tool dist env -w -p >env.bat || exit /b 1
call .\env.bat
del env.bat
echo.

if exist %GOTOOLDIR%\dist.exe goto distok
echo cannot find %GOTOOLDIR%\dist; nothing to clean
goto fail
:distok
if not exist %GOTOOLDIR%\dist.exe (
echo cannot find %GOTOOLDIR%\dist.exe; nothing to clean
exit /b 1
)

"%GOBIN%\go" clean -i std
"%GOBIN%\go" tool dist clean
"%GOBIN%\go" clean -i cmd

goto :eof

:fail
exit /b 1
28 changes: 12 additions & 16 deletions src/make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@

setlocal

if exist make.bat goto ok
echo Must run make.bat from Go src directory.
goto fail
:ok
if not exist make.bat (
echo Must run make.bat from Go src directory.
exit /b 1
)

:: Clean old generated file that will cause problems in the build.
del /F ".\pkg\runtime\runtime_defs.go" 2>NUL
Expand Down Expand Up @@ -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

:bootstrapset
if not exist "%GOROOT_BOOTSTRAP%\bin\go.exe" goto bootstrapfail
if not exist "%GOROOT_BOOTSTRAP%\bin\go.exe" (
echo ERROR: Cannot find %GOROOT_BOOTSTRAP%\bin\go.exe
echo Set GOROOT_BOOTSTRAP to a working Go tree ^>= Go %bootgo%.
exit /b 1
)
set GOROOT=%GOROOT_TEMP%
set GOROOT_TEMP=

Expand All @@ -90,9 +94,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 || goto fail
"%GOROOT_BOOTSTRAP%\bin\go.exe" build -o cmd\dist\dist.exe .\cmd\dist || exit /b 1
endlocal
.\cmd\dist\dist.exe env -w -p >env.bat || goto fail
.\cmd\dist\dist.exe env -w -p >env.bat || exit /b 1
call .\env.bat
del env.bat
if x%vflag==x-v echo.
Expand All @@ -109,7 +113,7 @@ if x%4==x--dist-tool goto copydist
:: 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 %* || goto fail
.\cmd\dist\dist.exe bootstrap -a %* || exit /b 1
del .\cmd\dist\dist.exe
goto :eof

Expand All @@ -131,11 +135,3 @@ set GOOS=
set GOARCH=
set GOEXPERIMENT=
set GOFLAGS=
goto :eof

:bootstrapfail
echo ERROR: Cannot find %GOROOT_BOOTSTRAP%\bin\go.exe
echo Set GOROOT_BOOTSTRAP to a working Go tree ^>= Go %bootgo%.

:fail
exit /b 1
34 changes: 13 additions & 21 deletions src/race.bat
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,22 @@

setlocal

if exist make.bat goto ok
echo race.bat must be run from go\src
exit /b 1
:ok
if not exist make.bat (
echo race.bat must be run from go\src
exit /b 1
)

set GOROOT=%CD%\..
call .\make.bat --dist-tool >NUL || goto fail
.\cmd\dist\dist.exe env -w -p >env.bat || goto fail
call .\make.bat --dist-tool >NUL || exit /b 1
.\cmd\dist\dist.exe env -w -p >env.bat || exit /b 1
call .\env.bat
del env.bat

if %GOHOSTARCH% == amd64 goto continue
echo Race detector is only supported on windows/amd64.
goto fail
if not %GOHOSTARCH% == amd64 (
echo Race detector is only supported on windows/amd64.
exit /b 1
)

:continue
call .\make.bat --no-banner || goto fail
echo # go install -race std
go install -race std || goto fail
go tool dist test -race || goto fail

echo All tests passed.
goto :eof

:fail
echo Fail.
exit /b 1
call .\make.bat --no-banner || exit /b 1
go install -race std || exit /b 1
go tool dist test -race || exit /b 1
16 changes: 6 additions & 10 deletions src/run.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,17 @@

@echo off

if exist ..\bin\go.exe goto ok
echo Must run run.bat from Go src directory after installing cmd/go.
goto fail
:ok
if not exist ..\bin\go.exe (
echo Must run run.bat from Go src directory after installing cmd/go.
exit /b 1
)

setlocal

set GOENV=off
..\bin\go tool dist env > env.bat || goto fail
..\bin\go tool dist env > env.bat || exit /b 1
call .\env.bat
del env.bat

set GOPATH=c:\nonexist-gopath
..\bin\go tool dist test --rebuild %* || goto fail
goto :eof

:fail
exit /b 1
..\bin\go tool dist test --rebuild %* || exit /b 1

0 comments on commit e9eb88a

Please sign in to comment.