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
|
|
|
|
|
2018-03-28 09:06:02 +08:00
|
|
|
function fetchToolInternal([Parameter(Mandatory=$true)][string]$tool)
|
|
|
|
{
|
|
|
|
$tool = $tool.toLower()
|
2018-02-24 08:34:31 +08:00
|
|
|
|
2018-03-28 09:06:02 +08:00
|
|
|
[xml]$asXml = Get-Content "$scriptsDir\vcpkgTools.xml"
|
|
|
|
$toolData = $asXml.SelectSingleNode("//tools/tool[@name=`"$tool`"]") # Case-sensitive!
|
2018-02-24 08:34:31 +08:00
|
|
|
|
2018-03-28 09:06:02 +08:00
|
|
|
if ($toolData -eq $null)
|
|
|
|
{
|
|
|
|
throw "Unkown tool $tool"
|
|
|
|
}
|
2018-02-24 08:34:31 +08:00
|
|
|
|
2018-04-05 11:33:45 +08:00
|
|
|
$toolPath="$downloadsDir\tools\$tool-$($toolData.version)-windows"
|
2018-04-04 12:05:31 +08:00
|
|
|
$exePath = "$toolPath\$($toolData.exeRelativePath)"
|
2018-02-24 08:34:31 +08:00
|
|
|
|
2018-03-28 09:06:02 +08:00
|
|
|
if (Test-Path $exePath)
|
|
|
|
{
|
|
|
|
return $exePath
|
|
|
|
}
|
2018-02-24 08:34:31 +08:00
|
|
|
|
2018-04-05 10:37:31 +08:00
|
|
|
$isArchive = vcpkgHasProperty -object $toolData -propertyName "archiveName"
|
2018-03-28 09:06:02 +08:00
|
|
|
if ($isArchive)
|
|
|
|
{
|
2018-04-05 10:37:31 +08:00
|
|
|
$downloadPath = "$downloadsDir\$($toolData.archiveName)"
|
2018-03-28 09:06:02 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-04-04 12:05:31 +08:00
|
|
|
$downloadPath = "$toolPath\$($toolData.exeRelativePath)"
|
2018-03-28 09:06:02 +08:00
|
|
|
}
|
2018-02-24 08:34:31 +08:00
|
|
|
|
2018-03-28 09:06:02 +08:00
|
|
|
[String]$url = $toolData.url
|
|
|
|
if (!(Test-Path $downloadPath))
|
|
|
|
{
|
|
|
|
Write-Host "Downloading $tool..."
|
2018-04-04 13:15:17 +08:00
|
|
|
|
2018-04-05 10:26:14 +08:00
|
|
|
# aria2 needs 7zip & 7zip920 to extract. So, we need to download those trough powershell
|
|
|
|
if ($tool -eq "aria2" -or $tool -eq "7zip" -or $tool -eq "7zip920")
|
2018-04-04 13:15:17 +08:00
|
|
|
{
|
|
|
|
vcpkgDownloadFile $url $downloadPath
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$aria2exe = fetchToolInternal "aria2"
|
|
|
|
vcpkgDownloadFileWithAria2 $aria2exe $url $downloadPath
|
|
|
|
}
|
|
|
|
|
2018-03-28 09:06:02 +08:00
|
|
|
Write-Host "Downloading $tool... done."
|
|
|
|
}
|
2018-02-24 08:34:31 +08:00
|
|
|
|
2018-04-05 11:07:45 +08:00
|
|
|
$expectedDownloadedFileHash = $toolData.sha512
|
|
|
|
$downloadedFileHash = vcpkgGetSHA512 $downloadPath
|
2018-03-28 09:06:02 +08:00
|
|
|
vcpkgCheckEqualFileHash -filePath $downloadPath -expectedHash $expectedDownloadedFileHash -actualHash $downloadedFileHash
|
2018-02-24 08:34:31 +08:00
|
|
|
|
2018-03-28 09:06:02 +08:00
|
|
|
if ($isArchive)
|
|
|
|
{
|
|
|
|
Write-Host "Extracting $tool..."
|
2018-04-05 10:26:14 +08:00
|
|
|
if ($tool -eq "7zip920")
|
2018-04-04 12:05:31 +08:00
|
|
|
{
|
2018-04-05 10:26:14 +08:00
|
|
|
vcpkgExtractZipFileWithShell -ArchivePath $downloadPath -DestinationDir $toolPath
|
|
|
|
}
|
|
|
|
elseif ($tool -eq "7zip")
|
|
|
|
{
|
|
|
|
$sevenZip920 = fetchToolInternal "7zip920"
|
|
|
|
$ec = vcpkgInvokeCommand "$sevenZip920" "x `"$downloadPath`" -o`"$toolPath`" -y"
|
2018-04-04 12:05:31 +08:00
|
|
|
if ($ec -ne 0)
|
|
|
|
{
|
|
|
|
Write-Host "Could not extract $downloadPath"
|
|
|
|
throw
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$sevenZipExe = fetchToolInternal "7zip"
|
|
|
|
vcpkgExtractFile -sevenZipExe "$sevenZipExe" -ArchivePath $downloadPath -DestinationDir $toolPath
|
|
|
|
}
|
2018-03-28 09:06:02 +08:00
|
|
|
Write-Host "Extracting $tool... done."
|
|
|
|
}
|
2018-02-24 08:34:31 +08:00
|
|
|
|
2018-03-28 09:06:02 +08:00
|
|
|
if (-not (Test-Path $exePath))
|
|
|
|
{
|
|
|
|
Write-Error "Could not detect or download $tool"
|
|
|
|
throw
|
|
|
|
}
|
|
|
|
|
|
|
|
return $exePath
|
2018-02-24 08:34:31 +08:00
|
|
|
}
|
|
|
|
|
2018-03-28 09:06:02 +08:00
|
|
|
$path = fetchToolInternal $tool
|
|
|
|
Write-Verbose "Fetching tool: $tool. Done."
|
|
|
|
return "<sol>::$path::<eol>"
|