msbuild

Форк
0
/
install-tool.ps1 
132 строки · 4.2 Кб
1
<#
2
.SYNOPSIS
3
Install native tool
4

5
.DESCRIPTION
6
Install cmake native tool from Azure blob storage
7

8
.PARAMETER InstallPath
9
Base directory to install native tool to
10

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

14
.PARAMETER CommonLibraryDirectory
15
Path to folder containing common library modules
16

17
.PARAMETER Force
18
Force install of tools even if they previously exist
19

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

23
.PARAMETER DownloadRetries
24
Total number of retry attempts
25

26
.PARAMETER RetryWaitTimeInSeconds
27
Wait time between retry attempts in seconds
28

29
.NOTES
30
Returns 0 if install succeeds, 1 otherwise
31
#>
32
[CmdletBinding(PositionalBinding=$false)]
33
Param (
34
  [Parameter(Mandatory=$True)]
35
  [string] $ToolName,
36
  [Parameter(Mandatory=$True)]
37
  [string] $InstallPath,
38
  [Parameter(Mandatory=$True)]
39
  [string] $BaseUri,
40
  [Parameter(Mandatory=$True)]
41
  [string] $Version,
42
  [string] $CommonLibraryDirectory = $PSScriptRoot,
43
  [switch] $Force = $False,
44
  [switch] $Clean = $False,
45
  [int] $DownloadRetries = 5,
46
  [int] $RetryWaitTimeInSeconds = 30
47
)
48

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

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

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

58
  $Arch = CommonLibrary\Get-MachineArchitecture
59
  $ToolOs = "win64"
60
  if($Arch -Eq "x32") {
61
    $ToolOs = "win32"
62
  }
63
  $ToolNameMoniker = "$ToolName-$Version-$ToolOs-$Arch"
64
  $ToolInstallDirectory = Join-Path $InstallPath "$ToolName\$Version\"
65
  $Uri = "$BaseUri/windows/$ToolName/$ToolNameMoniker.zip"
66
  $ShimPath = Join-Path $InstallPath "$ToolName.exe"
67

68
  if ($Clean) {
69
    Write-Host "Cleaning $ToolInstallDirectory"
70
    if (Test-Path $ToolInstallDirectory) {
71
      Remove-Item $ToolInstallDirectory -Force -Recurse
72
    }
73
    Write-Host "Cleaning $ShimPath"
74
    if (Test-Path $ShimPath) {
75
      Remove-Item $ShimPath -Force
76
    }
77
    $ToolTempPath = CommonLibrary\Get-TempPathFilename -Path $Uri
78
    Write-Host "Cleaning $ToolTempPath"
79
    if (Test-Path $ToolTempPath) {
80
      Remove-Item $ToolTempPath -Force
81
    }
82
    exit 0
83
  }
84

85
  # Install tool
86
  if ((Test-Path $ToolInstallDirectory) -And (-Not $Force)) {
87
    Write-Verbose "$ToolName ($Version) already exists, skipping install"
88
  }
89
  else {
90
    $InstallStatus = CommonLibrary\DownloadAndExtract -Uri $Uri `
91
                                                      -InstallDirectory $ToolInstallDirectory `
92
                                                      -Force:$Force `
93
                                                      -DownloadRetries $DownloadRetries `
94
                                                      -RetryWaitTimeInSeconds $RetryWaitTimeInSeconds `
95
                                                      -Verbose:$Verbose
96

97
    if ($InstallStatus -Eq $False) {
98
      Write-PipelineTelemetryError "Installation failed" -Category "NativeToolsetBootstrapping"
99
      exit 1
100
    }
101
  }
102

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

112
  # Generate shim
113
  # Always rewrite shims so that we are referencing the expected version
114
  $GenerateShimStatus = CommonLibrary\New-ScriptShim -ShimName $ToolName `
115
                                                     -ShimDirectory $InstallPath `
116
                                                     -ToolFilePath "$ToolFilePath" `
117
                                                     -BaseUri $BaseUri `
118
                                                     -Force:$Force `
119
                                                     -Verbose:$Verbose
120

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

126
  exit 0
127
}
128
catch {
129
  Write-Host $_.ScriptStackTrace
130
  Write-PipelineTelemetryError -Category "NativeToolsetBootstrapping" -Message $_
131
  exit 1
132
}
133

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.