cipd.bat 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. @echo off
  2. :: Copyright (c) 2016 The Chromium Authors. All rights reserved.
  3. :: Use of this source code is governed by a BSD-style license that can be
  4. :: found in the LICENSE file.
  5. setlocal
  6. set CIPD_BACKEND=https://chrome-infra-packages.appspot.com
  7. set VERSION_FILE=%~dp0cipd_client_version
  8. set CIPD_BINARY=%~dp0.cipd_client.exe
  9. set CIPD_PLATFORM=windows-amd64
  10. set PLATFORM_OVERRIDE_FILE=%~dp0.cipd_client_platform
  11. :: Uncomment to recognize arm64 by default.
  12. :: if %PROCESSOR_ARCHITECTURE%==ARM64 (
  13. :: set CIPD_PLATFORM=windows-arm64
  14. :: )
  15. :: A value in .cipd_client_platform overrides the "guessed" platform.
  16. if exist "%PLATFORM_OVERRIDE_FILE%" (
  17. for /F usebackq %%l in ("%PLATFORM_OVERRIDE_FILE%") do (
  18. set CIPD_PLATFORM=%%l
  19. )
  20. )
  21. :: Nuke the existing client if its platform doesn't match what we want now. We
  22. :: crudely search for a CIPD client package name in the .cipd_version JSON file.
  23. :: It has only "instance_id" as the other field (looking like a base64 string),
  24. :: so mismatches are very unlikely.
  25. set INSTALLED_VERSION_FILE=%~dp0.versions\.cipd_client.exe.cipd_version
  26. findstr /m "infra/tools/cipd/%CIPD_PLATFORM%" "%INSTALLED_VERSION_FILE%" 1>nul 2>nul
  27. if %ERRORLEVEL% neq 0 (
  28. if exist "%INSTALLED_VERSION_FILE%" (
  29. echo Detected CIPD client platform change to %CIPD_PLATFORM%. 1>&2
  30. echo Deleting the existing client to trigger the bootstrap... 1>&2
  31. del "%CIPD_BINARY%"
  32. del "%INSTALLED_VERSION_FILE%"
  33. )
  34. )
  35. if not exist "%CIPD_BINARY%" (
  36. call :CLEAN_BOOTSTRAP
  37. goto :EXEC_CIPD
  38. )
  39. call :SELF_UPDATE >nul 2>&1
  40. if %ERRORLEVEL% neq 0 (
  41. echo CIPD client self-update failed, trying to bootstrap it from scratch... 1>&2
  42. call :CLEAN_BOOTSTRAP
  43. )
  44. :EXEC_CIPD
  45. if %ERRORLEVEL% neq 0 (
  46. echo Failed to bootstrap or update CIPD client 1>&2
  47. )
  48. if %ERRORLEVEL% equ 0 (
  49. "%CIPD_BINARY%" %*
  50. )
  51. endlocal & (
  52. set EXPORT_ERRORLEVEL=%ERRORLEVEL%
  53. )
  54. exit /b %EXPORT_ERRORLEVEL%
  55. :: Functions below.
  56. ::
  57. :: See http://steve-jansen.github.io/guides/windows-batch-scripting/part-7-functions.html
  58. :: if you are unfamiliar with this madness.
  59. :CLEAN_BOOTSTRAP
  60. :: To allow this powershell script to run if it was a byproduct of downloading
  61. :: and unzipping the depot_tools.zip distribution, we clear the Zone.Identifier
  62. :: alternate data stream. This is equivalent to clicking the "Unblock" button
  63. :: in the file's properties dialog.
  64. echo.>"%~dp0.cipd_impl.ps1:Zone.Identifier"
  65. powershell -NoProfile -ExecutionPolicy RemoteSigned ^
  66. "%~dp0.cipd_impl.ps1" ^
  67. -CipdBinary "%CIPD_BINARY%" ^
  68. -Platform "%CIPD_PLATFORM%" ^
  69. -BackendURL "%CIPD_BACKEND%" ^
  70. -VersionFile "%VERSION_FILE%" ^
  71. <nul
  72. if %ERRORLEVEL% equ 0 (
  73. :: Need to call SELF_UPDATE to setup .cipd_version file.
  74. call :SELF_UPDATE
  75. )
  76. exit /B %ERRORLEVEL%
  77. :SELF_UPDATE
  78. "%CIPD_BINARY%" selfupdate ^
  79. -version-file "%VERSION_FILE%" ^
  80. -service-url "%CIPD_BACKEND%"
  81. exit /B %ERRORLEVEL%