blob: 973af4f1f8329b5d1b3fa0fb709a294ecb63e885 [file] [log] [blame]
Robert Iannucci2188fe92016-12-02 11:15:57 -08001# 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-14 18:42:52 -080015 Get-Content (Join-Path $myPath -ChildPath 'cipd_client_version') -TotalCount 1
Robert Iannucci2188fe92016-12-02 11:15:57 -080016}
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
Robert Iannucci78628da2017-04-24 18:21:39 -070031try {
32 $depot_tools_version = &git -C $myPath rev-parse HEAD 2>&1
33 if ($LastExitCode -eq 0) {
34 $user_agent = "depot_tools/$depot_tools_version"
35 } else {
36 $user_agent = "depot_tools/???"
37 }
38} catch [System.Management.Automation.CommandNotFoundException] {
39 $user_agent = "depot_tools/no_git/???"
Robert Iannucci2188fe92016-12-02 11:15:57 -080040}
41
42$Env:CIPD_HTTP_USER_AGENT_PREFIX = $user_agent
43if (!(Test-Path $client)) {
44 echo "Bootstrapping cipd client for $plat-$arch..."
45 echo "From $url"
46 # TODO(iannucci): It would be really nice if there was a way to get this to
47 # show progress without also completely destroying the download speed, but
48 # I can't seem to find a way to do it. Patches welcome :)
49 $wc = (New-Object System.Net.WebClient)
50 $wc.Headers.add('User-Agent', $user_agent)
51 $wc.DownloadFile($url, $client)
52}
53
54$_ = & $client selfupdate -version "$cipdClientVer"
55if ($LastExitCode -ne 0) {
56 Write-Host "selfupdate failed: " -ForegroundColor Red -NoNewline
57 Write-Host "run ``set CIPD_HTTP_USER_AGENT_PREFIX=$user_agent/manual && $client selfupdate -version $cipdClientVer`` to diagnose`n" -ForegroundColor White
58}
59
60& $client @args
61exit $LastExitCode