@@ -26,9 +26,80 @@ if "%PYTHON_VERSIONS%" == "" (
2626echo === Launching Windows Build Workflow ===
2727for %%V in (%PYTHON_VERSIONS% ) do (
2828 echo --- Building Python %%V ---
29- call " %~dp0 build_windows.bat" %%V
29+
30+ echo === Loading Environment Configuration ===
31+ call " %~dp0 set_env_windows.bat" %%V
3032 if !ERRORLEVEL! NEQ 0 (
31- echo Windows Presubmit Build FAILED for Python %%V !
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% //...
101+ if !ERRORLEVEL! NEQ 0 (
102+ echo Build failed!
32103 set " PRESUBMIT_STATUS = 1"
33104 goto cleanup
34105 )
@@ -50,10 +121,12 @@ for %%V in (%PYTHON_VERSIONS%) do (
50121echo Windows Presubmit Build and Tests PASSED!
51122
52123:cleanup
124+ if exist fetch.log del fetch.log
53125if exist MODULE.bazel.bak (
54126 echo --- Restoring MODULE.bazel ---
55127 move /y MODULE.bazel.bak MODULE.bazel > nul
56128)
57129if " %PRESUBMIT_STATUS% " NEQ " 0" (
58130 exit /b %PRESUBMIT_STATUS%
59131)
132+
0 commit comments