[interp] Share more wrappers for different interp in signatures (#14596)
[mono-project.git] / eng / common / init-tools-native.ps1
bloba4306bd37e14b08403b1e5bf0cf3cb9777215f8b
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 $LocalInstallerCommand = $InstallerPath
83 $LocalInstallerCommand += " -ToolName $ToolName"
84 $LocalInstallerCommand += " -InstallPath $InstallBin"
85 $LocalInstallerCommand += " -BaseUri $BaseUri"
86 $LocalInstallerCommand += " -CommonLibraryDirectory $EngCommonBaseDir"
87 $LocalInstallerCommand += " -Version $ToolVersion"
89 if ($Verbose) {
90 $LocalInstallerCommand += " -Verbose"
92 if (Get-Variable 'Force' -ErrorAction 'SilentlyContinue') {
93 if($Force) {
94 $LocalInstallerCommand += " -Force"
97 if ($Clean) {
98 $LocalInstallerCommand += " -Clean"
101 Write-Verbose "Installing $ToolName version $ToolVersion"
102 Write-Verbose "Executing '$LocalInstallerCommand'"
103 Invoke-Expression "$LocalInstallerCommand"
104 if ($LASTEXITCODE -Ne "0") {
105 $errMsg = "$ToolName installation failed"
106 if ((Get-Variable 'DoNotAbortNativeToolsInstallationOnFailure' -ErrorAction 'SilentlyContinue') -and $DoNotAbortNativeToolsInstallationOnFailure) {
107 Write-Warning $errMsg
108 $toolInstallationFailure = $true
109 } else {
110 Write-Error $errMsg
111 exit 1
116 if ((Get-Variable 'toolInstallationFailure' -ErrorAction 'SilentlyContinue') -and $toolInstallationFailure) {
117 exit 1
120 else {
121 Write-Host "No native tools defined in global.json"
122 exit 0
125 if ($Clean) {
126 exit 0
128 if (Test-Path $InstallBin) {
129 Write-Host "Native tools are available from" (Convert-Path -Path $InstallBin)
130 Write-Host "##vso[task.prependpath]$(Convert-Path -Path $InstallBin)"
132 else {
133 Write-Error "Native tools install directory does not exist, installation failed"
134 exit 1
136 exit 0
138 catch {
139 Write-Host $_
140 Write-Host $_.Exception
141 exit 1