Skip to content

Commit 8033c90

Browse files
committed
Add script for getting vcpkg tools behind a proxy
Currently the vcpkg executable downloads files directly from the network. Unfortunately it does not respect proxy environment variables. This downloads the files using those environment variables and stages them into the root.
1 parent bd1be9d commit 8033c90

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

Download-VcpkgTools.ps1

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

0 commit comments

Comments
 (0)