-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsetup.ps1
More file actions
197 lines (175 loc) · 6.57 KB
/
Copy pathsetup.ps1
File metadata and controls
197 lines (175 loc) · 6.57 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
param([switch]$Check)
Set-Location $PSScriptRoot
$script:Results = @()
$script:Failed = $false
function Report($status, $key, $detail) {
$script:Results += [pscustomobject]@{ Status = $status; Key = $key; Detail = $detail }
if ($status -eq 'FAIL') { $script:Failed = $true }
}
function Test-GitRepo {
$top = (git rev-parse --show-toplevel 2>$null)
if (-not $top) {
Report 'FAIL' 'git-repo' 'not a git repository'
return $false
}
Report 'OK' 'git-repo' $top
return $true
}
function Test-GitHooks {
if (-not (Test-Path '.githooks/pre-commit')) {
Report 'FAIL' 'git-hooks' '.githooks/pre-commit is missing from the working tree'
return
}
$path = (git config --get core.hooksPath 2>$null)
if ($path -eq '.githooks') {
Report 'OK' 'git-hooks' 'core.hooksPath = .githooks'
} elseif (-not $path) {
Report 'FAIL' 'git-hooks' 'core.hooksPath is unset -- git hooks never run in this clone'
} else {
Report 'FAIL' 'git-hooks' "core.hooksPath = $path (expected .githooks)"
}
}
function Test-StaleLocalHooks {
$stale = Get-ChildItem '.git/hooks' -File -ErrorAction SilentlyContinue |
Where-Object { $_.Extension -ne '.sample' }
if ($stale) {
$names = ($stale | ForEach-Object { $_.Name }) -join ', '
Report 'WARN' 'stale-local-hooks' "$names in .git/hooks (shadowed by core.hooksPath, delete to avoid confusion)"
} else {
Report 'OK' 'stale-local-hooks' 'none'
}
}
function Get-MissingSubmodules {
if (-not (Test-Path '.gitmodules')) { return @() }
$paths = git config -f .gitmodules --get-regexp '^submodule\..*\.path$' 2>$null |
ForEach-Object { ($_ -split '\s+', 2)[1] }
return @($paths | Where-Object {
-not (Test-Path $_) -or -not (Get-ChildItem $_ -Force -ErrorAction SilentlyContinue)
})
}
function Test-Submodules {
if (-not (Test-Path '.gitmodules')) {
Report 'OK' 'submodules' 'none declared'
return
}
$missing = Get-MissingSubmodules
if ($missing.Count -gt 0) {
Report 'FAIL' 'submodules' ("not initialised: " + ($missing -join ', '))
} else {
Report 'OK' 'submodules' 'all initialised'
}
}
function Test-Python {
$ver = (py -3 --version 2>&1)
if ($LASTEXITCODE -ne 0) {
Report 'FAIL' 'python' "py -3 not runnable -- every .claude hook is a no-op without it ($ver)"
} else {
Report 'OK' 'python' $ver
}
}
function Test-ClaudeHooks {
if (-not (Test-Path '.claude/settings.json')) {
Report 'FAIL' 'claude-hooks' '.claude/settings.json is missing'
return
}
try {
$raw = Get-Content '.claude/settings.json' -Raw
$null = $raw | ConvertFrom-Json
} catch {
Report 'FAIL' 'claude-hooks' ".claude/settings.json does not parse: $($_.Exception.Message)"
return
}
$referenced = [regex]::Matches($raw, '\.claude/hooks/([A-Za-z0-9_]+\.py)') |
ForEach-Object { $_.Groups[1].Value } | Sort-Object -Unique
if (-not $referenced) {
Report 'FAIL' 'claude-hooks' 'settings.json references no hook scripts'
return
}
$missing = $referenced | Where-Object { -not (Test-Path (Join-Path '.claude/hooks' $_)) }
if ($missing) {
Report 'FAIL' 'claude-hooks' ("scripts referenced but absent: " + ($missing -join ', '))
return
}
$broken = @()
foreach ($h in $referenced) {
$null = (py -3 -m py_compile (Join-Path '.claude/hooks' $h) 2>&1)
if ($LASTEXITCODE -ne 0) { $broken += $h }
}
if ($broken) {
Report 'FAIL' 'claude-hooks' ("scripts fail to compile under py -3: " + ($broken -join ', '))
} else {
Report 'OK' 'claude-hooks' "$($referenced.Count) hooks present and compiling"
}
}
function Test-Vcpkg {
if (Test-Path "$env:LOCALAPPDATA\vcpkg\vcpkg.user.props") {
Report 'OK' 'vcpkg' 'MSBuild integration present'
} else {
Report 'FAIL' 'vcpkg' "run 'vcpkg integrate install' from '<VS install>\VC\vcpkg\vcpkg.exe' -- build.ps1 refuses to build without it"
}
}
# docs/ce_apps_setup.md
function Test-CeToolchain {
$root = 'third_party/wince'
if (-not (Test-Path $root)) {
Report 'WARN' 'ce-toolchain' "absent -- optional; needed only to build ce_apps/ (see docs/ce_apps_setup.md)"
return
}
$tools = @('clarm.exe', 'clthumb.exe', 'clmips.exe', 'link.exe', 'lib.exe', 'rc.exe')
$missing = @($tools | Where-Object { -not (Test-Path (Join-Path "$root/bin" $_)) })
foreach ($a in @('Armv4', 'Armv4i', 'Mipsii', 'Mipsiv')) {
if (-not (Test-Path (Join-Path $root "STANDARDSDK/Include/$a"))) { $missing += "Include/$a" }
if (-not (Test-Path (Join-Path $root "STANDARDSDK/Lib/$a/coredll.lib"))) { $missing += "Lib/$a/coredll.lib" }
}
if ($missing.Count) {
Report 'FAIL' 'ce-toolchain' ("incomplete -- missing: " + ($missing -join ', ') + " (re-run tools/unpack_evc4.ps1 -Force)")
} else {
Report 'OK' 'ce-toolchain' 'Armv4, Armv4i, Mipsii, Mipsiv'
}
}
function Invoke-Checks {
if (-not (Test-GitRepo)) { return }
Test-GitHooks
Test-StaleLocalHooks
Test-Submodules
Test-Python
Test-ClaudeHooks
Test-Vcpkg
Test-CeToolchain
}
if ($Check) {
Invoke-Checks
foreach ($r in $script:Results) { "$($r.Status)`t$($r.Key)`t$($r.Detail)" }
if ($script:Failed) { exit 1 }
exit 0
}
Write-Host ""
Write-Host "CERF setup" -ForegroundColor Cyan
Write-Host ""
if (-not (git rev-parse --show-toplevel 2>$null)) {
Write-Host " FAIL not a git repository -- run setup.cmd from a cloned CERF tree" -ForegroundColor Red
exit 1
}
git config core.hooksPath .githooks
Write-Host " set core.hooksPath = .githooks" -ForegroundColor Green
$missingSubmodules = Get-MissingSubmodules
foreach ($m in $missingSubmodules) {
Write-Host " init submodule $m" -ForegroundColor Green
git submodule update --init --recursive -- $m
}
if ($missingSubmodules.Count -eq 0) {
Write-Host " skip submodules already initialised (left untouched)" -ForegroundColor DarkGray
}
Write-Host ""
Invoke-Checks
foreach ($r in $script:Results) {
$color = switch ($r.Status) { 'OK' { 'Green' } 'WARN' { 'Yellow' } default { 'Red' } }
Write-Host (" {0,-5} {1,-20} {2}" -f $r.Status, $r.Key, $r.Detail) -ForegroundColor $color
}
Write-Host ""
if ($script:Failed) {
Write-Host "Setup incomplete -- resolve the FAIL lines above, then re-run setup.cmd." -ForegroundColor Red
exit 1
}
Write-Host "Ready. Build with build.cmd, launch the Claude dev environment with run_claude.cmd." -ForegroundColor Cyan
exit 0