msbuild

Форк
0
/
init-tools-native.ps1 
203 строки · 7.8 Кб
1
<#
2
.SYNOPSIS
3
Entry point script for installing native tools
4

5
.DESCRIPTION
6
Reads $RepoRoot\global.json file to determine native assets to install
7
and executes installers for those tools
8

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

12
.PARAMETER InstallDirectory
13
Directory to install native toolset.  This is a command-line override for the default
14
Install directory precedence order:
15
- InstallDirectory command-line override
16
- NETCOREENG_INSTALL_DIRECTORY environment variable
17
- (default) %USERPROFILE%/.netcoreeng/native
18

19
.PARAMETER Clean
20
Switch specifying to not install anything, but cleanup native asset folders
21

22
.PARAMETER Force
23
Clean and then install tools
24

25
.PARAMETER DownloadRetries
26
Total number of retry attempts
27

28
.PARAMETER RetryWaitTimeInSeconds
29
Wait time between retry attempts in seconds
30

31
.PARAMETER GlobalJsonFile
32
File path to global.json file
33

34
.PARAMETER PathPromotion
35
Optional switch to enable either promote native tools specified in the global.json to the path (in Azure Pipelines)
36
or break the build if a native tool is not found on the path (on a local dev machine)
37

38
.NOTES
39
#>
40
[CmdletBinding(PositionalBinding=$false)]
41
Param (
42
  [string] $BaseUri = 'https://netcorenativeassets.blob.core.windows.net/resource-packages/external',
43
  [string] $InstallDirectory,
44
  [switch] $Clean = $False,
45
  [switch] $Force = $False,
46
  [int] $DownloadRetries = 5,
47
  [int] $RetryWaitTimeInSeconds = 30,
48
  [string] $GlobalJsonFile,
49
  [switch] $PathPromotion
50
)
51

52
if (!$GlobalJsonFile) {
53
  $GlobalJsonFile = Join-Path (Get-Item $PSScriptRoot).Parent.Parent.FullName 'global.json'
54
}
55

56
Set-StrictMode -version 2.0
57
$ErrorActionPreference='Stop'
58

59
. $PSScriptRoot\pipeline-logging-functions.ps1
60
Import-Module -Name (Join-Path $PSScriptRoot 'native\CommonLibrary.psm1')
61

62
try {
63
  # Define verbose switch if undefined
64
  $Verbose = $VerbosePreference -Eq 'Continue'
65

66
  $EngCommonBaseDir = Join-Path $PSScriptRoot 'native\'
67
  $NativeBaseDir = $InstallDirectory
68
  if (!$NativeBaseDir) {
69
    $NativeBaseDir = CommonLibrary\Get-NativeInstallDirectory
70
  }
71
  $Env:CommonLibrary_NativeInstallDir = $NativeBaseDir
72
  $InstallBin = Join-Path $NativeBaseDir 'bin'
73
  $InstallerPath = Join-Path $EngCommonBaseDir 'install-tool.ps1'
74

75
  # Process tools list
76
  Write-Host "Processing $GlobalJsonFile"
77
  If (-Not (Test-Path $GlobalJsonFile)) {
78
    Write-Host "Unable to find '$GlobalJsonFile'"
79
    exit 0
80
  }
81
  $NativeTools = Get-Content($GlobalJsonFile) -Raw |
82
                    ConvertFrom-Json |
83
                    Select-Object -Expand 'native-tools' -ErrorAction SilentlyContinue
84
  if ($NativeTools) {
85
    if ($PathPromotion -eq $True) {
86
      $ArcadeToolsDirectory = "$env:SYSTEMDRIVE\arcade-tools"
87
      if (Test-Path $ArcadeToolsDirectory) { # if this directory exists, we should use native tools on machine
88
        $NativeTools.PSObject.Properties | ForEach-Object {
89
          $ToolName = $_.Name
90
          $ToolVersion = $_.Value
91
          $InstalledTools = @{}
92

93
          if ((Get-Command "$ToolName" -ErrorAction SilentlyContinue) -eq $null) {
94
            if ($ToolVersion -eq "latest") {
95
              $ToolVersion = ""
96
            }
97
            $ToolDirectories = (Get-ChildItem -Path "$ArcadeToolsDirectory" -Filter "$ToolName-$ToolVersion*" | Sort-Object -Descending)
98
            if ($ToolDirectories -eq $null) {
99
              Write-Error "Unable to find directory for $ToolName $ToolVersion; please make sure the tool is installed on this image."
100
              exit 1
101
            }
102
            $ToolDirectory = $ToolDirectories[0]
103
            $BinPathFile = "$($ToolDirectory.FullName)\binpath.txt"
104
            if (-not (Test-Path -Path "$BinPathFile")) {
105
              Write-Error "Unable to find binpath.txt in '$($ToolDirectory.FullName)' ($ToolName $ToolVersion); artifact is either installed incorrectly or is not a bootstrappable tool."
106
              exit 1
107
            }
108
            $BinPath = Get-Content "$BinPathFile"
109
            $ToolPath = Convert-Path -Path $BinPath
110
            Write-Host "Adding $ToolName to the path ($ToolPath)..."
111
            Write-Host "##vso[task.prependpath]$ToolPath"
112
            $env:PATH = "$ToolPath;$env:PATH"
113
            $InstalledTools += @{ $ToolName = $ToolDirectory.FullName }
114
          }
115
        }
116
        return $InstalledTools
117
      } else {
118
        $NativeTools.PSObject.Properties | ForEach-Object {
119
          $ToolName = $_.Name
120
          $ToolVersion = $_.Value
121

122
          if ((Get-Command "$ToolName" -ErrorAction SilentlyContinue) -eq $null) {
123
            Write-PipelineTelemetryError -Category 'NativeToolsBootstrap' -Message "$ToolName not found on path. Please install $ToolName $ToolVersion before proceeding."
124
            Write-PipelineTelemetryError -Category 'NativeToolsBootstrap' -Message "If this is running on a build machine, the arcade-tools directory was not found, which means there's an error with the image."
125
          }
126
        }
127
        exit 0
128
      }
129
    } else {
130
      $NativeTools.PSObject.Properties | ForEach-Object {
131
        $ToolName = $_.Name
132
        $ToolVersion = $_.Value
133
        $LocalInstallerArguments =  @{ ToolName = "$ToolName" }
134
        $LocalInstallerArguments += @{ InstallPath = "$InstallBin" }
135
        $LocalInstallerArguments += @{ BaseUri = "$BaseUri" }
136
        $LocalInstallerArguments += @{ CommonLibraryDirectory = "$EngCommonBaseDir" }
137
        $LocalInstallerArguments += @{ Version = "$ToolVersion" }
138
  
139
        if ($Verbose) {
140
          $LocalInstallerArguments += @{ Verbose = $True }
141
        }
142
        if (Get-Variable 'Force' -ErrorAction 'SilentlyContinue') {
143
          if($Force) {
144
            $LocalInstallerArguments += @{ Force = $True }
145
          }
146
        }
147
        if ($Clean) {
148
          $LocalInstallerArguments += @{ Clean = $True }
149
        }
150
  
151
        Write-Verbose "Installing $ToolName version $ToolVersion"
152
        Write-Verbose "Executing '$InstallerPath $($LocalInstallerArguments.Keys.ForEach({"-$_ '$($LocalInstallerArguments.$_)'"}) -join ' ')'"
153
        & $InstallerPath @LocalInstallerArguments
154
        if ($LASTEXITCODE -Ne "0") {
155
          $errMsg = "$ToolName installation failed"
156
          if ((Get-Variable 'DoNotAbortNativeToolsInstallationOnFailure' -ErrorAction 'SilentlyContinue') -and $DoNotAbortNativeToolsInstallationOnFailure) {
157
              $showNativeToolsWarning = $true
158
              if ((Get-Variable 'DoNotDisplayNativeToolsInstallationWarnings' -ErrorAction 'SilentlyContinue') -and $DoNotDisplayNativeToolsInstallationWarnings) {
159
                  $showNativeToolsWarning = $false
160
              }
161
              if ($showNativeToolsWarning) {
162
                  Write-Warning $errMsg
163
              }
164
              $toolInstallationFailure = $true
165
          } else {
166
              # We cannot change this to Write-PipelineTelemetryError because of https://github.com/dotnet/arcade/issues/4482
167
              Write-Host $errMsg
168
              exit 1
169
          }
170
        }
171
      }
172
  
173
      if ((Get-Variable 'toolInstallationFailure' -ErrorAction 'SilentlyContinue') -and $toolInstallationFailure) {
174
          # We cannot change this to Write-PipelineTelemetryError because of https://github.com/dotnet/arcade/issues/4482
175
          Write-Host 'Native tools bootstrap failed'
176
          exit 1
177
      }
178
    }
179
  }
180
  else {
181
    Write-Host 'No native tools defined in global.json'
182
    exit 0
183
  }
184

185
  if ($Clean) {
186
    exit 0
187
  }
188
  if (Test-Path $InstallBin) {
189
    Write-Host 'Native tools are available from ' (Convert-Path -Path $InstallBin)
190
    Write-Host "##vso[task.prependpath]$(Convert-Path -Path $InstallBin)"
191
    return $InstallBin
192
  }
193
  elseif (-not ($PathPromotion)) {
194
    Write-PipelineTelemetryError -Category 'NativeToolsBootstrap' -Message 'Native tools install directory does not exist, installation failed'
195
    exit 1
196
  }
197
  exit 0
198
}
199
catch {
200
  Write-Host $_.ScriptStackTrace
201
  Write-PipelineTelemetryError -Category 'NativeToolsBootstrap' -Message $_
202
  ExitWithExitCode 1
203
}
204

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

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

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

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