Update dependencies from https://github.com/dotnet/arcade build 20191006.1 (#17214)
[mono-project.git] / eng / common / init-tools-native.ps1
blob0fc0503ab91e3549e964734082b91e334d408e32
1 <#
2 .SYNOPSIS
3 Entry point script for installing native tools
5 .DESCRIPTION
6 Reads $RepoRoot\global.json file to determine native assets to install
7 and executes installers for those tools
9 .PARAMETER BaseUri
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
19 .PARAMETER Clean
20 Switch specifying to not install anything, but cleanup native asset folders
22 .PARAMETER Force
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 .NOTES
36 [CmdletBinding(PositionalBinding=$false)]
37 Param (
38 [string] $BaseUri = "https://netcorenativeassets.blob.core.windows.net/resource-packages/external",
39 [string] $InstallDirectory,
40 [switch] $Clean = $False,
41 [switch] $Force = $False,
42 [int] $DownloadRetries = 5,
43 [int] $RetryWaitTimeInSeconds = 30,
44 [string] $GlobalJsonFile
47 if (!$GlobalJsonFile) {
48 $GlobalJsonFile = Join-Path (Get-Item $PSScriptRoot).Parent.Parent.FullName "global.json"
51 Set-StrictMode -version 2.0
52 $ErrorActionPreference="Stop"
54 Import-Module -Name (Join-Path $PSScriptRoot "native\CommonLibrary.psm1")
56 try {
57 # Define verbose switch if undefined
58 $Verbose = $VerbosePreference -Eq "Continue"
60 $EngCommonBaseDir = Join-Path $PSScriptRoot "native\"
61 $NativeBaseDir = $InstallDirectory
62 if (!$NativeBaseDir) {
63 $NativeBaseDir = CommonLibrary\Get-NativeInstallDirectory
65 $Env:CommonLibrary_NativeInstallDir = $NativeBaseDir
66 $InstallBin = Join-Path $NativeBaseDir "bin"
67 $InstallerPath = Join-Path $EngCommonBaseDir "install-tool.ps1"
69 # Process tools list
70 Write-Host "Processing $GlobalJsonFile"
71 If (-Not (Test-Path $GlobalJsonFile)) {
72 Write-Host "Unable to find '$GlobalJsonFile'"
73 exit 0
75 $NativeTools = Get-Content($GlobalJsonFile) -Raw |
76 ConvertFrom-Json |
77 Select-Object -Expand "native-tools" -ErrorAction SilentlyContinue
78 if ($NativeTools) {
79 $NativeTools.PSObject.Properties | ForEach-Object {
80 $ToolName = $_.Name
81 $ToolVersion = $_.Value
82 $LocalInstallerArguments = @{ ToolName = "$ToolName" }
83 $LocalInstallerArguments += @{ InstallPath = "$InstallBin" }
84 $LocalInstallerArguments += @{ BaseUri = "$BaseUri" }
85 $LocalInstallerArguments += @{ CommonLibraryDirectory = "$EngCommonBaseDir" }
86 $LocalInstallerArguments += @{ Version = "$ToolVersion" }
88 if ($Verbose) {
89 $LocalInstallerArguments += @{ Verbose = $True }
91 if (Get-Variable 'Force' -ErrorAction 'SilentlyContinue') {
92 if($Force) {
93 $LocalInstallerArguments += @{ Force = $True }
96 if ($Clean) {
97 $LocalInstallerArguments += @{ Clean = $True }
100 Write-Verbose "Installing $ToolName version $ToolVersion"
101 Write-Verbose "Executing '$InstallerPath $($LocalInstallerArguments.Keys.ForEach({"-$_ '$($LocalInstallerArguments.$_)'"}) -join ' ')'"
102 & $InstallerPath @LocalInstallerArguments
103 if ($LASTEXITCODE -Ne "0") {
104 $errMsg = "$ToolName installation failed"
105 if ((Get-Variable 'DoNotAbortNativeToolsInstallationOnFailure' -ErrorAction 'SilentlyContinue') -and $DoNotAbortNativeToolsInstallationOnFailure) {
106 $showNativeToolsWarning = $true
107 if ((Get-Variable 'DoNotDisplayNativeToolsInstallationWarnings' -ErrorAction 'SilentlyContinue') -and $DoNotDisplayNativeToolsInstallationWarnings) {
108 $showNativeToolsWarning = $false
110 if ($showNativeToolsWarning) {
111 Write-Warning $errMsg
113 $toolInstallationFailure = $true
114 } else {
115 Write-Error $errMsg
116 exit 1
121 if ((Get-Variable 'toolInstallationFailure' -ErrorAction 'SilentlyContinue') -and $toolInstallationFailure) {
122 exit 1
125 else {
126 Write-Host "No native tools defined in global.json"
127 exit 0
130 if ($Clean) {
131 exit 0
133 if (Test-Path $InstallBin) {
134 Write-Host "Native tools are available from" (Convert-Path -Path $InstallBin)
135 Write-Host "##vso[task.prependpath]$(Convert-Path -Path $InstallBin)"
136 return $InstallBin
138 else {
139 Write-Error "Native tools install directory does not exist, installation failed"
140 exit 1
142 exit 0
144 catch {
145 Write-Host $_
146 Write-Host $_.Exception
147 exit 1