From 4f3b322a39a668384bab321da1ca2e699a562a1b Mon Sep 17 00:00:00 2001 From: Vadim Shtayura Date: Thu, 12 Jan 2023 00:11:03 +0000 Subject: [PATCH] [cipd] Add windows-arm64 support to CIPD client bootstrap. This actually updates the CIPD client to a version that has a windows-arm64 build, as well as modifies the bootstrap script to support multiple possible Windows platforms (which is very similar to what was done to support mac-arm64 on OSX). By default windows-amd64 is still used everywhere, even on arm64 OS. To opt-in into windows-arm64, create a file .cipd_client_platform under depot_tools directory with a single line "windows-arm64". The bootstrap script now recognizes this file (if it exists) and rebootstraps the CIPD client if the platform changes. Since this check needs to happen on every CIPD invocation, it is done in the batch file, to avoid hitting relatively heavy Powershell on the hot path. Finally, do some minor style cleanup in the powershell script to make it look more consistent. CIPD client change log: https://chromium.googlesource.com/infra/luci/luci-go.git/+log/9cc9fd49..5252f4fc7/cipd R=bryner@google.com Change-Id: I4fe5c4ea5e0b5cbb43e7b8c4702dc9fb0627c056 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4153336 Reviewed-by: Brian Ryner Commit-Queue: Vadim Shtayura --- .cipd_impl.ps1 | 28 +++++++++++++++++++--------- cipd.bat | 30 ++++++++++++++++++++++++++++++ cipd_client_version | 2 +- cipd_client_version.digests | 35 ++++++++++++++++++----------------- 4 files changed, 68 insertions(+), 27 deletions(-) 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%" ^