2018-10-22 05:07:26 +00:00
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Install native tool
|
|
|
|
|
|
|
|
.DESCRIPTION
|
|
|
|
Install cmake native tool from Azure blob storage
|
|
|
|
|
|
|
|
.PARAMETER InstallPath
|
|
|
|
Base directory to install native tool to
|
|
|
|
|
|
|
|
.PARAMETER BaseUri
|
|
|
|
Base file directory or Url from which to acquire tool archives
|
|
|
|
|
|
|
|
.PARAMETER CommonLibraryDirectory
|
|
|
|
Path to folder containing common library modules
|
|
|
|
|
|
|
|
.PARAMETER Force
|
|
|
|
Force install of tools even if they previously exist
|
|
|
|
|
|
|
|
.PARAMETER Clean
|
|
|
|
Don't install the tool, just clean up the current install of the tool
|
|
|
|
|
|
|
|
.PARAMETER DownloadRetries
|
|
|
|
Total number of retry attempts
|
|
|
|
|
|
|
|
.PARAMETER RetryWaitTimeInSeconds
|
|
|
|
Wait time between retry attempts in seconds
|
|
|
|
|
|
|
|
.NOTES
|
|
|
|
Returns 0 if install succeeds, 1 otherwise
|
|
|
|
#>
|
|
|
|
[CmdletBinding(PositionalBinding=$false)]
|
|
|
|
Param (
|
|
|
|
[Parameter(Mandatory=$True)]
|
|
|
|
[string] $ToolName,
|
|
|
|
[Parameter(Mandatory=$True)]
|
|
|
|
[string] $InstallPath,
|
|
|
|
[Parameter(Mandatory=$True)]
|
|
|
|
[string] $BaseUri,
|
|
|
|
[Parameter(Mandatory=$True)]
|
|
|
|
[string] $Version,
|
|
|
|
[string] $CommonLibraryDirectory = $PSScriptRoot,
|
|
|
|
[switch] $Force = $False,
|
|
|
|
[switch] $Clean = $False,
|
|
|
|
[int] $DownloadRetries = 5,
|
|
|
|
[int] $RetryWaitTimeInSeconds = 30
|
|
|
|
)
|
|
|
|
|
2019-11-22 13:41:58 +00:00
|
|
|
. $PSScriptRoot\..\pipeline-logging-functions.ps1
|
|
|
|
|
2018-10-22 05:07:26 +00:00
|
|
|
# Import common library modules
|
|
|
|
Import-Module -Name (Join-Path $CommonLibraryDirectory "CommonLibrary.psm1")
|
|
|
|
|
|
|
|
try {
|
|
|
|
# Define verbose switch if undefined
|
|
|
|
$Verbose = $VerbosePreference -Eq "Continue"
|
|
|
|
|
|
|
|
$Arch = CommonLibrary\Get-MachineArchitecture
|
|
|
|
$ToolOs = "win64"
|
|
|
|
if($Arch -Eq "x32") {
|
|
|
|
$ToolOs = "win32"
|
|
|
|
}
|
|
|
|
$ToolNameMoniker = "$ToolName-$Version-$ToolOs-$Arch"
|
|
|
|
$ToolInstallDirectory = Join-Path $InstallPath "$ToolName\$Version\"
|
|
|
|
$Uri = "$BaseUri/windows/$ToolName/$ToolNameMoniker.zip"
|
|
|
|
$ShimPath = Join-Path $InstallPath "$ToolName.exe"
|
|
|
|
|
|
|
|
if ($Clean) {
|
|
|
|
Write-Host "Cleaning $ToolInstallDirectory"
|
|
|
|
if (Test-Path $ToolInstallDirectory) {
|
|
|
|
Remove-Item $ToolInstallDirectory -Force -Recurse
|
|
|
|
}
|
|
|
|
Write-Host "Cleaning $ShimPath"
|
|
|
|
if (Test-Path $ShimPath) {
|
|
|
|
Remove-Item $ShimPath -Force
|
|
|
|
}
|
|
|
|
$ToolTempPath = CommonLibrary\Get-TempPathFilename -Path $Uri
|
|
|
|
Write-Host "Cleaning $ToolTempPath"
|
|
|
|
if (Test-Path $ToolTempPath) {
|
|
|
|
Remove-Item $ToolTempPath -Force
|
|
|
|
}
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
# Install tool
|
|
|
|
if ((Test-Path $ToolInstallDirectory) -And (-Not $Force)) {
|
|
|
|
Write-Verbose "$ToolName ($Version) already exists, skipping install"
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$InstallStatus = CommonLibrary\DownloadAndExtract -Uri $Uri `
|
|
|
|
-InstallDirectory $ToolInstallDirectory `
|
|
|
|
-Force:$Force `
|
|
|
|
-DownloadRetries $DownloadRetries `
|
|
|
|
-RetryWaitTimeInSeconds $RetryWaitTimeInSeconds `
|
|
|
|
-Verbose:$Verbose
|
|
|
|
|
|
|
|
if ($InstallStatus -Eq $False) {
|
2019-11-22 13:41:58 +00:00
|
|
|
Write-PipelineTelemetryError "Installation failed" -Category "NativeToolsetBootstrapping"
|
2018-10-22 05:07:26 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$ToolFilePath = Get-ChildItem $ToolInstallDirectory -Recurse -Filter "$ToolName.exe" | % { $_.FullName }
|
|
|
|
if (@($ToolFilePath).Length -Gt 1) {
|
|
|
|
Write-Error "There are multiple copies of $ToolName in $($ToolInstallDirectory): `n$(@($ToolFilePath | out-string))"
|
|
|
|
exit 1
|
|
|
|
} elseif (@($ToolFilePath).Length -Lt 1) {
|
2021-03-09 13:58:13 +00:00
|
|
|
Write-Host "$ToolName was not found in $ToolInstallDirectory."
|
2018-10-22 05:07:26 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Generate shim
|
|
|
|
# Always rewrite shims so that we are referencing the expected version
|
|
|
|
$GenerateShimStatus = CommonLibrary\New-ScriptShim -ShimName $ToolName `
|
|
|
|
-ShimDirectory $InstallPath `
|
|
|
|
-ToolFilePath "$ToolFilePath" `
|
|
|
|
-BaseUri $BaseUri `
|
|
|
|
-Force:$Force `
|
|
|
|
-Verbose:$Verbose
|
|
|
|
|
|
|
|
if ($GenerateShimStatus -Eq $False) {
|
2019-11-22 13:41:58 +00:00
|
|
|
Write-PipelineTelemetryError "Generate shim failed" -Category "NativeToolsetBootstrapping"
|
2018-10-22 05:07:26 +00:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
catch {
|
2019-11-22 13:41:58 +00:00
|
|
|
Write-Host $_.ScriptStackTrace
|
|
|
|
Write-PipelineTelemetryError -Category "NativeToolsetBootstrapping" -Message $_
|
2018-10-22 05:07:26 +00:00
|
|
|
exit 1
|
|
|
|
}
|