chore: add Windows formatting convenience scripts - #922
Conversation
|
I always use the On my PC that's the difference between 8 seconds and 36 seconds 😅 |
|
Batch scripts are not the prettiest, how do you feel about powershell scripts instead? This one runs in about 6 seconds for me: # check-format.ps1
$ErrorActionPreference = "Stop"
$repositoryRoot = Split-Path -Parent $PSScriptRoot
$sourceDirectories = @(
(Join-Path $repositoryRoot "src")
(Join-Path $repositoryRoot "test")
)
$clangFormat = if ($env:CLANG_FORMAT_BIN) {
$env:CLANG_FORMAT_BIN
}
else {
"clang-format"
}
$files = @(
Get-ChildItem -Path $sourceDirectories -Recurse -File |
Where-Object { $_.Extension -in ".h", ".cpp" }
)
# Stay comfortably below Windows' native process command-line limit.
$batchSize = 100
for ($offset = 0; $offset -lt $files.Count; $offset += $batchSize) {
$lastIndex = [Math]::Min($offset + $batchSize - 1, $files.Count - 1)
$batch = $files[$offset..$lastIndex].FullName
& $clangFormat -Werror -ferror-limit=1 --dry-run $batch
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
}Also these could just be omitted altogether and a small guide added to the readme on running them through the provided scripts in a windows environment, or perhaps a dedicated |
the reason i usually avoid ps1 scripts is because of Microsoft's ExecutionPolicy stuff always causing headaches and problems. The script works well and definitely better than the batch version. I'd just add |
i guess on the side of documentation, there's a lot of room for improvement 😅 |
No description provided.