From 45d31162c25e168c46d9dd0f3f00e49edf625f21 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 27 Mar 2018 17:48:33 -0700 Subject: [PATCH] [ps1] Remove extraneous function --- scripts/fetchTool.ps1 | 103 ++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 55 deletions(-) diff --git a/scripts/fetchTool.ps1 b/scripts/fetchTool.ps1 index af6d4d1d9..8cf8002bc 100644 --- a/scripts/fetchTool.ps1 +++ b/scripts/fetchTool.ps1 @@ -13,64 +13,57 @@ $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) { - $tool = $tool.toLower() + throw "Unkown tool $tool" +} - [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)[0])" - - if (Test-Path $exePath) - { - return $exePath - } - - $isArchive = vcpkgHasProperty -object $toolData -propertyName "archiveRelativePath" - if ($isArchive) - { - $downloadPath = "$downloadsDir\$(@($toolData.archiveRelativePath)[0])" - } - else - { - $downloadPath = "$downloadsDir\$(@($toolData.exeRelativePath)[0])" - } - - [String]$url = @($toolData.url)[0] - if (!(Test-Path $downloadPath)) - { - Write-Host "Downloading $tool..." - vcpkgDownloadFile $url $downloadPath - Write-Host "Downloading $tool... done." - } - - $expectedDownloadedFileHash = @($toolData.sha256)[0] - $downloadedFileHash = vcpkgGetSHA256 $downloadPath - vcpkgCheckEqualFileHash -filePath $downloadPath -expectedHash $expectedDownloadedFileHash -actualHash $downloadedFileHash - - if ($isArchive) - { - $outFilename = (Get-ChildItem $downloadPath).BaseName - Write-Host "Extracting $tool..." - vcpkgExtractFile -ArchivePath $downloadPath -DestinationDir $downloadsDir -outFilename $outFilename - Write-Host "Extracting $tool... done." - } - - if (-not (Test-Path $exePath)) - { - Write-Error "Could not detect or download $tool" - throw - } +$exePath = "$downloadsDir\$($toolData.exeRelativePath)" +if (Test-Path $exePath) +{ return $exePath } -$path = fetchToolInternal $tool -Write-Verbose "Fetching tool: $tool. Done." -return "::$path::" +$isArchive = vcpkgHasProperty -object $toolData -propertyName "archiveRelativePath" +if ($isArchive) +{ + $downloadPath = "$downloadsDir\$($toolData.archiveRelativePath)" +} +else +{ + $downloadPath = "$downloadsDir\$($toolData.exeRelativePath)" +} + +[String]$url = $toolData.url +if (!(Test-Path $downloadPath)) +{ + Write-Host "Downloading $tool..." + vcpkgDownloadFile $url $downloadPath + Write-Host "Downloading $tool... done." +} + +$expectedDownloadedFileHash = $toolData.sha256 +$downloadedFileHash = vcpkgGetSHA256 $downloadPath +vcpkgCheckEqualFileHash -filePath $downloadPath -expectedHash $expectedDownloadedFileHash -actualHash $downloadedFileHash + +if ($isArchive) +{ + $outFilename = (Get-ChildItem $downloadPath).BaseName + Write-Host "Extracting $tool..." + vcpkgExtractFile -ArchivePath $downloadPath -DestinationDir $downloadsDir -outFilename $outFilename + Write-Host "Extracting $tool... done." +} + +if (-not (Test-Path $exePath)) +{ + Write-Error "Could not detect or download $tool" + throw +} + +return "::$exePath::"