-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathvcpkg.ps1
More file actions
95 lines (83 loc) · 2.66 KB
/
vcpkg.ps1
File metadata and controls
95 lines (83 loc) · 2.66 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
[CmdletBinding()]
param (
[Parameter(ValueFromRemainingArguments = $true)]
[string[]]$AllArgs
)
$ErrorActionPreference = "Stop"
$ScriptDir = $PSScriptRoot
$ProjectRoot = $ScriptDir
$DefaultVcpkgRoot = Join-Path $ProjectRoot ".vcpkg"
$VcpkgDefaultBinaryCache = Join-Path $ProjectRoot ".vcpkg_bincache"
# Configuration
$VcpkgGitRef = "2025.12.12"
$Update = $false
function Show-Usage {
Write-Host "Usage: vcpkg.bat [options]"
Write-Host "Options:"
Write-Host " --update Force git pull on the vcpkg repository."
Write-Host " -h, --help Show this help."
}
# Manual Argument Parsing
foreach ($Arg in $AllArgs) {
switch ($Arg) {
"--update" { $Update = $true }
"-h" { Show-Usage; exit 0 }
"--help" { Show-Usage; exit 0 }
default {
Write-Warning "Unknown argument: $Arg"
}
}
}
# Environment Setup
if (-not (Test-Path $VcpkgDefaultBinaryCache)) {
New-Item -ItemType Directory -Path $VcpkgDefaultBinaryCache -Force | Out-Null
}
$VcpkgRoot = $env:VCPKG_ROOT
if ([string]::IsNullOrWhiteSpace($VcpkgRoot)) {
$VcpkgRoot = $DefaultVcpkgRoot
}
$VcpkgExe = Join-Path $VcpkgRoot "vcpkg.exe"
function Write-Log { param([string]$Msg) Write-Host "[vcpkg] $Msg" -ForegroundColor Cyan }
function Write-Warn { param([string]$Msg) Write-Host "[vcpkg] Warning: $Msg" -ForegroundColor Yellow }
# --- Ensure Repo ---
if (-not (Test-Path "$VcpkgRoot\.git")) {
Write-Log "Cloning vcpkg into $VcpkgRoot..."
git clone https://github.com/microsoft/vcpkg "$VcpkgRoot"
if ($LASTEXITCODE -ne 0) { throw "Git clone failed." }
}
if (-not $Update) {
# Ensure fixed commit
Push-Location $VcpkgRoot
try {
git fetch origin --tags --force
git -c advice.detachedHead=false checkout --force "$VcpkgGitRef"
git reset --hard "$VcpkgGitRef"
} finally {
Pop-Location
}
} else {
# Update to latest
Write-Log "Updating vcpkg in $VcpkgRoot..."
Push-Location $VcpkgRoot
try {
git checkout master 2>$null
if ($LASTEXITCODE -ne 0) { git checkout -b master origin/master }
git pull --ff-only
if ($LASTEXITCODE -ne 0) { Write-Warn "Failed to update vcpkg repo." }
} finally {
Pop-Location
}
}
# --- Ensure Bootstrap ---
if (-not (Test-Path $VcpkgExe)) {
Write-Log "Bootstrapping vcpkg..."
Push-Location $VcpkgRoot
try {
Start-Process -FilePath "cmd.exe" -ArgumentList "/c bootstrap-vcpkg.bat -disableMetrics" -Wait -NoNewWindow
if ($LASTEXITCODE -ne 0) { throw "Bootstrap failed." }
} finally {
Pop-Location
}
}
Write-Log "Done. If using custom paths, reuse VCPKG_ROOT=$VcpkgRoot."
exit 0