Repository navigation
Expand file tree
/
Copy pathcheck.bat
More file actions
242 lines (229 loc) · 9.16 KB
/
Copy pathcheck.bat
File metadata and controls
242 lines (229 loc) · 9.16 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<# :
@echo off
setlocal
where pwsh >nul 2>nul
if %errorlevel%==0 ( set "PSBIN=pwsh" ) else ( set "PSBIN=powershell" )
%PSBIN% -NoProfile -ExecutionPolicy Bypass -Command "$env:_BATROOT='%~dp0'; $env:_BATPATH='%~f0'; & ([scriptblock]::Create((Get-Content -Raw '%~f0'))) %*"
exit /b %errorlevel%
: end batch #>
# check.bat - Static verification without building or installing.
# (PowerShell twin of ./check.)
# check.bat <module> [module...] # detekt + cargo check
# check.bat games/voxels maps # multi-module, one gradlew invocation
# check.bat voxels # shorthand -> games:voxels (same as install.bat)
# check.bat all # every app + library module
#
# Module notation mirrors install.bat: slash == colon, games:/personal: shorthand,
# 'all' keyword, deduped. Tasks run with --continue so one broken module does not
# block the rest; exit code is nonzero if anything failed.
#
# Rust: a module with src/main/rust/Cargo.toml is checked with `cargo check
# --locked`: workspace members together via `-p` from the repo root, standalone
# crates (own [workspace]) individually in their own dir (host target: fast smoke
# check; the real aarch64 cross-build runs inside the Gradle build via
# cargoNdkBuild). No rust modules -> cargo step skipped.
$ErrorActionPreference = 'Stop'
$CheckRoot = if ($PSScriptRoot) { $PSScriptRoot } else { $env:_BATROOT.TrimEnd('\') }
function Show-CheckHelp {
@'
Usage:
check.bat <module> [module...] # detekt (config/detekt/detekt.yml) + cargo check
check.bat games/voxels maps # multi-module, one gradlew invocation
check.bat voxels # shorthand -> games:voxels (same as install.bat)
check.bat all # every app + library module
Module notation mirrors install.bat: slash == colon, games:/personal: shorthand,
'all' keyword, deduped. Tasks run with --continue so one broken module does not
block the rest; exit code is nonzero if anything failed.
Rust: a module with src/main/rust/Cargo.toml is checked with `cargo check
--locked`: workspace members together via `-p` from the repo root, standalone
crates (own [workspace]) individually in their own dir (host target: fast smoke
check; the real aarch64 cross-build runs inside the Gradle build via
cargoNdkBuild). No rust modules -> cargo step skipped.
'@
}
function Normalize-CheckModule([string]$M) {
$M = $M.Trim()
$M = [regex]::Replace($M, '^[/:]+', '')
$M = [regex]::Replace($M, '[/:]+$', '')
$M = $M.Replace('/', ':')
while ($M.Contains('::')) { $M = $M.Replace('::', ':') }
return $M.ToLowerInvariant()
}
# all = app + library convention modules (both apply dev.detekt; pure-JVM
# modules like youpipe:extractor do not, so they are excluded here but still
# accepted when named explicitly and left for Gradle to report on).
function Get-CheckAllModuleDirs {
$CheckSettings = Join-Path $CheckRoot 'settings.gradle.kts'
$CheckFound = @()
if (-not (Test-Path -LiteralPath $CheckSettings)) { return $CheckFound }
foreach ($CheckLine in [System.IO.File]::ReadLines($CheckSettings)) {
if ($CheckLine -match 'include\(":([^"]+)"\)') {
$CheckP = $Matches[1].Replace(':', '/')
if (-not $CheckP) { continue }
$CheckBuild = Join-Path $CheckRoot "$CheckP/build.gradle.kts"
if ((Test-Path -LiteralPath $CheckBuild) -and
(Select-String -LiteralPath $CheckBuild -Pattern 'common-conventions-(app|library)' -Quiet)) {
$CheckFound += $CheckP
}
}
}
return @($CheckFound | Sort-Object -Unique)
}
function Get-CheckCargoBin {
$CheckCargoCmd = Get-Command cargo -ErrorAction SilentlyContinue
if ($CheckCargoCmd) { return $CheckCargoCmd.Source }
$CheckCargoHome = if ($env:CARGO_HOME) { $env:CARGO_HOME } else { Join-Path $HOME '.cargo' }
$CheckCand = Join-Path $CheckCargoHome 'bin/cargo'
if (Test-Path -LiteralPath $CheckCand -PathType Leaf) { return $CheckCand }
$CheckCandExe = "$CheckCand.exe"
if (Test-Path -LiteralPath $CheckCandExe -PathType Leaf) { return $CheckCandExe }
return ''
}
if ($args.Count -eq 0) {
Show-CheckHelp
Write-Output ''
Write-Output 'Error: no modules specified.'
exit 1
}
foreach ($CheckA in $args) {
if ($CheckA -eq '--help' -or $CheckA -eq '-h' -or $CheckA -eq 'help') {
Show-CheckHelp
exit 0
}
}
$CheckMods = @()
$CheckAllExp = $false
foreach ($CheckRaw in $args) {
$CheckNorm = Normalize-CheckModule ([string]$CheckRaw)
if (-not $CheckNorm) { continue }
if ($CheckNorm -eq 'all') {
if (-not $CheckAllExp) {
foreach ($CheckSm in (Get-CheckAllModuleDirs)) {
if ($CheckSm) { $CheckMods += $CheckSm }
}
$CheckAllExp = $true
}
continue
}
if (-not $CheckNorm.Contains(':')) {
foreach ($CheckPfx in @('games', 'personal')) {
if (Test-Path -LiteralPath (Join-Path $CheckRoot "$CheckPfx/$CheckNorm/build.gradle.kts")) {
$CheckNorm = "$CheckPfx`:$CheckNorm"
break
}
}
}
$CheckFs = $CheckNorm.Replace(':', '/')
if (-not (Test-Path -LiteralPath (Join-Path $CheckRoot "$CheckFs/build.gradle.kts"))) {
[Console]::Error.WriteLine("Error: unknown module '$CheckRaw' (-> $CheckFs/, no build.gradle.kts).")
exit 1
}
if ($CheckMods -notcontains $CheckFs) { $CheckMods += $CheckFs }
}
if ($CheckMods.Count -eq 0) {
[Console]::Error.WriteLine('Error: no valid modules.')
exit 1
}
$CheckTasks = @()
foreach ($CheckMod in $CheckMods) {
$CheckTasks += ":$($CheckMod.Replace('/', ':')):detekt"
}
Write-Output "Modules ($($CheckMods.Count)): $($CheckMods -join ' ')"
Write-Output "Gradle tasks: $($CheckTasks -join ' ')"
Write-Output ''
# gradlew: prefer the extensionless wrapper via bash when present
# (keeps one code path), else gradlew.bat on Windows.
$CheckGradlewSh = Join-Path $CheckRoot 'gradlew'
$CheckGradlewBat = Join-Path $CheckRoot 'gradlew.bat'
$CheckBashCmd = Get-Command bash -ErrorAction SilentlyContinue
if ($CheckBashCmd -and (Test-Path -LiteralPath $CheckGradlewSh)) {
$CheckPrevPref = $ErrorActionPreference
$ErrorActionPreference = 'Continue'
& $CheckBashCmd.Source $CheckGradlewSh @CheckTasks --continue --console=plain
$CheckDetektRc = $LASTEXITCODE
$ErrorActionPreference = $CheckPrevPref
}
elseif (Test-Path -LiteralPath $CheckGradlewBat) {
$CheckPrevPref = $ErrorActionPreference
$ErrorActionPreference = 'Continue'
& $CheckGradlewBat @CheckTasks --continue --console=plain
$CheckDetektRc = $LASTEXITCODE
$ErrorActionPreference = $CheckPrevPref
}
else {
[Console]::Error.WriteLine('Error: no Gradle wrapper found (gradlew / gradlew.bat).')
exit 1
}
Write-Output ''
if ($CheckDetektRc -ne 0) { Write-Output "Warning: detekt reported failures (exit $CheckDetektRc)." }
# --- cargo check (rust modules only) ---
# Workspace members share one root `cargo check -p ...` invocation; standalone
# crates (own [workspace] table + lockfile, e.g. games:voxels, code) are checked
# individually with cwd set to the crate dir.
$CheckRootCrates = @()
$CheckStandaloneDirs = @()
foreach ($CheckMod in $CheckMods) {
$CheckRdir = Join-Path $CheckRoot "$CheckMod/src/main/rust"
$CheckCt = Join-Path $CheckRdir 'Cargo.toml'
if (Test-Path -LiteralPath $CheckCt -PathType Leaf) {
if (Select-String -LiteralPath $CheckCt -Pattern '^\[workspace\]\s*$' -Quiet) {
$CheckStandaloneDirs += $CheckRdir
Write-Output "Rust: $CheckMod -> standalone crate ($CheckRdir)"
}
else {
$CheckName = $null
foreach ($CheckLine in [System.IO.File]::ReadLines($CheckCt)) {
if ($CheckLine -match '^\s*name\s*=\s*"([^"]+)"') { $CheckName = $Matches[1]; break }
}
if ($CheckName) {
$CheckRootCrates += $CheckName
Write-Output "Rust: $CheckMod -> workspace crate $CheckName"
}
}
}
}
$CheckCargoRc = 0
$CheckCargoBin = Get-CheckCargoBin
if (-not $CheckCargoBin) {
[Console]::Error.WriteLine('Error: cargo not found (install Rust or set CARGO_HOME).')
exit 1
}
if ($CheckRootCrates.Count -gt 0) {
Write-Output ''
$CheckCargoArgs = @()
foreach ($CheckC in $CheckRootCrates) { $CheckCargoArgs += @('-p', $CheckC) }
Write-Output "Running: cargo check --locked $($CheckCargoArgs -join ' ')"
$CheckPrevPref = $ErrorActionPreference
$ErrorActionPreference = 'Continue'
Push-Location -LiteralPath $CheckRoot
try {
& $CheckCargoBin check --locked @CheckCargoArgs
$CheckCargoRc = $LASTEXITCODE
}
finally {
Pop-Location
$ErrorActionPreference = $CheckPrevPref
}
if ($CheckCargoRc -ne 0) { Write-Output "Warning: cargo check (workspace) reported failures (exit $CheckCargoRc)." }
}
foreach ($CheckRdir in $CheckStandaloneDirs) {
Write-Output ''
Write-Output "Running: cargo check --locked (in $CheckRdir)"
$CheckPrevPref = $ErrorActionPreference
$ErrorActionPreference = 'Continue'
Push-Location -LiteralPath $CheckRdir
try {
& $CheckCargoBin check --locked
$CheckCargoRc = $LASTEXITCODE
}
finally {
Pop-Location
$ErrorActionPreference = $CheckPrevPref
}
if ($CheckCargoRc -ne 0) { Write-Output "Warning: cargo check ($CheckRdir) reported failures (exit $CheckCargoRc)." }
}
if (($CheckRootCrates.Count -eq 0) -and ($CheckStandaloneDirs.Count -eq 0)) {
Write-Output 'No Rust crates in scope; cargo step skipped.'
}
if (($CheckDetektRc -ne 0) -or ($CheckCargoRc -ne 0)) { exit 1 }
exit 0