diff --git a/.cipd_impl.ps1 b/.cipd_impl.ps1 index eb83751315..ce8091413f 100644 --- a/.cipd_impl.ps1 +++ b/.cipd_impl.ps1 @@ -11,19 +11,29 @@ # -VersionFile ./cipd_client_version # file _cipd.exe -Param( - # Path to download the CIPD binary to. - [parameter(Mandatory=$true)][string]$CipdBinary, - # E.g. "https://chrome-infra-packages.appspot.com". - [parameter(Mandatory=$true)][string]$BackendURL, - # Path to the cipd_client_version file with the client version. - [parameter(Mandatory=$true)][string]$VersionFile +param( + # Path to download the CIPD binary to. + [Parameter(Mandatory = $true)] + [string] + $CipdBinary, + + # CIPD platform to download the client for. + [string] + $Platform = "windows-amd64", + + # E.g. "https://chrome-infra-packages.appspot.com". + [Parameter(Mandatory = $true)] + [string] + $BackendURL, + + # Path to the cipd_client_version file with the client version. + [Parameter(Mandatory = $true)] + [string] + $VersionFile ) $DepotToolsPath = Split-Path $MyInvocation.MyCommand.Path -Parent -$Platform = "windows-amd64" - # Put depot_tool's git revision into the user agent string. try { $DepotToolsVersion = &git -C $DepotToolsPath rev-parse HEAD 2>&1 diff --git a/cipd.bat b/cipd.bat index e0312921e7..d44f9ad625 100644 --- a/cipd.bat +++ b/cipd.bat @@ -8,6 +8,35 @@ setlocal set CIPD_BACKEND=https://chrome-infra-packages.appspot.com set VERSION_FILE=%~dp0cipd_client_version set CIPD_BINARY=%~dp0.cipd_client.exe +set CIPD_PLATFORM=windows-amd64 +set PLATFORM_OVERRIDE_FILE=%~dp0.cipd_client_platform + +:: Uncomment to recognize arm64 by default. +:: if %PROCESSOR_ARCHITECTURE%==ARM64 ( +:: set CIPD_PLATFORM=windows-arm64 +:: ) + +:: A value in .cipd_client_platform overrides the "guessed" platform. +if exist "%PLATFORM_OVERRIDE_FILE%" ( + for /F usebackq %%l in ("%PLATFORM_OVERRIDE_FILE%") do ( + set CIPD_PLATFORM=%%l + ) +) + +:: Nuke the existing client if its platform doesn't match what we want now. We +:: crudely search for a CIPD client package name in the .cipd_version JSON file. +:: It has only "instance_id" as the other field (looking like a base64 string), +:: so mismatches are very unlikely. +set INSTALLED_VERSION_FILE=%~dp0.versions\.cipd_client.exe.cipd_version +findstr /m "infra/tools/cipd/%CIPD_PLATFORM%" "%INSTALLED_VERSION_FILE%" 2>nul +if %ERRORLEVEL% neq 0 ( + if exist "%INSTALLED_VERSION_FILE%" ( + echo Detected CIPD client platform change to %CIPD_PLATFORM%. 1>&2 + echo Deleting the existing client to trigger the bootstrap... 1>&2 + del "%CIPD_BINARY%" + del "%INSTALLED_VERSION_FILE%" + ) +) if not exist "%CIPD_BINARY%" ( call :CLEAN_BOOTSTRAP @@ -50,6 +79,7 @@ echo.>"%~dp0.cipd_impl.ps1:Zone.Identifier" powershell -NoProfile -ExecutionPolicy RemoteSigned ^ -File "%~dp0.cipd_impl.ps1" ^ -CipdBinary "%CIPD_BINARY%" ^ + -Platform "%CIPD_PLATFORM%" ^ -BackendURL "%CIPD_BACKEND%" ^ -VersionFile "%VERSION_FILE%" ^