Skip to content

Commit afe10d8

Browse files
authored
Fix CI diagnostics for failed bazel builds on Windows (#42006)
### What does this PR do? CI diagnostics for failed `bazel` builds on Windows didn't work as expected (see #41844 for more details). The change consists in: - removing the pseudo-shebang that was preventing from resolving paths relative to the source script's location, - making sure the output is UTF-8 (`chcp 65001`) to echo non-ASCII characters from dumped contents, - using the right `bazel` startup flag (`--local_startup_timeout_secs`) to limit the total retry loop to 30s, while making the retries more frequent (`--connect_timeout_secs`) inside the loop, - no longer assuming `$CI_PROJECT_DIR` resolves to the workspace's root, - payload: fixing/discovering base location for server logs which happen to be under a subdirectory whose name is a hash (`jgkidtko` on my VM). ### Motivation Really get actionable outputs for addressing `FATAL: couldn't connect to server` errors. ### Describe how you validated your changes Reproduced CI layout locally and fixed the script to make it provide with available info on `bazel` build failures. ### Additional Notes This is of course temporary until we figure out what's preventing the `bazel` CLI from contacting the server.
1 parent 4a24410 commit afe10d8

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

tools/bazel.bat

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
@echo off & setlocal EnableDelayedExpansion & if not defined bb (set "bb=%TEMP%\%~n0-%RANDOM%.bat" & more /e /p "%~f0" >"!bb!" & call "!bb!" %* & set "rc=!errorlevel!" & del /q "!bb!" & exit /b !rc!)
2-
:: Above one-liner copies the present script to a temporary file with normalized Windows line endings and executes it.
3-
:: Works regardless of actual source line endings because the pseudo-shebang is interpreted before the first newline.
1+
@echo off & setlocal EnableDelayedExpansion
2+
>nul chcp 65001
43

54
:: Check `bazelisk` properly bootstraps `bazel` or fail with instructions
65
if not defined BAZEL_REAL (
@@ -41,12 +40,13 @@ if exist "!BAZEL_REPO_CONTENTS_CACHE!" (
4140

4241
:: Pass CI-specific options through `.user.bazelrc` so any nested `bazel run` and next `bazel shutdown` also honor them
4342
(
44-
echo startup --connect_timeout_secs=30
43+
echo startup --connect_timeout_secs=5 # instead of 30s, for quicker iterations in diagnostics
44+
echo startup --local_startup_timeout_secs=30 # instead of 120s, to fail faster for diagnostics
4545
echo startup --output_user_root=!BAZEL_OUTPUT_USER_ROOT!
4646
echo common --config=cache
4747
echo common --repo_contents_cache=!ext_repo_contents_cache!
4848
echo build --disk_cache=!BAZEL_DISK_CACHE!
49-
) >"%CI_PROJECT_DIR%\user.bazelrc"
49+
) >"%~dp0..\user.bazelrc"
5050

5151
:: Diagnostics: print any stalled client/server before `bazel` execution
5252
>&2 powershell -NoProfile -Command "Get-Process bazel,java -ErrorAction SilentlyContinue | Select-Object 🟡,ProcessName,StartTime"
@@ -55,16 +55,22 @@ if exist "!BAZEL_REPO_CONTENTS_CACHE!" (
5555
"%BAZEL_REAL%" %*
5656
set "bazel_exit=!errorlevel!"
5757

58-
:: Diagnostics: dump JVM output on failure
58+
:: Diagnostics: dump logs on failure
5959
if !bazel_exit! neq 0 (
60-
>&2 echo 🟡 JVM output:
61-
>&2 type "!BAZEL_OUTPUT_USER_ROOT!\server\jvm.out"
60+
>&2 echo 🟡 Bazel failed, dumping available info:
61+
for /d %%d in ("!BAZEL_OUTPUT_USER_ROOT!\*") do (
62+
for %%f in ("%%d\java.log.*" "%%d\server\*") do (
63+
>&2 echo 🟡 %%f:
64+
>&2 type "%%f"
65+
>&2 echo.
66+
)
67+
)
6268
exit /b !bazel_exit!
6369
)
6470

6571
:: Stop `bazel` (if still running) to close files and proceed with cleanup
6672
>&2 "%BAZEL_REAL%" shutdown --ui_event_filters=-info
67-
>&2 del /f /q "%CI_PROJECT_DIR%\user.bazelrc"
73+
>&2 del /f /q "%~dp0..\user.bazelrc"
6874

6975
:: Reintegrate `--repo_contents_cache` to original directory
7076
if exist "!ext_repo_contents_cache!" (

0 commit comments

Comments
 (0)