Skip to content

Commit ab104f8

Browse files
compiler: add retry loop and enable allowEmptyChecksums on Windows (#12962)
Enables allowEmptyChecksums globally on Chocolatey and implements a 3-attempt retry loop for pkgconfiglite to prevent Windows CI failures caused by transient network or SourceForge mirror errors. Even though --allow-empty-checksums is passed to choco install, newer Chocolatey versions do not propagate this CLI flag to the nested PowerShell installer script (chocolateyInstall.ps1). The inner script fails when downloading the binary from non-secure HTTP SourceForge mirrors unless the allowEmptyChecksums feature is globally enabled via choco feature beforehand. This change also makes the script exit prematurely if pkg-config installation still failed instead of continuing and failing later at the linking step. [Failed Kokoro build logs example](https://btx.cloud.google.com/invocations/f43affbc-6ace-4158-bac4-86779b985b2f/targets/grpc%2Fjava%2Fmaster%2Fpresubmit%2Fwindows;config=default/log).
1 parent 72c6e5f commit ab104f8

1 file changed

Lines changed: 40 additions & 7 deletions

File tree

buildscripts/make_dependencies.bat

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
choco install -y pkgconfiglite --allow-empty-checksums
1+
choco feature enable -n allowEmptyChecksums
2+
3+
set RETRY=0
4+
:install_pkgconfig
5+
choco install -y pkgconfiglite --allow-empty-checksums --force
6+
if %ERRORLEVEL% neq 0 (
7+
if %RETRY% lss 3 (
8+
set /a RETRY=%RETRY%+1
9+
echo pkgconfiglite installation failed. Retrying %RETRY% of 3 in 5 seconds...
10+
@rem Sleep for 5 seconds using the loopback ping trick (timeout command fails in non-interactive CI)
11+
ping -n 6 127.0.0.1 >nul
12+
goto :install_pkgconfig
13+
)
14+
echo Failed to install pkgconfiglite after 3 attempts.
15+
exit /b 1
16+
)
17+
218
choco install -y openjdk --version=17.0
319
set PATH=%PATH%;"c:\Program Files\OpenJDK\jdk-17\bin"
420
set PROTOBUF_VER=35.1
@@ -24,11 +40,11 @@ if not exist "%CMAKE_NAME%" (
2440
set PATH=%PATH%;%cd%\%CMAKE_NAME%\bin
2541
:hasCmake
2642
@rem GitHub requires TLSv1.2, and for whatever reason our powershell doesn't have it enabled
27-
powershell -command "$ProgressPreference = 'SilentlyContinue'; $ErrorActionPreference = 'stop'; & { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ; iwr https://github.com/google/protobuf/releases/download/v%PROTOBUF_VER%/protobuf-%PROTOBUF_VER%.zip -OutFile protobuf.zip }" || exit /b 1
28-
powershell -command "$ErrorActionPreference = 'stop'; & { Add-Type -AssemblyName System.IO.Compression.FileSystem; [System.IO.Compression.ZipFile]::ExtractToDirectory('protobuf.zip', '.') }" || exit /b 1
43+
call :RunPowershellWithRetry "$ProgressPreference = 'SilentlyContinue'; $ErrorActionPreference = 'stop'; & { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ; iwr https://github.com/google/protobuf/releases/download/v%PROTOBUF_VER%/protobuf-%PROTOBUF_VER%.zip -OutFile protobuf.zip }" || exit /b 1
44+
call :RunPowershellWithRetry "$ErrorActionPreference = 'stop'; & { Add-Type -AssemblyName System.IO.Compression.FileSystem; [System.IO.Compression.ZipFile]::ExtractToDirectory('protobuf.zip', '.') }" || exit /b 1
2945
del protobuf.zip
30-
powershell -command "$ProgressPreference = 'SilentlyContinue'; $ErrorActionPreference = 'stop'; & { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ; iwr https://github.com/abseil/abseil-cpp/archive/refs/tags/%ABSL_VERSION%.zip -OutFile absl.zip }" || exit /b 1
31-
powershell -command "$ErrorActionPreference = 'stop'; & { Add-Type -AssemblyName System.IO.Compression.FileSystem; [System.IO.Compression.ZipFile]::ExtractToDirectory('absl.zip', '.') }" || exit /b 1
46+
call :RunPowershellWithRetry "$ProgressPreference = 'SilentlyContinue'; $ErrorActionPreference = 'stop'; & { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ; iwr https://github.com/abseil/abseil-cpp/archive/refs/tags/%ABSL_VERSION%.zip -OutFile absl.zip }" || exit /b 1
47+
call :RunPowershellWithRetry "$ErrorActionPreference = 'stop'; & { Add-Type -AssemblyName System.IO.Compression.FileSystem; [System.IO.Compression.ZipFile]::ExtractToDirectory('absl.zip', '.') }" || exit /b 1
3248
del absl.zip
3349
move abseil-cpp-%ABSL_VERSION% protobuf-%PROTOBUF_VER%\third_party\abseil-cpp
3450
mkdir protobuf-%PROTOBUF_VER%\build
@@ -58,8 +74,25 @@ goto :eof
5874

5975
:installCmake
6076

61-
powershell -command "$ErrorActionPreference = 'stop'; & { iwr https://cmake.org/files/v3.3/%CMAKE_NAME%.zip -OutFile cmake.zip }" || exit /b 1
62-
powershell -command "$ErrorActionPreference = 'stop'; & { Add-Type -AssemblyName System.IO.Compression.FileSystem; [System.IO.Compression.ZipFile]::ExtractToDirectory('cmake.zip', '.') }" || exit /b 1
77+
call :RunPowershellWithRetry "$ErrorActionPreference = 'stop'; & { iwr https://cmake.org/files/v3.3/%CMAKE_NAME%.zip -OutFile cmake.zip }" || exit /b 1
78+
call :RunPowershellWithRetry "$ErrorActionPreference = 'stop'; & { Add-Type -AssemblyName System.IO.Compression.FileSystem; [System.IO.Compression.ZipFile]::ExtractToDirectory('cmake.zip', '.') }" || exit /b 1
6379
del cmake.zip
6480
goto :eof
6581

82+
@rem Helper to retry powershell commands (e.g. for transient network failures during iwr)
83+
:RunPowershellWithRetry
84+
set "PS_CMD=%~1"
85+
set PS_RETRY=0
86+
:ps_retry_loop
87+
powershell -command "%PS_CMD%"
88+
if %ERRORLEVEL% equ 0 exit /b 0
89+
if %PS_RETRY% lss 3 (
90+
set /a PS_RETRY=%PS_RETRY%+1
91+
echo PowerShell command failed. Retrying %PS_RETRY% of 3 in 5 seconds...
92+
ping -n 6 127.0.0.1 >nul
93+
goto :ps_retry_loop
94+
)
95+
echo PowerShell command failed after 3 attempts: %PS_CMD%
96+
exit /b 1
97+
98+

0 commit comments

Comments
 (0)