From 1588b4519a2164131bf212713fe182fba9359c1f Mon Sep 17 00:00:00 2001 From: mo Date: Fri, 4 Sep 2026 17:06:13 +0100 Subject: [PATCH] chore: add Windows formatting convenience scripts (#922) * chore: add Windows formatting convenience scripts * chore: use powershell scripts --------- Co-authored-by: Jan Laupetin --- scripts/check-format.ps1 | 35 +++++++++++++++++++++++++++++++++++ scripts/reformat-all.ps1 | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 scripts/check-format.ps1 create mode 100644 scripts/reformat-all.ps1 diff --git a/scripts/check-format.ps1 b/scripts/check-format.ps1 new file mode 100644 index 00000000..02cfba55 --- /dev/null +++ b/scripts/check-format.ps1 @@ -0,0 +1,35 @@ +#!powershell + +$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 + } +} \ No newline at end of file diff --git a/scripts/reformat-all.ps1 b/scripts/reformat-all.ps1 new file mode 100644 index 00000000..f30cb896 --- /dev/null +++ b/scripts/reformat-all.ps1 @@ -0,0 +1,35 @@ +#!powershell + +$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 --verbose -i $batch + + if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE + } +} \ No newline at end of file