blob: 32ec2b461e274f57d3837920a47e5da89b8fa9f4 [file] [log] [blame]
Robert Iannucci2188fe92016-12-02 19:15:571# Copyright (c) 2016 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5$myPath = Split-Path $MyInvocation.MyCommand.Path -Parent
6
7function GetEnvVar([string] $key, [scriptblock] $defaultFn) {
8 if (Test-Path "Env:\$key") {
9 return Get-ChildItem $Env $key
10 }
11 return $defaultFn.Invoke()
12}
13
14$cipdClientVer = GetEnvVar "CIPD_CLIENT_VER" {
Robert Iannuccibe3daff2016-12-15 02:42:5215 Get-Content (Join-Path $myPath -ChildPath 'cipd_client_version') -TotalCount 1
Robert Iannucci2188fe92016-12-02 19:15:5716}
17$cipdClientSrv = GetEnvVar "CIPD_CLIENT_SRV" {
18 "https://chrome-infra-packages.appspot.com"
19}
20
21$plat="windows"
22if ([environment]::Is64BitOperatingSystem) {
23 $arch="amd64"
24} else {
25 $arch="386"
26}
27
28$url = "$cipdClientSrv/client?platform=$plat-$arch&version=$cipdClientVer"
29$client = Join-Path $myPath -ChildPath ".cipd_client.exe"
30
31$depot_tools_version = &git -C $myPath rev-parse HEAD 2>&1
32if ($LastExitCode -eq 0) {
33 $user_agent = "depot_tools/$depot_tools_version"
34} else {
35 $user_agent = "depot_tools/???"
36}
37
38$Env:CIPD_HTTP_USER_AGENT_PREFIX = $user_agent
39if (!(Test-Path $client)) {
40 echo "Bootstrapping cipd client for $plat-$arch..."
41 echo "From $url"
42 # TODO(iannucci): It would be really nice if there was a way to get this to
43 # show progress without also completely destroying the download speed, but
44 # I can't seem to find a way to do it. Patches welcome :)
45 $wc = (New-Object System.Net.WebClient)
46 $wc.Headers.add('User-Agent', $user_agent)
47 $wc.DownloadFile($url, $client)
48}
49
50$_ = & $client selfupdate -version "$cipdClientVer"
51if ($LastExitCode -ne 0) {
52 Write-Host "selfupdate failed: " -ForegroundColor Red -NoNewline
53 Write-Host "run ``set CIPD_HTTP_USER_AGENT_PREFIX=$user_agent/manual && $client selfupdate -version $cipdClientVer`` to diagnose`n" -ForegroundColor White
54}
55
56& $client @args
57exit $LastExitCode