-
Notifications
You must be signed in to change notification settings - Fork 17
/
Download-VcpkgTools.ps1
63 lines (53 loc) · 1.9 KB
/
Download-VcpkgTools.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<#
.Synopsis
Downloads tools required by vcpkg.
.Details
At this time the `vcpkg` executable uses the system proxy settings, not the
values contained in the proxy environment variables. This script is a
workaround until that is resolved
.Parameter ToolsPath
The XML file containing the tool listing.
#>
param(
[Parameter(Mandatory)]
[string]$toolsPath
)
$ErrorActionPreference = 'Stop';
$downloads = @(
'powershell-core',
'7zip'
);
[xml]$document = Get-Content $toolsPath;
$tools = $document.SelectNodes('//tool');
Write-Host $document;
$downloadPath = Join-Path $PSScriptRoot 'downloads';
$toolsPath = Join-Path $downloadPath 'tools';
if (!(Test-Path $downloadPath)) {
New-Item -ItemType 'directory' -Path $downloadPath;
}
foreach ($tool in $tools) {
if ($tool.os -eq 'windows') {
foreach ($download in $downloads) {
if ($tool.Name -eq $download) {
$toolName = $tool.Name;
# Download the tool
$downloadTo = (Join-Path $downloadPath $tool.archiveName);
if (!(Test-Path $downloadTo)) {
Write-Host ('Downloading {0} from {1}' -f $toolName,$tool.url);
Invoke-WebFileRequest -url $tool.url -DestinationPath $downloadTo;
Write-Host ('Downloaded {0} to {1}' -f $toolName,$downloadTo);
# Extract the tool
$extractTo = (Join-Path $toolsPath ('{0}-{1}-windows' -f $toolName,$tool.version));
if ($toolName -eq '7zip') {
$extractTo = Join-Path $extractTo ($tool.exeRelativePath -split '\\')[0];
}
Write-Host ('Extracting {0} from {1}' -f $toolName,$downloadTo);
Expand-7Zip -ArchiveFileName $downloadTo -TargetPath $extractTo;
Write-Host ('Extracted {0} to {1}' -f $toolName,$extractTo);
} else {
Write-Host ('Skipping download of {0}' -f $toolName)
}
}
}
}
}