3
Entry point script for installing native tools
6
Reads $RepoRoot\global.json file to determine native assets to install
7
and executes installers for those tools
10
Base file directory or Url from which to acquire tool archives
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
20
Switch specifying to not install anything, but cleanup native asset folders
23
Clean and then install tools
25
.PARAMETER DownloadRetries
26
Total number of retry attempts
28
.PARAMETER RetryWaitTimeInSeconds
29
Wait time between retry attempts in seconds
31
.PARAMETER GlobalJsonFile
32
File path to global.json file
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)
40
[CmdletBinding(PositionalBinding=$false)]
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
52
if (!$GlobalJsonFile) {
53
$GlobalJsonFile = Join-Path (Get-Item $PSScriptRoot).Parent.Parent.FullName 'global.json'
56
Set-StrictMode -version 2.0
57
$ErrorActionPreference='Stop'
59
. $PSScriptRoot\pipeline-logging-functions.ps1
60
Import-Module -Name (Join-Path $PSScriptRoot 'native\CommonLibrary.psm1')
63
# Define verbose switch if undefined
64
$Verbose = $VerbosePreference -Eq 'Continue'
66
$EngCommonBaseDir = Join-Path $PSScriptRoot 'native\'
67
$NativeBaseDir = $InstallDirectory
68
if (!$NativeBaseDir) {
69
$NativeBaseDir = CommonLibrary\Get-NativeInstallDirectory
71
$Env:CommonLibrary_NativeInstallDir = $NativeBaseDir
72
$InstallBin = Join-Path $NativeBaseDir 'bin'
73
$InstallerPath = Join-Path $EngCommonBaseDir 'install-tool.ps1'
76
Write-Host "Processing $GlobalJsonFile"
77
If (-Not (Test-Path $GlobalJsonFile)) {
78
Write-Host "Unable to find '$GlobalJsonFile'"
81
$NativeTools = Get-Content($GlobalJsonFile) -Raw |
83
Select-Object -Expand 'native-tools' -ErrorAction SilentlyContinue
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 {
90
$ToolVersion = $_.Value
93
if ((Get-Command "$ToolName" -ErrorAction SilentlyContinue) -eq $null) {
94
if ($ToolVersion -eq "latest") {
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."
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."
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 }
116
return $InstalledTools
118
$NativeTools.PSObject.Properties | ForEach-Object {
120
$ToolVersion = $_.Value
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."
130
$NativeTools.PSObject.Properties | ForEach-Object {
132
$ToolVersion = $_.Value
133
$LocalInstallerArguments = @{ ToolName = "$ToolName" }
134
$LocalInstallerArguments += @{ InstallPath = "$InstallBin" }
135
$LocalInstallerArguments += @{ BaseUri = "$BaseUri" }
136
$LocalInstallerArguments += @{ CommonLibraryDirectory = "$EngCommonBaseDir" }
137
$LocalInstallerArguments += @{ Version = "$ToolVersion" }
140
$LocalInstallerArguments += @{ Verbose = $True }
142
if (Get-Variable 'Force' -ErrorAction 'SilentlyContinue') {
144
$LocalInstallerArguments += @{ Force = $True }
148
$LocalInstallerArguments += @{ Clean = $True }
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
161
if ($showNativeToolsWarning) {
162
Write-Warning $errMsg
164
$toolInstallationFailure = $true
166
# We cannot change this to Write-PipelineTelemetryError because of https://github.com/dotnet/arcade/issues/4482
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'
181
Write-Host 'No native tools defined in global.json'
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)"
193
elseif (-not ($PathPromotion)) {
194
Write-PipelineTelemetryError -Category 'NativeToolsBootstrap' -Message 'Native tools install directory does not exist, installation failed'
200
Write-Host $_.ScriptStackTrace
201
Write-PipelineTelemetryError -Category 'NativeToolsBootstrap' -Message $_