Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions release/kokoro/build_windows.bat
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,25 @@
:: Core Bazel Build script for CEL Python on Windows.

echo === Loading Environment Configuration ===
call "%~dp0set_env_windows.bat"
call "%~dp0set_env_windows.bat" %1
if !ERRORLEVEL! NEQ 0 (
echo Failed to configure build environment!
exit /b 1
)

set "BUILD_STATUS=0"

echo --- Backing up MODULE.bazel ---
copy MODULE.bazel MODULE.bazel.bak >nul

echo --- Dynamically Adjusting Python Version in MODULE.bazel ---
!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!\"'))"
if !ERRORLEVEL! NEQ 0 (
echo Failed to modify MODULE.bazel!
set "BUILD_STATUS=1"
goto cleanup
)

:: Fetch dependencies. We perform multiple attempts to absorb transient flaky network connections.
echo --- Fetching Dependencies ---
set ATTEMPTS=0
Expand All @@ -42,8 +55,8 @@ if !FETCH_STATUS! NEQ 0 (
)
)
echo Fetch failed permanently or max attempts reached.
if exist fetch.log del fetch.log
exit /b 1
set "BUILD_STATUS=1"
goto cleanup
)
if exist fetch.log del fetch.log

Expand All @@ -53,7 +66,7 @@ set "OUTPUT_BASE=!OUTPUT_BASE:/=\!"
echo Output Base: !OUTPUT_BASE!

echo --- Resolving Hermetic Python Toolchain ---
for /f "tokens=*" %%A in ('dir /b /ad "!OUTPUT_BASE!\external\*python_3_11_host" 2^>nul') do set "PY_HOST_DIR=%%A"
for /f "tokens=*" %%A in ('dir /b /ad "!OUTPUT_BASE!\external\*python_!PY_VER_UNDERSCORE!_host" 2^>nul') do set "PY_HOST_DIR=%%A"
echo Hermetic Python Directory: !PY_HOST_DIR!

if not "!PY_HOST_DIR!" == "" (
Expand Down Expand Up @@ -87,7 +100,18 @@ echo --- Bazel Build ---
bazel %STARTUP_FLAGS% build %LINK_FLAGS% //...
if !ERRORLEVEL! NEQ 0 (
echo Build failed!
exit /b 1
set "BUILD_STATUS=1"
goto cleanup
)

echo --- Build Success ---

:cleanup
if exist fetch.log del fetch.log
if exist MODULE.bazel.bak (
echo --- Restoring MODULE.bazel ---
move /y MODULE.bazel.bak MODULE.bazel >nul
)
if "%BUILD_STATUS%" NEQ "0" (
exit /b %BUILD_STATUS%
)
45 changes: 35 additions & 10 deletions release/kokoro/presubmit_windows.bat
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,43 @@ setlocal enabledelayedexpansion
:: presubmit_windows.bat
:: Kokoro entrypoint for Windows Presubmit builds.

echo === Launching Windows Build Workflow ===
call "%~dp0build_windows.bat"
if !ERRORLEVEL! NEQ 0 (
echo Windows Presubmit Build FAILED!
exit /b 1
set "IN_PRESUBMIT=1"
set "PRESUBMIT_STATUS=0"
if "%PYTHON_VERSIONS%" == "" (
set "PYTHON_VERSIONS=3.11"
)

echo --- Bazel Test ---
bazel %STARTUP_FLAGS% test %LINK_FLAGS% --test_output=errors //...
if !ERRORLEVEL! NEQ 0 (
echo Tests failed!
exit /b 1
echo === Launching Windows Build Workflow ===
for %%V in (%PYTHON_VERSIONS%) do (
echo --- Building Python %%V ---
call "%~dp0build_windows.bat" %%V
if !ERRORLEVEL! NEQ 0 (
echo Windows Presubmit Build FAILED for Python %%V!
set "PRESUBMIT_STATUS=1"
goto cleanup
)

echo --- Bazel Test Python %%V ---
bazel %STARTUP_FLAGS% test %LINK_FLAGS% --test_output=errors //...
if !ERRORLEVEL! NEQ 0 (
echo Tests failed for Python %%V!
set "PRESUBMIT_STATUS=1"
goto cleanup
)

if exist MODULE.bazel.bak (
echo --- Restoring MODULE.bazel ---
move /y MODULE.bazel.bak MODULE.bazel >nul
)
)

echo Windows Presubmit Build and Tests PASSED!

:cleanup
if exist MODULE.bazel.bak (
echo --- Restoring MODULE.bazel ---
move /y MODULE.bazel.bak MODULE.bazel >nul
)
if "%PRESUBMIT_STATUS%" NEQ "0" (
exit /b %PRESUBMIT_STATUS%
)
20 changes: 13 additions & 7 deletions release/kokoro/set_env_windows.bat
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,21 @@ echo STARTUP_FLAGS set to %STARTUP_FLAGS%
echo --- Bazel Version ---
bazel %STARTUP_FLAGS% version

set "PYTHON_VERSION=%~1"
if "%PYTHON_VERSION%" == "" (
set "PYTHON_VERSION=3.11"
)
set "PY_VER_UNDERSCORE=%PYTHON_VERSION:.=_%"
set "PY_VER_NO_DOT=%PYTHON_VERSION:.=%"

echo Python Version Selected: %PYTHON_VERSION%

:: Detect Python executable first (needed for downloading BCR assets dynamically)
set PYTHON_EXE=python
where python3.11 >nul 2>&1
where python%PYTHON_VERSION% >nul 2>&1
if !ERRORLEVEL! EQU 0 (
set PYTHON_EXE=python3.11
) else if exist C:\Python311\python.exe (
set PYTHON_EXE=C:\Python311\python.exe
set PYTHON_EXE=python%PYTHON_VERSION%
) else if exist C:\Python%PY_VER_NO_DOT%\python.exe (
set PYTHON_EXE=C:\Python%PY_VER_NO_DOT%\python.exe
)
echo Python set to %PYTHON_EXE%

echo --- Python Version ---
!PYTHON_EXE! --version
Loading