cipd.bat 1.76 KB
Newer Older
1 2 3 4 5
@echo off
:: Copyright (c) 2016 The Chromium Authors. All rights reserved.
:: Use of this source code is governed by a BSD-style license that can be
:: found in the LICENSE file.

6 7
setlocal

8 9 10
set CIPD_BACKEND=https://chrome-infra-packages.appspot.com
set VERSION_FILE="%~dp0cipd_client_version"
set CIPD_BINARY="%~dp0.cipd_client.exe"
11

12
if not exist %CIPD_BINARY% (
13 14 15
  call :CLEAN_BOOTSTRAP
  goto :EXEC_CIPD
)
16

17
call :SELF_UPDATE >nul 2>&1
18 19 20
if %ERRORLEVEL% neq 0 (
  echo CIPD client self-update failed, trying to bootstrap it from scratch... 1>&2
  call :CLEAN_BOOTSTRAP
21 22
)

23
:EXEC_CIPD
24

25 26 27 28
if %ERRORLEVEL% neq 0 (
  echo Failed to bootstrap or update CIPD client 1>&2
)
if %ERRORLEVEL% equ 0 (
29
  "%CIPD_BINARY%" %*
30
)
31

32
endlocal & (
33
  set EXPORT_ERRORLEVEL=%ERRORLEVEL%
34
)
35
exit /b %EXPORT_ERRORLEVEL%
36 37 38 39 40 41 42 43 44 45 46 47 48 49


:: Functions below.
::
:: See http://steve-jansen.github.io/guides/windows-batch-scripting/part-7-functions.html
:: if you are unfamiliar with this madness.


:CLEAN_BOOTSTRAP
:: To allow this powershell script to run if it was a byproduct of downloading
:: and unzipping the depot_tools.zip distribution, we clear the Zone.Identifier
:: alternate data stream. This is equivalent to clicking the "Unblock" button
:: in the file's properties dialog.
echo.>%~dp0cipd.ps1:Zone.Identifier
50 51 52 53 54 55
powershell -NoProfile -ExecutionPolicy RemoteSigned ^
    -Command "%~dp0cipd.ps1" ^
    -CipdBinary "%CIPD_BINARY%" ^
    -BackendURL "%CIPD_BACKEND%" ^
    -VersionFile "%VERSION_FILE%" ^
  <nul
56 57 58 59 60 61 62 63
if %ERRORLEVEL% equ 0 (
  :: Need to call SELF_UPDATE to setup .cipd_version file.
  call :SELF_UPDATE
)
exit /B %ERRORLEVEL%


:SELF_UPDATE
64 65 66
"%CIPD_BINARY%" selfupdate ^
    -version-file "%VERSION_FILE%" ^
    -service-url "%CIPD_BACKEND%"
67
exit /B %ERRORLEVEL%