2018-02-24 08:34:31 +08:00
|
|
|
[CmdletBinding()]
|
|
|
|
param(
|
|
|
|
[Parameter(Mandatory=$true)][string]$tool
|
|
|
|
)
|
|
|
|
|
2018-03-01 10:51:25 +08:00
|
|
|
Set-StrictMode -Version Latest
|
2018-02-24 08:34:31 +08:00
|
|
|
$scriptsDir = split-path -parent $script:MyInvocation.MyCommand.Definition
|
|
|
|
. "$scriptsDir\VcpkgPowershellUtils.ps1"
|
|
|
|
|
|
|
|
Write-Verbose "Fetching tool: $tool"
|
|
|
|
$vcpkgRootDir = vcpkgFindFileRecursivelyUp $scriptsDir .vcpkg-root
|
|
|
|
|
|
|
|
$downloadsDir = "$vcpkgRootDir\downloads"
|
|
|
|
vcpkgCreateDirectoryIfNotExists $downloadsDir
|
|
|
|
|
|
|
|
function fetchToolInternal([Parameter(Mandatory=$true)][string]$tool)
|
|
|
|
{
|
|
|
|
$tool = $tool.toLower()
|
|
|
|
|
|
|
|
[xml]$asXml = Get-Content "$scriptsDir\vcpkgTools.xml"
|
|
|
|
$toolData = $asXml.SelectSingleNode("//tools/tool[@name=`"$tool`"]") # Case-sensitive!
|
|
|
|
|
|
|
|
if ($toolData -eq $null)
|
|
|
|
{
|
|
|
|
throw "Unkown tool $tool"
|
|
|
|
}
|
|
|
|
|
|
|
|
$exePath = "$downloadsDir\$($toolData.exeRelativePath)"
|
|
|
|
|
|
|
|
if (Test-Path $exePath)
|
|
|
|
{
|
|
|
|
return $exePath
|
|
|
|
}
|
|
|
|
|
2018-03-01 10:51:25 +08:00
|
|
|
$isArchive = vcpkgHasProperty -object $toolData -propertyName "archiveRelativePath"
|
|
|
|
if ($isArchive)
|
2018-02-24 08:34:31 +08:00
|
|
|
{
|
2018-03-22 18:08:25 +08:00
|
|
|
$downloadPath = "$downloadsDir\$(@($toolData.archiveRelativePath)[0])"
|
2018-02-24 08:34:31 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-03-22 18:08:25 +08:00
|
|
|
$downloadPath = "$downloadsDir\$(@($toolData.exeRelativePath)[0])"
|
2018-02-24 08:34:31 +08:00
|
|
|
}
|
|
|
|
|
2018-03-22 18:08:25 +08:00
|
|
|
[String]$url = @($toolData.url)[0]
|
2018-02-24 08:34:31 +08:00
|
|
|
if (!(Test-Path $downloadPath))
|
|
|
|
{
|
|
|
|
Write-Host "Downloading $tool..."
|
|
|
|
vcpkgDownloadFile $url $downloadPath
|
|
|
|
Write-Host "Downloading $tool has completed successfully."
|
|
|
|
}
|
|
|
|
|
2018-03-22 18:08:25 +08:00
|
|
|
$expectedDownloadedFileHash = @($toolData.sha256)[0]
|
2018-02-24 08:34:31 +08:00
|
|
|
$downloadedFileHash = vcpkgGetSHA256 $downloadPath
|
|
|
|
vcpkgCheckEqualFileHash -filePath $downloadPath -expectedHash $expectedDownloadedFileHash -actualHash $downloadedFileHash
|
|
|
|
|
2018-03-01 10:51:25 +08:00
|
|
|
if ($isArchive)
|
2018-02-24 08:34:31 +08:00
|
|
|
{
|
|
|
|
$outFilename = (Get-ChildItem $downloadPath).BaseName
|
|
|
|
Write-Host "Extracting $tool..."
|
|
|
|
vcpkgExtractFile -File $downloadPath -DestinationDir $downloadsDir -outFilename $outFilename
|
|
|
|
Write-Host "Extracting $tool has completed successfully."
|
|
|
|
}
|
|
|
|
|
|
|
|
if (-not (Test-Path $exePath))
|
|
|
|
{
|
|
|
|
throw ("Could not detect or download " + $tool)
|
|
|
|
}
|
|
|
|
|
|
|
|
return $exePath
|
|
|
|
}
|
|
|
|
|
|
|
|
$path = fetchToolInternal $tool
|
|
|
|
Write-Verbose "Fetching tool: $tool. Done."
|
|
|
|
return "<sol>::$path::<eol>"
|