vcpkg/scripts/fetchTool.ps1

108 lines
3.0 KiB
PowerShell
Raw Normal View History

[CmdletBinding()]
param(
[Parameter(Mandatory=$true)][string]$tool
)
Set-StrictMode -Version Latest
$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-03-28 09:06:02 +08:00
[xml]$asXml = Get-Content "$scriptsDir\vcpkgTools.xml"
$toolData = $asXml.SelectSingleNode("//tools/tool[@name=`"$tool`"]") # Case-sensitive!
2018-03-28 09:06:02 +08:00
if ($toolData -eq $null)
{
2018-04-10 13:14:47 +08:00
throw "Unknown tool $tool"
2018-03-28 09:06:02 +08:00
}
$toolPath="$downloadsDir\tools\$tool-$($toolData.version)-windows"
$exePath = "$toolPath\$($toolData.exeRelativePath)"
2018-03-28 09:06:02 +08:00
if (Test-Path $exePath)
{
return $exePath
}
$isArchive = vcpkgHasProperty -object $toolData -propertyName "archiveName"
2018-03-28 09:06:02 +08:00
if ($isArchive)
{
$downloadPath = "$downloadsDir\$($toolData.archiveName)"
2018-03-28 09:06:02 +08:00
}
else
{
$downloadPath = "$toolPath\$($toolData.exeRelativePath)"
2018-03-28 09:06:02 +08:00
}
2018-03-28 09:06:02 +08:00
[String]$url = $toolData.url
if (!(Test-Path $downloadPath))
{
Write-Host "Downloading $tool..."
2018-04-05 13:13:12 +08:00
# Download aria2 with .NET. aria2 will be used to download everything else.
if ($tool -eq "aria2")
{
vcpkgDownloadFile $url $downloadPath $toolData.sha512
}
else
{
$aria2exe = fetchToolInternal "aria2"
vcpkgDownloadFileWithAria2 $aria2exe $url $downloadPath $toolData.sha512
}
2018-03-28 09:06:02 +08:00
Write-Host "Downloading $tool... done."
}
else
{
vcpkgCheckEqualFileHash -url $url -filePath $downloadPath -expectedHash $toolData.sha512
}
2018-03-28 09:06:02 +08:00
if ($isArchive)
{
Write-Host "Extracting $tool..."
2018-04-05 13:13:12 +08:00
# Extract 7zip920 with shell because we need it to extract 7zip
# Extract aria2 with shell because we need it to download 7zip
if ($tool -eq "7zip920" -or $tool -eq "aria2")
{
vcpkgExtractZipFile -ArchivePath $downloadPath -DestinationDir $toolPath
2018-04-05 10:26:14 +08:00
}
elseif ($tool -eq "7zip")
{
$sevenZip920 = fetchToolInternal "7zip920"
$ec = vcpkgInvokeCommand "$sevenZip920" "x `"$downloadPath`" -o`"$toolPath`" -y"
if ($ec -ne 0)
{
Write-Host "Could not extract $downloadPath"
throw
}
}
else
{
$sevenZipExe = fetchToolInternal "7zip"
vcpkgExtractFileWith7z -sevenZipExe "$sevenZipExe" -ArchivePath $downloadPath -DestinationDir $toolPath
}
2018-03-28 09:06:02 +08:00
Write-Host "Extracting $tool... done."
}
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-03-28 09:06:02 +08:00
$path = fetchToolInternal $tool
Write-Verbose "Fetching tool: $tool. Done."
return "<sol>::$path::<eol>"