Skip to content

Commit 78b2d31

Browse files
dmitriplotnikovcopybara-github
authored andcommitted
Simplify Windows presubmit setup for cel-python.
Fold build_windows.bat into presubmit_windows.bat and rename build_windows.cfg to presubmit_windows.cfg to improve consistency with release workflows. PiperOrigin-RevId: 922419089
1 parent d3dd6f4 commit 78b2d31

3 files changed

Lines changed: 74 additions & 107 deletions

File tree

release/kokoro/build_windows.bat

Lines changed: 0 additions & 105 deletions
This file was deleted.

release/kokoro/presubmit_windows.bat

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,80 @@ if "%PYTHON_VERSIONS%" == "" (
2626
echo === Launching Windows Build Workflow ===
2727
for %%V in (%PYTHON_VERSIONS%) do (
2828
echo --- Building Python %%V ---
29-
call "%~dp0build_windows.bat" %%V
29+
30+
echo === Loading Environment Configuration ===
31+
call "%~dp0set_env_windows.bat" %%V
32+
if !ERRORLEVEL! NEQ 0 (
33+
echo Failed to configure build environment!
34+
set "PRESUBMIT_STATUS=1"
35+
goto cleanup
36+
)
37+
38+
set "BUILD_STATUS=0"
39+
40+
echo --- Backing up MODULE.bazel ---
41+
copy MODULE.bazel MODULE.bazel.bak >nul
42+
43+
echo --- Dynamically Adjusting Python Version in MODULE.bazel ---
44+
!PYTHON_EXE! -c "import sys; path='MODULE.bazel'; content=open(path).read(); open(path,'w').write(content.replace('python_version = \"3.11\"', 'python_version = \"!PYTHON_VERSION!\"'))"
45+
if !ERRORLEVEL! NEQ 0 (
46+
echo Failed to modify MODULE.bazel!
47+
set "PRESUBMIT_STATUS=1"
48+
goto cleanup
49+
)
50+
51+
:: Fetch dependencies. We perform multiple attempts to absorb transient flaky network connections.
52+
echo --- Fetching Dependencies ---
53+
set ATTEMPTS=0
54+
:fetch_loop
55+
set /a ATTEMPTS+=1
56+
echo Fetch attempt !ATTEMPTS! of %FETCH_RETRIES%...
57+
bazel %STARTUP_FLAGS% fetch //... > fetch.log 2>&1
58+
set FETCH_STATUS=!ERRORLEVEL!
59+
type fetch.log
60+
if !FETCH_STATUS! NEQ 0 (
61+
findstr /i "timeout timed" fetch.log >nul
62+
if !ERRORLEVEL! EQU 0 (
63+
if !ATTEMPTS! LSS %FETCH_RETRIES% (
64+
echo Fetch failed with timeout. Retrying in %FETCH_RETRY_DELAY_S% seconds...
65+
:: Use ping instead of timeout because timeout command fails in non-interactive Kokoro environments
66+
:: with "ERROR: Input redirection is not supported, exiting the process immediately."
67+
set /a PINGS=%FETCH_RETRY_DELAY_S%+1
68+
ping -n !PINGS! 127.0.0.1 >nul
69+
goto fetch_loop
70+
)
71+
)
72+
echo Fetch failed permanently or max attempts reached.
73+
set "PRESUBMIT_STATUS=1"
74+
goto cleanup
75+
)
76+
if exist fetch.log del fetch.log
77+
78+
echo --- Getting Output Base ---
79+
for /f "tokens=*" %%i in ('bazel %STARTUP_FLAGS% info output_base') do set "OUTPUT_BASE=%%i"
80+
set "OUTPUT_BASE=!OUTPUT_BASE:/=\!"
81+
echo Output Base: !OUTPUT_BASE!
82+
83+
echo --- Resolving Hermetic Python Toolchain ---
84+
for /f "tokens=*" %%A in ('dir /b /ad "!OUTPUT_BASE!\external\*python_!PY_VER_UNDERSCORE!_host" 2^>nul') do set "PY_HOST_DIR=%%A"
85+
echo Hermetic Python Directory: !PY_HOST_DIR!
86+
87+
if not "!PY_HOST_DIR!" == "" (
88+
echo --- Copying Hermetic Python import library to space-free directory ---
89+
if not exist C:\tmp\python_libs mkdir C:\tmp\python_libs
90+
copy "!OUTPUT_BASE!\external\!PY_HOST_DIR!\libs\python*.lib" C:\tmp\python_libs\
91+
echo --- Copying Hermetic Python DLL to space-free directory ---
92+
copy "!OUTPUT_BASE!\external\!PY_HOST_DIR!\python*.dll" C:\tmp\python_libs\
93+
set "LINK_FLAGS=--linkopt=/LIBPATH:C:\tmp\python_libs --action_env=PATH"
94+
set "PATH=C:\tmp\python_libs;!PATH!"
95+
) else (
96+
echo Warning: Hermetic Python directory not found! Skipping import library copy.
97+
)
98+
99+
echo --- Bazel Build ---
100+
bazel %STARTUP_FLAGS% build %LINK_FLAGS% //...
30101
if !ERRORLEVEL! NEQ 0 (
31-
echo Windows Presubmit Build FAILED for Python %%V!
102+
echo Build failed!
32103
set "PRESUBMIT_STATUS=1"
33104
goto cleanup
34105
)
@@ -50,6 +121,7 @@ for %%V in (%PYTHON_VERSIONS%) do (
50121
echo Windows Presubmit Build and Tests PASSED!
51122

52123
:cleanup
124+
if exist fetch.log del fetch.log
53125
if exist MODULE.bazel.bak (
54126
echo --- Restoring MODULE.bazel ---
55127
move /y MODULE.bazel.bak MODULE.bazel >nul

0 commit comments

Comments
 (0)