Welcome to mirror list, hosted at ThFree Co, Russian Federation.

install-tool.ps1 « native « common « eng - github.com/mono/cecil.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 78f2d84a4e4b11046a4a694a46694fb9d4e49593 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<#
.SYNOPSIS
Install native tool

.DESCRIPTION
Install cmake native tool from Azure blob storage

.PARAMETER InstallPath
Base directory to install native tool to

.PARAMETER BaseUri
Base file directory or Url from which to acquire tool archives

.PARAMETER CommonLibraryDirectory
Path to folder containing common library modules

.PARAMETER Force
Force install of tools even if they previously exist

.PARAMETER Clean
Don't install the tool, just clean up the current install of the tool

.PARAMETER DownloadRetries
Total number of retry attempts

.PARAMETER RetryWaitTimeInSeconds
Wait time between retry attempts in seconds

.NOTES
Returns 0 if install succeeds, 1 otherwise
#>
[CmdletBinding(PositionalBinding=$false)]
Param (
  [Parameter(Mandatory=$True)]
  [string] $ToolName,
  [Parameter(Mandatory=$True)]
  [string] $InstallPath,
  [Parameter(Mandatory=$True)]
  [string] $BaseUri,
  [Parameter(Mandatory=$True)]
  [string] $Version,
  [string] $CommonLibraryDirectory = $PSScriptRoot,
  [switch] $Force = $False,
  [switch] $Clean = $False,
  [int] $DownloadRetries = 5,
  [int] $RetryWaitTimeInSeconds = 30
)

. $PSScriptRoot\..\pipeline-logging-functions.ps1

# Import common library modules
Import-Module -Name (Join-Path $CommonLibraryDirectory "CommonLibrary.psm1")

try {
  # Define verbose switch if undefined
  $Verbose = $VerbosePreference -Eq "Continue"

  $Arch = CommonLibrary\Get-MachineArchitecture
  $ToolOs = "win64"
  if($Arch -Eq "x32") {
    $ToolOs = "win32"
  }
  $ToolNameMoniker = "$ToolName-$Version-$ToolOs-$Arch"
  $ToolInstallDirectory = Join-Path $InstallPath "$ToolName\$Version\"
  $Uri = "$BaseUri/windows/$ToolName/$ToolNameMoniker.zip"
  $ShimPath = Join-Path $InstallPath "$ToolName.exe"

  if ($Clean) {
    Write-Host "Cleaning $ToolInstallDirectory"
    if (Test-Path $ToolInstallDirectory) {
      Remove-Item $ToolInstallDirectory -Force -Recurse
    }
    Write-Host "Cleaning $ShimPath"
    if (Test-Path $ShimPath) {
      Remove-Item $ShimPath -Force
    }
    $ToolTempPath = CommonLibrary\Get-TempPathFilename -Path $Uri
    Write-Host "Cleaning $ToolTempPath"
    if (Test-Path $ToolTempPath) {
      Remove-Item $ToolTempPath -Force
    }
    exit 0
  }

  # Install tool
  if ((Test-Path $ToolInstallDirectory) -And (-Not $Force)) {
    Write-Verbose "$ToolName ($Version) already exists, skipping install"
  }
  else {
    $InstallStatus = CommonLibrary\DownloadAndExtract -Uri $Uri `
                                                      -InstallDirectory $ToolInstallDirectory `
                                                      -Force:$Force `
                                                      -DownloadRetries $DownloadRetries `
                                                      -RetryWaitTimeInSeconds $RetryWaitTimeInSeconds `
                                                      -Verbose:$Verbose

    if ($InstallStatus -Eq $False) {
      Write-PipelineTelemetryError "Installation failed" -Category "NativeToolsetBootstrapping"
      exit 1
    }
  }

  $ToolFilePath = Get-ChildItem $ToolInstallDirectory -Recurse -Filter "$ToolName.exe" | % { $_.FullName }
  if (@($ToolFilePath).Length -Gt 1) {
    Write-Error "There are multiple copies of $ToolName in $($ToolInstallDirectory): `n$(@($ToolFilePath | out-string))"
    exit 1
  } elseif (@($ToolFilePath).Length -Lt 1) {
    Write-Host "$ToolName was not found in $ToolInstallDirectory."
    exit 1
  }

  # Generate shim
  # Always rewrite shims so that we are referencing the expected version
  $GenerateShimStatus = CommonLibrary\New-ScriptShim -ShimName $ToolName `
                                                     -ShimDirectory $InstallPath `
                                                     -ToolFilePath "$ToolFilePath" `
                                                     -BaseUri $BaseUri `
                                                     -Force:$Force `
                                                     -Verbose:$Verbose

  if ($GenerateShimStatus -Eq $False) {
    Write-PipelineTelemetryError "Generate shim failed" -Category "NativeToolsetBootstrapping"
    return 1
  }

  exit 0
}
catch {
  Write-Host $_.ScriptStackTrace
  Write-PipelineTelemetryError -Category "NativeToolsetBootstrapping" -Message $_
  exit 1
}